SampleMCP
SampleMCP
FastMCP、LangChain MCPアダプター、LangGraph、OpenAIを使用してMCPサーバーを構築および接続する方法を示すシンプルなPythonプロジェクトです。
機能
stdioを使用した数学MCPサーバーstreamable-httpを使用した天気MCPサーバー複数のMCPサーバーに接続するLangChain MCPクライアント
MCPツールを使用したLangGraph ReActエージェント
数学および天気クエリのツール呼び出し例
プロジェクト構成
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 CaliforniaThis server cannot be installed
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