causalml / app.py
ghh1125's picture
Upload 14 files
21327b6 verified
Raw
History Blame Contribute Delete
1.37 kB
from __future__ import annotations
import os
import sys
from pathlib import Path
from typing import Any
from fastapi import FastAPI
CURRENT_DIR = Path(__file__).resolve().parent
PLUGIN_DIR = CURRENT_DIR / "causalml" / "mcp_output" / "mcp_plugin"
if str(PLUGIN_DIR) not in sys.path:
sys.path.insert(0, str(PLUGIN_DIR))
app = FastAPI(title="causalml MCP Info API", version="1.0.0")
@app.get("/")
def root() -> dict[str, Any]:
return {
"service": "causalml-mcp",
"description": "Supplementary FastAPI info service for local development.",
"mcp_http_endpoint": "/mcp",
"note": "This app is not the MCP server entrypoint.",
}
@app.get("/health")
def health() -> dict[str, str]:
return {"status": "healthy"}
@app.get("/tools")
def tools() -> dict[str, Any]:
from mcp_service import create_app
mcp = create_app()
discovered: list[dict[str, Any]] = []
for tool in getattr(mcp, "tools", []):
discovered.append(
{
"name": getattr(tool, "name", getattr(tool, "__name__", "unknown")),
"description": getattr(tool, "description", ""),
}
)
return {"count": len(discovered), "tools": discovered}
PORT = int(os.getenv("PORT", "7860"))
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=PORT)