mcpField
🌦
🌦️ Weather-MCP

🌦️ Weather-MCP

ローカル
github.com/brunolnettoメディア・デザイン077 週間前に更新

🌦️ Weather-MCP について

Weather-MCPは、米国の気象警報と座標に基づく予報を取得するFastAPIサーバーです。AIエージェントのワークフロー向けで、Pydantic AIによる自然言語での利用にも対応します。

主な機能

  1. 01米国の気象警報の取得
  2. 02地理座標に基づく予報
  3. 03Pydantic AIによる自然言語操作
  4. 04FastMCPによるツール拡張

活用シーン

  1. 01米国の州ごとの警報確認
  2. 02指定座標の天気予報取得

MCP 対応

SSEエンドポイントを備え、FastMCPを通じて米国の気象警報と座標ベースの予報ツールをMCPクライアントに提供します。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

インストール方法は未掲載です

このサーバーのパッケージやリモートエンドポイントはまだ取得できていません。プロジェクトの README の手順に従ってください。

リポジトリ

ツール

ツール一覧はまだ取得されていません

ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。

詳細

🌦️ Weather-MCP

Weather-MCP は、FastMCP および Pydantic AI と連携し、リアルタイムの気象警報と予報を提供する FastAPI サーバーです。ユーザーは自然言語のプロンプトを通じてサーバーとやり取りでき、気象情報にシームレスにアクセスできます。


📋 目次


🚀 特長

  • 米国各州で発令中の気象警報を取得します。
  • 地理座標に基づいて詳細な気象予報を取得します。
  • Pydantic AI による自然言語でのやり取りが可能です。
  • FastMCP を通じて拡張可能なツールセットを提供します。

🛠️ インストール

前提条件
  • Python 3.8 以降
  • OpenAI API キー(OPENAI_API_KEY):OpenAI API キーを取得するには、OpenAI API Keys ページをご覧ください。

セットアップを進める前に、これらの前提条件を満たしていることを確認してください。

手順
  1. リポジトリをクローンします:

    git clone https://github.com/yourusername/weather-mcp.git
    cd weather-mcp
    
  2. 仮想環境を作成して有効化します:

    pip install uv
    uv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. 依存関係をインストールします:

    uv sync
    
  4. OpenAI API キーを設定します

OpenAI のサービスを安全に利用するには、OPENAI_API_KEY 環境変数を設定します。([DEV Community][1])

Unix/Linux/macOS の場合:
export OPENAI_API_KEY="your-api-key-here"

この変更を永続化するには、上記の行をシェルの設定ファイル(例:~/.bashrc、~/.zshrc)に追加し、シェルを再読み込みします。([Hacker News][2])

source ~/.bashrc  # or source ~/.zshrc
Windows(コマンドプロンプト)の場合:
setx OPENAI_API_KEY "your-api-key-here"

変数を設定した後、変更を適用するためにコマンドプロンプトを再起動してください。

Windows(PowerShell)の場合:
$env:OPENAI_API_KEY = "your-api-key-here"
  1. サーバーを起動します:

    python weather_server.py
    

サーバーには http://localhost:8000/sse からアクセスできます。


💡 使用方法

Pydantic AI を介したやり取り

Pydantic AI を通じて自然言語のプロンプトを使い、サーバーとやり取りできます。([YouTube][1])

例:

import asyncio
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerHTTP

# Define the MCP server connection
mcp_server = MCPServerHTTP(url="http://localhost:8000/sse")

# Create the Pydantic AI agent
agent = Agent(
    model="openai:gpt-4o-mini",
    mcp_servers=[mcp_server],
    system_prompt="You are a helpful assistant that provides weather information."
)

async def main():
    prompt = "Are there any weather alerts for California?"
    async with agent.run_mcp_servers():
        result = await agent.run(prompt)
        print(result.output)

if __name__ == "__main__":
    asyncio.run(main())
ツールを直接呼び出す

または、FastMCP のクライアントを使ってツールを直接呼び出すこともできます。

例:

import asyncio
from fastmcp import Client

async def main():
    async with Client("http://localhost:8000/sse") as client:
        tools = await client.list_tools()
        print("Available tools:")
        for tool in tools:
            print(f"- {tool.name}: {tool.description}")

        # Call the get_weather_alerts tool
        state_code = "CA"
        alerts_result = await client.call_tool("get_weather_alerts", {"state": state_code})
        print(f"\nWeather alerts for {state_code}:\n{alerts_result[0].text}")

        # Call the get_weather_forecast tool
        latitude = 34.05
        longitude = -118.25
        forecast_result = await client.call_tool("get_weather_forecast", {
            "latitude": latitude,
            "longitude": longitude
        })
        print(f"\nWeather forecast for ({latitude}, {longitude}):\n{forecast_result[0].text}")

if __name__ == "__main__":
    asyncio.run(main())

📡 API エンドポイント

サーバーは MCP プロトコルを介して、以下のツールを公開します。

  • get_weather_alerts(state: str) -> str 指定した米国の州で発令中の気象警報を取得します。

  • get_weather_forecast(latitude: float, longitude: float) -> str 指定した地理座標の気象予報を取得します。


🤝 貢献

貢献を歓迎します!以下の手順に従ってください。

  1. リポジトリをフォークします。
  2. 新しいブランチを作成します:git checkout -b feature-name。
  3. 変更を加えてコミットします:git commit -m 'Add feature'。
  4. ブランチにプッシュします:git push origin feature-name。
  5. プルリクエストを作成します。([GitHub][2])

大規模な変更の場合は、変更内容について話し合うため、まず issue を作成してください。([Make a README][3])


📄 ライセンス

このプロジェクトは MIT ライセンスの下でライセンスされています。

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。