SampleMCP
SampleMCP
FastMCP、LangChain MCPアダプター、LangGraph、OpenAIを使用してMCPサーバーを構築および接続する方法を示すシンプルなPythonプロジェクトです。
機能
stdioを使用した数学MCPサーバーstreamable-httpを使用した天気MCPサーバー複数のMCPサーバーに接続するLangChain MCPクライアント
MCPツールを使用したLangGraph ReActエージェント
数学および天気クエリのツール呼び出し例
Related MCP server: Server MCP
プロジェクト構成
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要件
Python 3.12以上
OpenAI APIキー
オプション: Groq APIキー
インストール
リポジトリをクローンします:
git clone https://github.com/JayantPrakash/SampleMCP.git
cd SampleMCP依存関係をインストールします:
pip install -r requirements.txtまたは uv を使用します:
uv sync環境変数
プロジェクトのルートに .env ファイルを作成します:
OPENAI_API_KEY=your_openai_api_key
GROQ_API_KEY=your_groq_api_keyMCPサーバーの実行
1. 天気サーバーの起動
天気サーバーは streamable-http を使用します。
python weather.pyデフォルトでは、MCPエンドポイントは以下で公開されます:
http://localhost:8000/mcp2. 数学サーバー
数学サーバーは stdio を使用し、クライアントによって以下のように自動的に起動されます:
"command": "python",
"args": ["mathserver.py"],
"transport": "stdio"クライアントの実行
別のターミナルで以下を実行します:
python client.pyクライアントは以下に接続します:
mathserver.py(stdio経由)weather.py(streamable_http経由)
その後、LangGraph ReActエージェントを作成し、以下を問い合わせます:
what's (3 + 5) x 12?および:
what is the weather in California?MCPツール
数学サーバー
mathserver.py で定義されています。
add(a: int, b: int) -> int2つの数値を加算します。
multiple(a: int, b: int) -> int2つの数値を乗算します。
天気サーバー
weather.py で定義されています。
get_weather(location: str) -> str指定された場所のサンプル天気レスポンスを返します。
注意事項
mathserver.pyはtransport="stdio"を使用します。weather.pyはtransport="streamable-http"を使用します。client.pyでは、ストリーミング可能なHTTPトランスポートがstreamable_httpとして設定されています。client.pyを実行する前に、天気サーバーが起動していることを確認してください。
出力例
Math response: 96
Weather response: It's always raining in CaliforniaTool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
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)
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceDemonstrates an MCP server with calculate and text_stats tools over Streamable HTTP, integrating with LangChain/LangGraph and n8n agents.ISC
- 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.-