Server MCP
Provides math and weather tools accessible via LangGraph agent using MCP protocol with stdio and streamable HTTP transports.
README
đ€ Server MCP - Agent LangGraph avec outils Math & MĂ©tĂ©o
đŻ Objectif pĂ©dagogique : Ce projet a pour but de montrer comment utiliser le protocole MCP (Model Context Protocol) pour connecter un agent IA Ă des outils externes, en utilisant les deux types de transport :
stdioetstreamable_http.
Un projet d'agent IA basé sur LangChain, LangGraph et le protocole MCP (Model Context Protocol), connectant un modÚle LLM Groq à des outils externes via des serveurs MCP, avec observabilité via LangSmith et Langfuse.
Qu'est-ce que MCP ?
Le Model Context Protocol est un standard ouvert qui permet à un LLM de communiquer avec des outils externes (serveurs MCP) de maniÚre structurée. Il définit comment un agent peut découvrir, appeler et recevoir les résultats d'outils distants, quel que soit le langage ou la plateforme utilisée.
Ce projet illustre deux modes de communication MCP :
| Transport | Cas d'usage | Exemple dans ce projet |
|---|---|---|
stdio |
Outil local, lancé par le client | mathserver.py |
streamable_http |
Outil distant, serveur indépendant | weather.py |
đ Structure du projet
Server_mcp/
âââ src/
â âââ client.py # Agent principal (LangGraph + Groq)
â âââ mathserver.py # Serveur MCP â outils mathĂ©matiques (stdio)
â âââ weather.py # Serveur MCP â outil mĂ©tĂ©o (streamable_http)
âââ .env # ClĂ©s API (non versionnĂ©)
âââ .env.example # ModĂšle de variables d'environnement
âââ .gitignore
âââ .python-version
âââ .venv/
âââ pyproject.toml # Configuration du projet
âââ requitements.txt
âââ uv.lock
âââ README.md
âïž PrĂ©requis
- Python 3.11+ (voir
.python-version) - uv â gestionnaire de paquets (recommandĂ©)
- Un compte Groq pour la clé API LLM
- Un compte LangSmith pour le tracing
- Un compte Langfuse pour l'observabilité
đ Installation
Avec uv (recommandé)
cd Server_mcp
uv sync
Avec pip classique
cd Server_mcp
python -m venv .venv
source .venv/bin/activate # Sur Windows : .venv\Scripts\activate
pip install -r requitements.txt
Configurer les variables d'environnement
Copier le fichier .env.example et remplir les valeurs :
cp .env.example .env
Contenu du .env :
# LLM
GROQ_API_KEY=votre_clé_groq_ici
# LangSmith (tracing & évaluation)
LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=votre_clé_langsmith_ici
LANGCHAIN_PROJECT=server_mcp
# Langfuse (observabilité & analytics)
LANGFUSE_PUBLIC_KEY=votre_clé_publique_langfuse_ici
LANGFUSE_SECRET_KEY=votre_clé_secrÚte_langfuse_ici
LANGFUSE_HOST=https://cloud.langfuse.com
đ§© Architecture
Ce projet utilise deux types de transport MCP :
| Fichier | Transport | Lancement |
|---|---|---|
src/mathserver.py |
stdio |
Automatique via le client |
src/weather.py |
streamable_http |
Manuel sur le port 8000 |
src/client.py
âââ MultiServerMCPClient
â âââ math (stdio) â src/mathserver.py
â âââ weather (http) â src/weather.py :8000
âââ ChatGroq (openai/gpt-oss-120b)
âââ create_agent (LangChain)
âââ LangSmith âââââââââââââââââââââââ smith.langchain.com
âââ Langfuse âââââââââââââââââââââââ cloud.langfuse.com
đ ObservabilitĂ©
LangSmith
Trace automatiquement toutes les invocations de l'agent, les appels aux outils MCP et les réponses du modÚle. Accessible sur smith.langchain.com sous le projet server_mcp.
Langfuse
Fournit des analytics détaillés sur les coûts, latences et qualité des réponses LLM. Accessible sur cloud.langfuse.com.
đ ïž Les outils disponibles
Serveur Math (src/mathserver.py)
| Outil | Description | ParamĂštres |
|---|---|---|
add |
Additionne deux nombres | a: float, b: float |
subtract |
Soustrait deux nombres | a: float, b: float |
Serveur Météo (src/weather.py)
| Outil | Description | ParamĂštres |
|---|---|---|
get_weather |
Retourne la météo d'une ville | location: str |
â¶ïž Lancer le projet
Ătape 1 â DĂ©marrer le serveur mĂ©tĂ©o (Terminal 1)
source .venv/bin/activate
python src/weather.py
Le serveur démarre sur http://127.0.0.1:8000/mcp
Ătape 2 â Lancer le client agent (Terminal 2)
source .venv/bin/activate
python src/client.py
Résultat attendu
Les outils disponibles: ['add', 'subtract', 'get_weather']
La réponse à votre question: (4+5) = 9 et (54-50) = 4
đ Erreurs frĂ©quentes
| Erreur | Cause | Solution |
|---|---|---|
Missing 'transport' key |
Clé transport absente dans la config |
Ajouter "transport": "stdio" ou "streamable_http" |
SyntaxError: forgot a comma |
print("texte" variable) |
Ajouter une virgule : print("texte", variable) |
object dict can't be used in await |
Utilisation de .invoke() au lieu de .ainvoke() |
Remplacer par await agent.ainvoke(...) |
streamable-http non reconnu |
Tiret au lieu d'underscore | Utiliser streamable_http |
| Push GitHub bloqué | Fichier .env commité avec des clés |
Révoquer les clés, retirer .env de l'historique Git |
đ Technologies utilisĂ©es
- LangChain - Framework LLM
- LangGraph - Agent ReAct
- langchain-mcp-adapters -Intégration MCP
- FastMCP - Création de serveurs MCP
- Groq â InfĂ©rence LLM ultra-rapide
- LangSmith - Tracing & évaluation des chaßnes LLM
- Langfuse - Observabilité & analytics LLM
- uv - Gestionnaire de paquets moderne
- python-dotenv- Gestion des variables d'environnement
đ€ Auteur
BANE Seydina Mouhamet
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.