Skip to main content
Glama
Jotarose

mcp-server-multitask

by Jotarose

mcp_training

MCPサーバー(天気、ジオコーディング、通貨のツール付き)と、それらを使用できるOpenAIモデルと対話するコンソールクライアント。

Tú › ¿Qué tiempo hace en Madrid?

Modelo:
  En Madrid hay 24,3 °C, humedad del 41 % y cielo despejado.

  · get_lat_lon_from_city → get_current_weather

仕組み

main_client.py ──> OpenAI (Responses API) ──> [túnel] ──> main_server.py (MCP)
   tu terminal        el modelo decide                     5 herramientas
                      qué herramientas usa                 sobre APIs públicas

クライアントはツールを実行しません。OpenAIにMCPサーバーの公開URLを渡し、OpenAIがツールの一覧表示、呼び出し、連鎖(都市→座標→天気)を行います。そのため、サーバーはインターネットからアクセス可能である必要があります。OpenAIは自社のサーバーから接続するため、あなたのマシンからではありません。

ツール

ツール

入力

出力

get_lat_lon_from_city

都市名

緯度と経度

get_current_weather

座標

気温、湿度、天気状態

weather_forecast

座標

7日間の予報

get_exchange_rate

2つのISOコード

現在の為替レート

convert_currency

金額 + レート

換算後の金額

天気とジオコーディングはOpen-Meteo(無料、キー不要)を使用。通貨はExchangeRate-APIを使用し、キーが必要です。20通貨に対応(CLIでは/monedas)。

構造

config/settings.py     configuración y logging (todo sale del .env)
server/                herramientas + clientes HTTP de las APIs externas
client/                cliente de OpenAI + interfaz de terminal
main_server.py         arranca el servidor MCP
main_client.py         arranca la conversación

Related MCP server: Python Weather MCP Server

インストール

**Python 3.11+**が必要。uv(推奨)を使用する場合:

git clone <url-del-repo>
cd mcp_training
uv sync

またはpipと仮想環境を使用する場合:

python -m venv .venv
.venv\Scripts\activate        # Windows;  en Linux/macOS: source .venv/bin/activate
pip install -r requirements.txt

設定

サンプルをコピーしてキーを入力:

cp .env.example .env

必須の変数は2つだけ:

変数

用途

API_KEY_EXCHANGE

為替レート(こちらで無料キーを取得)

OPENAI_API_KEY

クライアントのモデル

そして3つ目の変数MCP_PUBLIC_URLは次のステップで設定します。その他(モデル、ポート、トランスポート、タイムアウト、ログレベル)は適切なデフォルト値があり、.env.exampleに記載されています。

使用方法

3つのターミナルが必要:サーバー、トンネル、クライアント。

1. MCPサーバーを起動

uv run python main_server.py

http://127.0.0.1:8002/mcpで待機します。

2. トンネルでサーバーを公開

OpenAIがサーバーに到達するには公開URLが必要です。devtunnelを使用:

devtunnel port create -p 8002 --allow-anonymous
devtunnel host

表示されたURL(https://xxxxxxx-8002.euw.devtunnels.ms)をコピーして.envに設定:

MCP_PUBLIC_URL=https://xxxxxxx-8002.euw.devtunnels.ms

どのトンネルでも構いません(ngrok、Cloudflare Tunnelなど)。URLが外部からアクセス可能であることだけが重要です。クライアントはURLに/mcpが含まれていない場合は自動的に追加します。

3. クライアントを起動

uv run python main_client.py

クエリを入力してEnterキーを押します。会話にはメモリがあり、マドリッドについて尋ねた後、「では明日は?」とだけ言うことができます。

Convierte 100 USD a EUR
¿Cuál es el clima actual en Madrid?
Dame el pronóstico del tiempo para Nueva York

CLIコマンド:

コマンド

機能

/ayuda

ツール、例、コマンドを表示

/monedas

対応通貨コードを表示

/salir

終了(Ctrl+C、Ctrl+Dも可)

クライアントなしでサーバーを使用する

サーバーは標準のMCPサーバーです。互換性のあるクライアントで使用できます。サブプロセスとして接続する場合(Claude Desktop、Claude Codeなど)は、.envにMCP_TRANSPORT=stdioを設定します。これによりトンネルやポートは不要になります。

よくある問題

症状

原因

起動時にAPI_KEY_EXCHANGE Field required

.envまたはキーが不足

クライアントが起動せずMCP_PUBLIC_URLの警告

.envにトンネルのURLが不足

モデルがツールを使用できないと言う

サーバーまたはトンネルがダウンしているか、MCP_PUBLIC_URLが古い(devtunnel hostのたびに変更される)

OpenAIのクォータエラー

残高不足。再試行しても解決しない

各呼び出しの詳細(引数、応答、URL)を確認するには、.envにLOG_LEVEL=DEBUGを設定します。ログはstderrに出力されるため、python main_client.py > charla.txtとすると会話のみが保存されます。

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    A server that integrates the MCP library with OpenAI's API, allowing users to interact with various tools, such as the weather tool, through natural language queries.
    MIT
  • A
    license
    B
    quality
    D
    maintenance
    Enables AI agents to fetch real-time weather data for any location using the OpenWeatherMap API. Demonstrates how to build a simple MCP server that exposes weather information as a tool for LLMs.
    1
    GPL 3.0
  • A
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that enables AI assistants to call weather tools, read resources, and use prompt templates for live weather data integration.
    1,107 npm
    MIT