Skip to main content
Glama

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_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.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 California

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Demonstrates an MCP server with calculate and text_stats tools over Streamable HTTP, integrating with LangChain/LangGraph and n8n agents.
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides math and weather tools accessible via LangGraph agent using MCP protocol with stdio and streamable HTTP transports.
    1
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    A model-agnostic MCP server exposing example tools (add1, multiply2, greet) for learning purposes, working with any LLM through stdio transport.
    -