from typing import Any
import httpx
from claude_agent_sdk import tool, create_sdk_mcp_server
# ツールを定義:名前、説明、入力スキーマ、ハンドラー
@tool(
"get_temperature",
"Get the current temperature at a location",
{"latitude": float, "longitude": float},
)
async def get_temperature(args: dict[str, Any]) -> dict[str, Any]:
async with httpx.AsyncClient() as client:
response = await client.get(
"https://api.open-meteo.com/v1/forecast",
params={
"latitude": args["latitude"],
"longitude": args["longitude"],
"current": "temperature_2m",
"temperature_unit": "fahrenheit",
},
)
data = response.json()
# コンテンツ配列を返す - Claude はこれをツール結果として見ます
return {
"content": [
{
"type": "text",
"text": f"Temperature: {data['current']['temperature_2m']}°F",
}
]
}
# ツールをインプロセス MCP サーバーにラップします
weather_server = create_sdk_mcp_server(
name="weather",
version="1.0