langgraph / app.py
ghh1125's picture
Upload 14 files
b5bd543 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 / "langgraph" / "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)
PORT = int(os.getenv("PORT", "7860"))
app = FastAPI(title="langgraph-mcp-info", version="1.0.0")
@app.get("/")
def root() -> dict[str, Any]:
return {
"service": "langgraph-mcp",
"description": "Supplementary info API for local development",
"mcp_transport": os.getenv("MCP_TRANSPORT", "stdio"),
"mcp_port": os.getenv("MCP_PORT", "8000"),
"port": PORT,
}
@app.get("/health")
def health() -> dict[str, str]:
return {"status": "healthy"}
@app.get("/tools")
def tools() -> dict[str, Any]:
try:
from mcp_service import create_app
mcp = create_app()
tool_items: list[dict[str, str]] = []
tools_obj = getattr(mcp, "tools", None)
if isinstance(tools_obj, dict):
iterable = tools_obj.values()
elif isinstance(tools_obj, list):
iterable = tools_obj
else:
iterable = []
for tool in iterable:
name = getattr(tool, "name", getattr(tool, "__name__", "unknown"))
description = getattr(tool, "description", "")
tool_items.append({"name": str(name), "description": str(description)})
return {"count": len(tool_items), "tools": tool_items}
except Exception as exc:
return {"count": 0, "tools": [], "error": str(exc)}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=PORT)