| from __future__ import annotations |
|
|
| import os |
| import sys |
| from pathlib import Path |
|
|
| from fastapi import FastAPI |
|
|
| ROOT_DIR = Path(__file__).resolve().parent |
| PLUGIN_DIR = (ROOT_DIR / "dateutil" / "mcp_output" / "mcp_plugin").resolve() |
| if str(PLUGIN_DIR) not in sys.path: |
| sys.path.insert(0, str(PLUGIN_DIR)) |
|
|
| app = FastAPI(title="dateutil MCP info app", version="1.0.0") |
|
|
|
|
| @app.get("/") |
| def service_info() -> dict: |
| return { |
| "service": "dateutil-mcp", |
| "description": "Supplementary info API for dateutil MCP deployment", |
| "mcp_entrypoint": "dateutil/mcp_output/start_mcp.py", |
| "transport_default": "stdio", |
| "http_endpoint": "/mcp when MCP_TRANSPORT=http", |
| } |
|
|
|
|
| @app.get("/health") |
| def health() -> dict: |
| return {"status": "healthy"} |
|
|
|
|
| @app.get("/tools") |
| def tools() -> dict: |
| import importlib |
|
|
| service_module = importlib.import_module("mcp_service") |
| create_app = getattr(service_module, "create_app") |
| mcp = create_app() |
| raw_tools = getattr(mcp, "tools", None) |
|
|
| items: list[dict] = [] |
| if isinstance(raw_tools, dict): |
| for key, tool_obj in raw_tools.items(): |
| items.append( |
| { |
| "name": getattr(tool_obj, "name", str(key)), |
| "description": getattr(tool_obj, "description", ""), |
| } |
| ) |
| elif isinstance(raw_tools, list): |
| for tool_obj in raw_tools: |
| items.append( |
| { |
| "name": getattr(tool_obj, "name", "unknown"), |
| "description": getattr(tool_obj, "description", ""), |
| } |
| ) |
|
|
| return {"count": len(items), "tools": items} |
|
|
|
|
| PORT = int(os.getenv("PORT", "7860")) |
|
|