Skip to main content
Glama

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 stdio

  • Servidor MCP de clima usando streamable-http

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

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

Requisitos

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

Instala las dependencias:

pip install -r requirements.txt

O usando uv:

uv sync

Variables 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_key

Ejecución de los servidores MCP

1. Iniciar el servidor de clima

El servidor de clima utiliza streamable-http.

python weather.py

Por defecto, expone el endpoint MCP en:

http://localhost:8000/mcp

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

El cliente se conecta a:

  • mathserver.py a través de stdio

  • weather.py a través de streamable_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) -> int

Suma dos números.

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

Multiplica dos números.

Servidor de clima

Definido en weather.py.

get_weather(location: str) -> str

Devuelve una respuesta de clima de muestra para una ubicación determinada.

Notas

  • mathserver.py utiliza transport="stdio".

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

  • En client.py, el transporte HTTP transmitible se configura como streamable_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 California
F
license - not found
-
quality - not tested
C
maintenance

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JayantPrakash/SampleMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server