| from __future__ import annotations |
|
|
| import os |
| import sys |
| from pathlib import Path |
| from typing import Any |
|
|
| from fastapi import FastAPI |
|
|
| PLUGIN_DIR = Path(__file__).resolve().parent / "galpy" / "mcp_output" / "mcp_plugin" |
| plugin_str = str(PLUGIN_DIR) |
| if plugin_str not in sys.path: |
| sys.path.insert(0, plugin_str) |
|
|
| app = FastAPI(title="galpy MCP Info App", version="1.0.0") |
|
|
|
|
| @app.get("/") |
| def root() -> dict[str, Any]: |
| return { |
| "name": "galpy MCP Service", |
| "description": "Supplementary info app for local development.", |
| "mcp_entrypoint": "galpy/mcp_output/start_mcp.py", |
| "default_port": int(os.getenv("PORT", "7860")), |
| } |
|
|
|
|
| @app.get("/health") |
| def health() -> dict[str, str]: |
| return {"status": "healthy"} |
|
|
|
|
| @app.get("/tools") |
| def tools() -> dict[str, Any]: |
| from mcp_service import create_app |
|
|
| mcp = create_app() |
| raw_tools = getattr(mcp, "tools", []) |
|
|
| out: list[dict[str, Any]] = [] |
| if isinstance(raw_tools, dict): |
| for name, tool_obj in raw_tools.items(): |
| desc = getattr(tool_obj, "description", "") |
| out.append({"name": str(name), "description": str(desc)}) |
| else: |
| for item in raw_tools: |
| if isinstance(item, dict): |
| out.append( |
| { |
| "name": str(item.get("name", "")), |
| "description": str(item.get("description", "")), |
| } |
| ) |
| else: |
| name = getattr(item, "name", getattr(item, "__name__", "")) |
| desc = getattr(item, "description", "") |
| out.append({"name": str(name), "description": str(desc)}) |
|
|
| return {"count": len(out), "tools": out} |
|
|