| 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 / "dedupe" / "mcp_output" / "mcp_plugin" |
| if str(PLUGIN_DIR) not in sys.path: |
| sys.path.insert(0, str(PLUGIN_DIR)) |
|
|
| app = FastAPI(title="dedupe MCP helper app") |
|
|
|
|
| @app.get("/") |
| def root() -> dict[str, Any]: |
| return { |
| "service": "dedupe-mcp", |
| "description": "Supplementary info app for local development.", |
| "mcp_entrypoint": "dedupe/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]: |
| try: |
| from mcp_service import create_app |
|
|
| mcp = create_app() |
| raw_tools = getattr(mcp, "tools", None) |
|
|
| tool_items: list[Any] |
| if isinstance(raw_tools, dict): |
| tool_items = list(raw_tools.values()) |
| elif isinstance(raw_tools, list): |
| tool_items = raw_tools |
| else: |
| tool_items = [] |
|
|
| tools_payload = [] |
| for tool in tool_items: |
| name = getattr(tool, "name", None) |
| description = getattr(tool, "description", None) |
| if isinstance(tool, dict): |
| name = tool.get("name", name) |
| description = tool.get("description", description) |
| tools_payload.append({"name": name, "description": description}) |
|
|
| return {"count": len(tools_payload), "tools": tools_payload} |
| except Exception as exc: |
| return {"count": 0, "tools": [], "error": str(exc)} |
|
|