Server MCP

Server MCP

Provides math and weather tools accessible via LangGraph agent using MCP protocol with stdio and streamable HTTP transports.

Category
Visit Server

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 : stdio et streamable_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


đŸ‘€ Auteur

BANE Seydina Mouhamet

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