Skip to main content
Glama

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 stdio

  • Wetter-MCP-Server mit streamable-http

  • LangChain-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.md

Anforderungen

  • 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 SampleMCP

Installieren Sie die Abhängigkeiten:

pip install -r requirements.txt

Oder mit uv:

uv sync

Umgebungsvariablen

Erstellen Sie eine .env-Datei im Projektstammverzeichnis:

OPENAI_API_KEY=your_openai_api_key
GROQ_API_KEY=your_groq_api_key

Ausführen der MCP-Server

1. Starten des Wetter-Servers

Der Wetter-Server verwendet streamable-http.

python weather.py

Standardmäßig stellt er den MCP-Endpunkt unter folgender Adresse bereit:

http://localhost:8000/mcp

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

Der Client verbindet sich mit:

  • mathserver.py über stdio

  • weather.py über streamable_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) -> int

Addiert zwei Zahlen.

multiple(a: int, b: int) -> int

Multipliziert zwei Zahlen.

Wetter-Server

Definiert in weather.py.

get_weather(location: str) -> str

Gibt eine Beispiel-Wetterantwort für einen bestimmten Ort zurück.

Hinweise

  • mathserver.py verwendet transport="stdio".

  • weather.py verwendet transport="streamable-http".

  • In client.py ist der streamable HTTP-Transport als streamable_http konfiguriert.

  • Stellen Sie sicher, dass der Wetter-Server läuft, bevor Sie client.py ausführen.

Beispielausgabe

Math response: 96
Weather response: It's always raining in California

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Demonstrates an MCP server with calculate and text_stats tools over Streamable HTTP, integrating with LangChain/LangGraph and n8n agents.
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides math and weather tools accessible via LangGraph agent using MCP protocol with stdio and streamable HTTP transports.
    1
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    A model-agnostic MCP server exposing example tools (add1, multiply2, greet) for learning purposes, working with any LLM through stdio transport.
    -