A simple Python project demonstrating how to build and connect MCP servers using FastMCP, LangChain MCP adapters, LangGraph, and OpenAI.
- Math MCP server using
stdio - Weather MCP server using
streamable-http - LangChain MCP client connecting to multiple MCP servers
- LangGraph ReAct agent using MCP tools
- Example tool calls for math and weather queries
SampleMCP/
├── client.py # MCP client + LangGraph agent
├── mathserver.py # Math MCP server with add/multiply tools
├── weather.py # Weather MCP server using streamable HTTP
├── main.py # Basic sample entry point
├── pyproject.toml # Project metadata and dependencies
├── requirements.txt # Python dependencies
└── README.md
- Python 3.12+
- OpenAI API key
- Optional: Groq API key
Clone the repository:
git clone https://github.com/JayantPrakash/SampleMCP.git
cd SampleMCPInstall dependencies:
pip install -r requirements.txtOr using uv:
uv syncCreate a .env file in the project root:
OPENAI_API_KEY=your_openai_api_key
GROQ_API_KEY=your_groq_api_keyThe weather server uses streamable-http.
python weather.pyBy default, it exposes the MCP endpoint at:
http://localhost:8000/mcp
The math server uses stdio and is started automatically by the client through:
"command": "python",
"args": ["mathserver.py"],
"transport": "stdio"In a separate terminal, run:
python client.pyThe client connects to:
mathserver.pythroughstdioweather.pythroughstreamable_http
It then creates a LangGraph ReAct agent and asks:
what's (3 + 5) x 12?
and:
what is the weather in California?
Defined in mathserver.py.
add(a: int, b: int) -> intAdds two numbers.
multiple(a: int, b: int) -> intMultiplies two numbers.
Defined in weather.py.
get_weather(location: str) -> strReturns a sample weather response for a given location.
mathserver.pyusestransport="stdio".weather.pyusestransport="streamable-http".- In
client.py, the streamable HTTP transport is configured asstreamable_http. - Make sure the weather server is running before executing
client.py.
Math response: 96
Weather response: It's always raining in California