| from __future__ import annotations |
|
|
| import os |
| import sys |
| import importlib |
| from pathlib import Path |
| from typing import Any |
|
|
| FastAPI = importlib.import_module("fastapi").FastAPI |
|
|
| BASE_DIR = Path(__file__).resolve().parent |
| PLUGIN_DIR = BASE_DIR / "rebound" / "mcp_output" / "mcp_plugin" |
| if str(PLUGIN_DIR) not in sys.path: |
| sys.path.insert(0, str(PLUGIN_DIR)) |
|
|
| app = FastAPI(title="rebound MCP Info App", version="1.0.0") |
|
|
|
|
| def _extract_tools(mcp_app: Any) -> list[dict[str, str]]: |
| tools_attr = getattr(mcp_app, "tools", None) |
| if tools_attr is None: |
| return [] |
|
|
| if isinstance(tools_attr, dict): |
| iterable = tools_attr.values() |
| elif isinstance(tools_attr, list): |
| iterable = tools_attr |
| else: |
| iterable = list(tools_attr) |
|
|
| tools: list[dict[str, str]] = [] |
| for tool in iterable: |
| name = getattr(tool, "name", None) or str(tool) |
| description = getattr(tool, "description", "") or "" |
| tools.append({"name": name, "description": description}) |
| return tools |
|
|
|
|
| @app.get("/") |
| def root() -> dict[str, Any]: |
| return { |
| "service": "rebound-mcp", |
| "description": "Supplementary info API for local development.", |
| "mcp_http_endpoint": "/mcp", |
| "note": "This app does not run the MCP server.", |
| } |
|
|
|
|
| @app.get("/health") |
| def health() -> dict[str, str]: |
| return {"status": "healthy"} |
|
|
|
|
| @app.get("/tools") |
| def list_tools() -> dict[str, Any]: |
| from rebound.mcp_output.mcp_plugin.mcp_service import create_app |
|
|
| mcp_app = create_app() |
| return {"tools": _extract_tools(mcp_app)} |
|
|
|
|
| if __name__ == "__main__": |
| import uvicorn |
|
|
| port = int(os.getenv("PORT", "7860")) |
| uvicorn.run(app, host="0.0.0.0", port=port) |
|
|