LangGraph ReAct Agent with MCP

by nachoal

MCP Client 2 stars
  • agent-framework

About

What is LangGraph ReAct Agent with MCP?

This template is a ReAct agent implemented using LangGraph and the Model Context Protocol (MCP). It runs as a Python application and connects to one or more MCP servers to provide tools and capabilities through a unified gateway. It is designed for developers building tool‑using agents.

How to use LangGraph ReAct Agent with MCP?

Install the agent and gateway packages (pip install -e .), then configure MCP servers in gateway/config.json. Start the gateway server (python -m mcp_gateway.server on port 8808), set the gateway URL in langgraph.json, and open the agent in LangGraph Studio or a LangGraph server. The agent will automatically discover tools from the configured MCP servers.

Key features of LangGraph ReAct Agent with MCP

- Implements a ReAct agent with LangGraph and MCP.
- Unified MCP gateway manages multiple MCP server processes.
- Provides tools from filesystem and memory MCP servers.
- Automatic tool discovery from connected MCP servers.
- Easy to extend by adding new MCP servers.
- Open source (MIT License).

Use cases of LangGraph ReAct Agent with MCP

- Reading, writing, and searching files on the local filesystem.
- Creating and querying a knowledge graph (entities and relations).
- Combining filesystem and memory tools in a single agent conversation.
- Building an agent that can use any tool from the MCP ecosystem.

FAQ from LangGraph ReAct Agent with MCP

What is the ReAct agent pattern used here?

The template follows the ReAct (Reasoning + Acting) pattern described in the paper “ReAct: Synergizing Reasoning and Acting in Language Models”. The agent reasons about a task, calls tools from MCP servers, and continues until the task is complete.

What is the Model Context Protocol (MCP)?

MCP is a protocol that allows agents to discover and use tools provided by external servers. The agent connects to an MCP gateway that manages multiple MCP server processes and exposes their tools via a simple HTTP interface.

How do I add more MCP servers?

Edit the gateway/config.json file to add the server’s command and arguments under mcp.servers. The official MCP servers repository (linked in the README) provides ready‑to‑use servers. After restarting the gateway, the agent will automatically discover the new tools.

What license is this template under?

The template is licensed under the MIT License. See the LICENSE file for details.

Does this require a specific LLM or platform?

The template is built with LangGraph and runs in LangGraph Studio or any LangGraph server. It does not mandate a specific model; the LLM is configured through the LangGraph environment (e.g., via .env). The MCP servers themselves are model‑agnostic.

Details

Author
nachoal
GitHub stars
2
Category
agent-framework
Repository
nachoal/react-agent-with-mcp

LangGraph ReAct Agent with MCP

CI
Integration Tests
Open in - LangGraph Studio

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:

1. 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

2. 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

3. 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:
1. Connect to the local gateway server
2. Discover available tools
3. 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 contents - write_file: Create or update files - list_directory: List directory contents - search_files: Find files matching patterns - And more...

Memory Tools

- create_entities: Add entities to knowledge graph - create_relations: Link entities together - search_nodes: Query the knowledge graph - And more...

Development

Adding New MCP Servers

1. Find a server in the MCP servers repository
2. Add its configuration to gateway/config.json
3. 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

- LangGraph Documentation
- Model Context Protocol
- MCP Servers Repository

License

This project is licensed under the MIT License - see the LICENSE file for details.