Skip to main content
Glama

Weather MCP

by kaisumi
main.py1.02 kB
from fastapi import FastAPI, HTTPException from fastapi.middleware.cors import CORSMiddleware from mcp import MCPClient import os from dotenv import load_dotenv load_dotenv() app = FastAPI(title="Weather MCP") # CORS設定 app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # MCPクライアントの初期化 mcp_client = MCPClient( api_key=os.getenv("MCP_API_KEY"), base_url=os.getenv("MCP_BASE_URL", "https://api.modelcontextprotocol.io") ) @app.get("/") async def root(): return {"message": "Weather MCP API"} @app.get("/weather/{location}") async def get_weather(location: str): try: # MCPを使用して天気情報を取得 response = await mcp_client.query( prompt=f"Get current weather for {location}", context={"location": location} ) return response except Exception as e: raise HTTPException(status_code=500, detail=str(e))

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/kaisumi/weather-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server