SampleMCP
SampleMCP
Un proyecto sencillo en Python que demuestra cómo construir y conectar servidores MCP utilizando FastMCP, adaptadores MCP de LangChain, LangGraph y OpenAI.
Características
Servidor MCP de matemáticas usando
stdioServidor MCP de clima usando
streamable-httpCliente MCP de LangChain que se conecta a múltiples servidores MCP
Agente ReAct de LangGraph que utiliza herramientas MCP
Ejemplos de llamadas a herramientas para consultas de matemáticas y clima
Related MCP server: Server MCP
Estructura del proyecto
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.mdRequisitos
Python 3.12+
Clave de API de OpenAI
Opcional: Clave de API de Groq
Instalación
Clona el repositorio:
git clone https://github.com/JayantPrakash/SampleMCP.git
cd SampleMCPInstala las dependencias:
pip install -r requirements.txtO usando uv:
uv syncVariables de entorno
Crea un archivo .env en la raíz del proyecto:
OPENAI_API_KEY=your_openai_api_key
GROQ_API_KEY=your_groq_api_keyEjecución de los servidores MCP
1. Iniciar el servidor de clima
El servidor de clima utiliza streamable-http.
python weather.pyPor defecto, expone el endpoint MCP en:
http://localhost:8000/mcp2. Servidor de matemáticas
El servidor de matemáticas utiliza stdio y es iniciado automáticamente por el cliente a través de:
"command": "python",
"args": ["mathserver.py"],
"transport": "stdio"Ejecución del cliente
En una terminal separada, ejecuta:
python client.pyEl cliente se conecta a:
mathserver.pya través destdioweather.pya través destreamable_http
Luego crea un agente ReAct de LangGraph y pregunta:
what's (3 + 5) x 12?y:
what is the weather in California?Herramientas MCP
Servidor de matemáticas
Definido en mathserver.py.
add(a: int, b: int) -> intSuma dos números.
multiple(a: int, b: int) -> intMultiplica dos números.
Servidor de clima
Definido en weather.py.
get_weather(location: str) -> strDevuelve una respuesta de clima de muestra para una ubicación determinada.
Notas
mathserver.pyutilizatransport="stdio".weather.pyutilizatransport="streamable-http".En
client.py, el transporte HTTP transmitible se configura comostreamable_http.Asegúrate de que el servidor de clima esté ejecutándose antes de ejecutar
client.py.
Ejemplo de salida
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.-