Dynamic LangGraph MCP Agent

Dynamic LangGraph MCP Agent

A production-ready agent system that automatically discovers and uses tools from MCP servers using LangGraph's ReAct architecture and LLM-powered routing.

Category
Visit Server

README

๐Ÿš€ Dynamic LangGraph MCP Agent

A production-ready agent system that automatically discovers and uses tools from MCP (Model Context Protocol) servers using LangGraph's ReAct architecture.

โœจ Features

  • ๐Ÿค– LangGraph ReAct Agent - Built-in reasoning and multi-step planning
  • ๐Ÿ” Automatic Tool Discovery - No hardcoding, just add MCP servers and go
  • ๐Ÿง  LLM-Powered Routing - Gemini Flash intelligently selects the right tools
  • ๐Ÿ”Œ Multi-Server Support - Connect to unlimited MCP servers
  • ๐Ÿ“ Multi-Step Reasoning - Agent can chain multiple tools to solve complex tasks
  • โœจ Zero Configuration - Add tools and they work instantly

๐Ÿ“ Project Structure

mcp-agent/
โ”œโ”€โ”€ agents.py              # Main application (FastAPI + LangGraph)
โ”œโ”€โ”€ mcp_server.py          # MCP server with agricultural tools
โ”œโ”€โ”€ config.json            # MCP server configuration
โ”œโ”€โ”€ .env                   # Environment variables (API keys)
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”œโ”€โ”€ README.md              # This file
โ”œโ”€โ”€ ARCHITECTURE.md        # System architecture documentation
โ””โ”€โ”€ DATAFLOW.md           # Complete data flow explanation

๐Ÿš€ Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Set Up Environment Variables

Create a .env file:

GOOGLE_API_KEY=your_google_api_key_here

Get your API key from: https://aistudio.google.com/app/apikey

3. Configure MCP Servers

Edit config.json with your MCP server paths:

{
  "mcpServers": {
    "agricultural-server": {
      "command": "python",
      "args": ["mcp_server.py"],
      "env": {
        "PYTHONIOENCODING": "utf-8"
      }
    }
  }
}

Important: Use full paths on Windows:

{
  "command": "D:\\Python\\python.exe",
  "args": ["D:\\projects\\mcp-agent\\mcp_server.py"]
}

4. Start the Server

python agents.py

5. Test the Agent

Visit http://localhost:8000/docs

Or use cURL:

curl -X POST "http://localhost:8000/chat" \
  -H "Content-Type: application/json" \
  -d '{"message": "What is the weather in Tokyo?"}'

๐Ÿ“Š Available Tools

Tool Description Arguments
get_current_weather Real-time weather data city (string)
get_pesticide_seed_info Agricultural information query (string)
get_placeholder_posts Sample blog posts limit (integer)

๐Ÿงช Example Queries

# Weather query โ†’ Uses get_current_weather
"What's the weather in Paris?"

# Agriculture query โ†’ Uses get_pesticide_seed_info  
"Tell me about organic farming techniques"

# Content query โ†’ Uses get_placeholder_posts
"Show me 5 interesting articles"

# Multi-step reasoning โ†’ Uses multiple tools
"What's the weather in Mumbai and what crops grow best there?"

๐Ÿ”ง API Endpoints

POST /chat

Main endpoint for chatting with the agent

Request:

{
  "message": "Your query here"
}

Response:

{
  "response": "Agent's answer",
  "intermediate_steps": ["Tool used: get_current_weather"],
  "error": null
}

GET / - Server info

GET /tools - List all tools

GET /health - Health check

๐Ÿ”Œ Adding New Tools

Edit mcp_server.py:

@mcp_server.list_tools()
async def list_tools() -> list[Tool]:
    return [
        # ... existing tools ...
        Tool(
            name="my_new_tool",
            description="What this tool does",
            inputSchema={
                "type": "object",
                "properties": {
                    "param": {"type": "string"}
                },
                "required": ["param"]
            }
        )
    ]

Restart the agent - tools are auto-discovered!

๐Ÿ› Troubleshooting

"GOOGLE_API_KEY not found"

  • Create .env file with your API key

"No MCP servers found"

  • Check config.json exists and has correct paths

"Agent not initialized"

  • Verify MCP server starts independently: python mcp_server.py

๐Ÿ“š Resources

  • LangGraph: https://langchain-ai.github.io/langgraph/
  • MCP Protocol: https://modelcontextprotocol.io
  • Gemini API: https://ai.google.dev/

See ARCHITECTURE.md for system design. See DATAFLOW.md for data flow details.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured