SampleMCP
SampleMCP
Ein einfaches Python-Projekt, das zeigt, wie man MCP-Server mit FastMCP, LangChain-MCP-Adaptern, LangGraph und OpenAI erstellt und verbindet.
Funktionen
Mathe-MCP-Server mit
stdioWetter-MCP-Server mit
streamable-httpLangChain-MCP-Client zur Verbindung mit mehreren MCP-Servern
LangGraph ReAct-Agent unter Verwendung von MCP-Tools
Beispiel-Tool-Aufrufe für Mathe- und Wetterabfragen
Related MCP server: Server MCP
Projektstruktur
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.mdAnforderungen
Python 3.12+
OpenAI API-Schlüssel
Optional: Groq API-Schlüssel
Installation
Klonen Sie das Repository:
git clone https://github.com/JayantPrakash/SampleMCP.git
cd SampleMCPInstallieren Sie die Abhängigkeiten:
pip install -r requirements.txtOder mit uv:
uv syncUmgebungsvariablen
Erstellen Sie eine .env-Datei im Projektstammverzeichnis:
OPENAI_API_KEY=your_openai_api_key
GROQ_API_KEY=your_groq_api_keyAusführen der MCP-Server
1. Starten des Wetter-Servers
Der Wetter-Server verwendet streamable-http.
python weather.pyStandardmäßig stellt er den MCP-Endpunkt unter folgender Adresse bereit:
http://localhost:8000/mcp2. Mathe-Server
Der Mathe-Server verwendet stdio und wird automatisch vom Client gestartet durch:
"command": "python",
"args": ["mathserver.py"],
"transport": "stdio"Ausführen des Clients
Führen Sie in einem separaten Terminal Folgendes aus:
python client.pyDer Client verbindet sich mit:
mathserver.pyüberstdioweather.pyüberstreamable_http
Anschließend erstellt er einen LangGraph ReAct-Agenten und stellt die Fragen:
what's (3 + 5) x 12?und:
what is the weather in California?MCP-Tools
Mathe-Server
Definiert in mathserver.py.
add(a: int, b: int) -> intAddiert zwei Zahlen.
multiple(a: int, b: int) -> intMultipliziert zwei Zahlen.
Wetter-Server
Definiert in weather.py.
get_weather(location: str) -> strGibt eine Beispiel-Wetterantwort für einen bestimmten Ort zurück.
Hinweise
mathserver.pyverwendettransport="stdio".weather.pyverwendettransport="streamable-http".In
client.pyist der streamable HTTP-Transport alsstreamable_httpkonfiguriert.Stellen Sie sicher, dass der Wetter-Server läuft, bevor Sie
client.pyausführen.
Beispielausgabe
Math response: 96
Weather response: It's always raining in CaliforniaThis server cannot be deployed
Maintenance
Related MCP Connectors
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
MCP server for langchain documentation, generated by doc2mcp.
MCP server for progressive tool usage at any scale (see https://klavis.ai)
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceDemonstrates an MCP server with calculate and text_stats tools over Streamable HTTP, integrating with LangChain/LangGraph and n8n agents.-
- FlicenseNot gradedqualityDmaintenanceProvides math and weather tools accessible via LangGraph agent using MCP protocol with stdio and streamable HTTP transports.1-
- FlicenseNot gradedqualityDmaintenanceA collection of MCP servers demonstrating math operations, weather data, and LangGraph workflows.1-
- FlicenseNot gradedqualityDmaintenanceA model-agnostic MCP server exposing example tools (add1, multiply2, greet) for learning purposes, working with any LLM through stdio transport.-