sunpy / app.py
ghh1125's picture
Upload 14 files
7ddcc5d verified
from __future__ import annotations
import importlib
import os
from pathlib import Path
import sys
from typing import Any
from fastapi import FastAPI
BASE_DIR = Path(__file__).resolve().parent
PLUGIN_DIR = BASE_DIR / "sunpy" / "mcp_output" / "mcp_plugin"
plugin_str = str(PLUGIN_DIR)
if plugin_str not in sys.path:
sys.path.insert(0, plugin_str)
PORT = int(os.getenv("PORT", "7860"))
app = FastAPI(title="sunpy-mcp-info", version="1.0.0")
@app.get("/")
def root() -> dict[str, Any]:
return {
"service": "sunpy MCP deployment",
"mcp_transport": os.getenv("MCP_TRANSPORT", "stdio"),
"mcp_port": os.getenv("MCP_PORT", "8000"),
"info_app_port": PORT,
}
@app.get("/health")
def health() -> dict[str, str]:
return {"status": "healthy"}
@app.get("/tools")
def tools() -> dict[str, Any]:
try:
module = importlib.import_module("mcp_service")
create_app = getattr(module, "create_app")
mcp = create_app()
tool_items = []
for tool in getattr(mcp, "tools", []):
name = getattr(tool, "name", getattr(tool, "__name__", "unknown"))
description = getattr(tool, "description", getattr(tool, "__doc__", ""))
tool_items.append({"name": str(name), "description": str(description or "")})
return {"count": len(tool_items), "tools": tool_items}
except Exception as exc:
return {"count": 0, "tools": [], "error": str(exc)}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=PORT)