rdkit / app.py
ghh1125's picture
Upload 14 files
06f7446 verified
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 / "rdkit" / "mcp_output" / "mcp_plugin"
if str(PLUGIN_DIR) not in sys.path:
sys.path.insert(0, str(PLUGIN_DIR))
app = FastAPI(title="rdkit MCP info app", version="1.0.0")
PORT = int(os.getenv("PORT", "7860"))
@app.get("/")
def root() -> dict[str, Any]:
return {
"service": "rdkit-mcp-service",
"description": "Supplementary API for MCP service metadata (not MCP transport endpoint).",
"mcp_transport": os.getenv("MCP_TRANSPORT", "stdio"),
"mcp_port": os.getenv("MCP_PORT", "8000"),
"info_app_port": PORT,
}
@app.get("/health")
def health() -> dict[str, str]:
return {"status": "healthy"}
def _extract_tools(mcp_obj: Any) -> list[dict[str, str | None]]:
tool_entries = getattr(mcp_obj, "tools", None)
if tool_entries is None:
return []
tools: list[dict[str, str | None]] = []
if isinstance(tool_entries, dict):
iterator = tool_entries.items()
for name, tool in iterator:
description = getattr(tool, "description", None)
tools.append({"name": str(name), "description": description})
elif isinstance(tool_entries, list):
for tool in tool_entries:
name = getattr(tool, "name", str(tool))
description = getattr(tool, "description", None)
tools.append({"name": name, "description": description})
return tools
@app.get("/tools")
def list_tools() -> dict[str, Any]:
from mcp_service import create_app
mcp = create_app()
return {
"count": len(_extract_tools(mcp)),
"tools": _extract_tools(mcp),
}