A minimal Model Context Protocol (MCP) client built using LangGraph in Python.
This repository shows how to:
- Build a conversational agent with LangGraph.
- Connect that agent to external tools and data sources via MCP clients.
- Experiment with synchronous, asynchronous, and MCP-driven chatbot flows.
MCP (Model Context Protocol) is an open standard for connecting AI applications to external tools and data sources, so LLMs can call tools, query systems, and act on real-world context. :contentReference[oaicite:0]{index=0}
mcp-client-langgraph/
├── chatbot.py # Basic LangGraph chatbot example
├── chatbot_async.py # Asynchronous LangGraph chatbot example
├── chatbot_mcp.py # LangGraph chatbot wired to an MCP client
chatbot.py– simplest entry point to understand how a LangGraph-based chatbot is structured.chatbot_async.py– demonstrates async usage (useful when integrating with external APIs/tools).chatbot_mcp.py– the main example showing how to use LangGraph as an MCP client, connecting to MCP servers and invoking tools via the protocol.
-
Python 3.10+
-
git -
(Optional but recommended) A virtual environment tool:
venv/virtualenv/conda
-
One or more MCP servers running locally or remotely (for the MCP example).
You can explore public MCP servers and ecosystem docs via the official MCP resources and registries. ([Anthropic][1])
git clone https://github.com/campusx-official/mcp-client-langgraph.git
cd mcp-client-langgraphpython -m venv .venv
# Linux / macOS
source .venv/bin/activate
# Windows (PowerShell)
# .venv\Scripts\Activate.ps1If a requirements.txt exists:
pip install -r requirements.txtIf not, you can install the core libraries typically needed for LangGraph + MCP work:
pip install langgraph openai mcp
⚠️ Adjust the dependencies based on what’s imported insidechatbot.py,chatbot_async.py, andchatbot_mcp.py.
python chatbot.pyThis example is usually the simplest place to start. It will:
- Initialize a LangGraph graph.
- Run a basic chat loop in the terminal.
- Show how messages flow through the graph.
python chatbot_async.pyUse this to:
- Understand async patterns with LangGraph.
- Integrate with non-blocking I/O (e.g., external HTTP tools, databases, etc.).
python chatbot_mcp.pyThis script demonstrates:
- How to configure a LangGraph agent as an MCP client.
- How to connect to MCP servers (tools, data sources, or workflows exposed via MCP).
- How to call MCP tools from within a conversational flow.
Before running this, ensure that:
- Your MCP server(s) are running and reachable.
- Any required environment variables / config (e.g., server address, API keys) are set inside
chatbot_mcp.pyor via your shell.
Typical configuration options (check inside the Python files and tailor as needed):
-
Model configuration
- OpenAI / Anthropic / other LLM provider keys via environment variables
- Model name, temperature, max tokens, etc.
-
MCP connection details
- MCP server URL / transport (e.g.,
stdio,http, etc.) - Tool names and resource IDs to be used by the agent
- MCP server URL / transport (e.g.,
Common environment variables you may need:
export OPENAI_API_KEY="your-api-key"
export MCP_SERVER_URL="http://localhost:PORT" # Example if using HTTP transportReplace with the actual variables used in the code.
MCP is an open standard that allows AI assistants to connect to external systems (files, databases, tools, APIs) through a common protocol. Think of it as a “USB-C for AI tools”—your LangGraph agent becomes an MCP client, and any MCP server you point it to becomes a pluggable capability. ([Model Context Protocol][2])
This repo’s chatbot_mcp.py file is a simple, practical example of that pattern.
Here are some ideas to extend this repo:
-
Add custom MCP servers for:
- Internal APIs
- Databases
- File systems / knowledge bases
-
Build a LangGraph workflow that:
- Searches documents via MCP
- Summarizes them
- Performs actions (e.g., write back results, send notifications)
-
Integrate with UI frontends:
- Stream responses to a web UI or CLI with streaming support.
-
Add tracing / logging:
- Track MCP tool calls and LangGraph node execution.