What is LangGraph ReAct Agent with MCP?
LangGraph ReAct Agent with MCP is a framework that integrates a ReAct agent with the Model Context Protocol (MCP) to provide a unified gateway for accessing various tools and capabilities.
How to use LangGraph ReAct Agent with MCP?
To use the agent, install the necessary dependencies, configure the MCP servers, start the gateway server, and then connect the agent to the gateway. You can interact with the agent through the LangGraph platform.
Key features of LangGraph ReAct Agent with MCP?
- Unified API for accessing multiple tools through MCP.
- Supports various server capabilities including filesystem and memory operations.
- Easy integration with LangGraph for enhanced functionality.
Use cases of LangGraph ReAct Agent with MCP?
- Automating file operations such as reading and writing files.
- Managing knowledge graphs by creating entities and relations.
- Enhancing applications with AI-driven capabilities through the ReAct agent.
FAQ from LangGraph ReAct Agent with MCP?
- What is the Model Context Protocol (MCP)?
MCP is a protocol that allows for the integration of various server capabilities into a unified framework.
- How do I add new MCP servers?
You can add new servers by configuring them in the
gateway/config.json
file and the agent will automatically discover them.
- Is there documentation available?
Yes, comprehensive documentation is available on the LangGraph and MCP websites.
LangGraph ReAct Agent with MCP
This template showcases a ReAct agent implemented using LangGraph and the Model Context Protocol (MCP). The agent uses MCP servers to provide tools and capabilities through a unified gateway.
Architecture
The system consists of three main components:
-
MCP Gateway Server: A server that:
- Manages multiple MCP server processes
- Provides a unified API for accessing tools
- Handles communication with MCP servers
- Exposes tools through a simple HTTP interface
-
MCP Servers: Individual servers that provide specific capabilities:
- Filesystem Server: File operations (read, write, list, search)
- Memory Server: Knowledge graph operations (entities, relations, queries)
- Additional servers can be added for more capabilities
-
ReAct Agent: The agent that:
- Connects to the MCP gateway
- Discovers available tools
- Uses tools to accomplish tasks
- Combines capabilities from multiple servers
Getting Started
1. Install Dependencies
# Install the agent package
pip install -e .
# Install the gateway package
cd gateway
pip install -e .
cd ..
2. Configure MCP Servers
The gateway server is configured through gateway/config.json
. By default, it starts two MCP servers:
{
"mcp": {
"servers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/directory"
]
},
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}
}
You can add more servers from the official MCP servers repository.
3. Start the Gateway Server
cd gateway
python -m mcp_gateway.server
The server will start on port 8808 by default.
4. Configure the Agent
The agent's connection to the gateway is configured in langgraph.json
:
{
"dependencies": ["."],
"graphs": {
"agent": "./src/react_agent/graph.py:graph"
},
"env": ".env",
"mcp": {
"gateway_url": "http://localhost:8808"
}
}
5. Use the Agent
Open your app in LangGraph! Install guide here.
This will open a new browser window with the agent running. The agent will automatically:
- Connect to the local gateway server
- Discover available tools
- Make tools available for use in conversations
Available Tools
The agent has access to tools from both MCP servers:
Filesystem Tools
read_file
: Read file contentswrite_file
: Create or update fileslist_directory
: List directory contentssearch_files
: Find files matching patterns- And more...
Memory Tools
create_entities
: Add entities to knowledge graphcreate_relations
: Link entities togethersearch_nodes
: Query the knowledge graph- And more...
Development
Adding New MCP Servers
- Find a server in the MCP servers repository
- Add its configuration to
gateway/config.json
- The agent will automatically discover its tools
Customizing the Agent
- Modify the system prompt in
src/react_agent/prompts.py
- Update the agent's reasoning in
src/react_agent/graph.py
- Add new capabilities by including more MCP servers
Documentation
License
This project is licensed under the MIT License - see the LICENSE file for details.