Spaces:
Build error
Build error
| from __future__ import annotations | |
| import os | |
| import sys | |
| from pathlib import Path | |
| from typing import Any | |
| from fastapi import FastAPI | |
| BASE_DIR = Path(__file__).resolve().parent | |
| PLUGIN_DIR = BASE_DIR / "snap-python" / "mcp_output" / "mcp_plugin" | |
| if str(PLUGIN_DIR) not in sys.path: | |
| sys.path.insert(0, str(PLUGIN_DIR)) | |
| app = FastAPI(title="snap-python MCP Info API", version="1.0.0") | |
| def root() -> dict[str, Any]: | |
| return { | |
| "service": "snap-python MCP Service", | |
| "mcp_transport": os.getenv("MCP_TRANSPORT", "stdio"), | |
| "mcp_port": int(os.getenv("MCP_PORT", "8000")), | |
| "info": "This FastAPI app is supplementary and does not run the MCP server.", | |
| } | |
| def health() -> dict[str, str]: | |
| return {"status": "healthy"} | |
| def tools() -> dict[str, Any]: | |
| from mcp_service import create_app | |
| mcp = create_app() | |
| tool_items: list[dict[str, Any]] = [] | |
| raw_tools = getattr(mcp, "tools", None) | |
| if isinstance(raw_tools, dict): | |
| for name, value in raw_tools.items(): | |
| description = getattr(value, "description", "") | |
| tool_items.append({"name": str(name), "description": str(description)}) | |
| elif isinstance(raw_tools, list): | |
| for value in raw_tools: | |
| name = getattr(value, "name", "") | |
| description = getattr(value, "description", "") | |
| tool_items.append({"name": str(name), "description": str(description)}) | |
| return {"count": len(tool_items), "tools": tool_items} | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run("app:app", host="0.0.0.0", port=int(os.getenv("PORT", "7860")), reload=False) |