File size: 1,784 Bytes
06f7446
 
697d6c3
 
06f7446
 
 
 
697d6c3
06f7446
 
 
 
 
 
697d6c3
 
 
06f7446
697d6c3
06f7446
 
 
 
 
697d6c3
 
06f7446
697d6c3
06f7446
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
697d6c3
 
06f7446
 
 
 
 
 
 
 
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
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),
    }