File size: 2,297 Bytes
f970651 21e6af8 f970651 21e6af8 f970651 21e6af8 f970651 21e6af8 f970651 21e6af8 f970651 21e6af8 f970651 21e6af8 f970651 21e6af8 f970651 21e6af8 f970651 21e6af8 f970651 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | """Supplementary FastAPI app for local inspection (not MCP runtime entrypoint)."""
from __future__ import annotations
import os
import importlib
import sys
from pathlib import Path
from typing import Any
try:
FastAPI = getattr(importlib.import_module("fastapi"), "FastAPI", None)
except Exception:
FastAPI = None
PLUGIN_DIR = Path(__file__).resolve().parent / "biopython" / "mcp_output" / "mcp_plugin"
plugin_dir_str = str(PLUGIN_DIR)
if plugin_dir_str not in sys.path:
sys.path.insert(0, plugin_dir_str)
if FastAPI is not None:
app = FastAPI(title="biopython-mcp-info", version="1.0.0")
else:
class _FallbackApp:
def get(self, *_args: Any, **_kwargs: Any):
def decorator(func):
return func
return decorator
app = _FallbackApp()
PORT = int(os.getenv("PORT", "7860"))
def _extract_tools(app_obj: Any) -> list[dict[str, str]]:
tools_attr = getattr(app_obj, "tools", None)
if tools_attr is None:
return []
if isinstance(tools_attr, dict):
items = tools_attr.values()
else:
items = tools_attr
tools: list[dict[str, str]] = []
for item in items:
if isinstance(item, dict):
name = str(item.get("name", ""))
description = str(item.get("description", ""))
else:
name = str(getattr(item, "name", getattr(item, "__name__", "")))
description = str(getattr(item, "description", ""))
if name:
tools.append({"name": name, "description": description})
return tools
@app.get("/")
def root() -> dict[str, Any]:
return {
"service": "biopython-mcp-deployment",
"mcp_transport": os.getenv("MCP_TRANSPORT", "stdio"),
"mcp_port": os.getenv("MCP_PORT", "8000"),
"info_port": PORT,
"note": "This FastAPI app is supplementary and does not run the MCP server.",
}
@app.get("/health")
def health() -> dict[str, str]:
return {"status": "healthy"}
@app.get("/tools")
def tools() -> dict[str, Any]:
try:
create_app = getattr(importlib.import_module("mcp_service"), "create_app")
mcp_app = create_app()
return {"tools": _extract_tools(mcp_app)}
except Exception as exc:
return {"tools": [], "error": str(exc)}
|