Skip to main content
Glama

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_key

MCPサーバーの実行

1. 天気サーバーの起動

天気サーバーは streamable-http を使用します。

python weather.py

デフォルトでは、MCPエンドポイントは以下で公開されます:

http://localhost:8000/mcp

2. 数学サーバー

数学サーバーは 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) -> int

2つの数値を加算します。

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

2つの数値を乗算します。

天気サーバー

weather.py で定義されています。

get_weather(location: str) -> str

指定された場所のサンプル天気レスポンスを返します。

注意事項

  • mathserver.pytransport="stdio" を使用します。

  • weather.pytransport="streamable-http" を使用します。

  • client.py では、ストリーミング可能なHTTPトランスポートが streamable_http として設定されています。

  • client.py を実行する前に、天気サーバーが起動していることを確認してください。

出力例

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