Skip to main content
Glama
app.py2.95 kB
import uvicorn from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from contextlib import asynccontextmanager from .config import manager_config from .database import init_database from .api.settings import router as settings_router from .api.token_usage import router as token_usage_router from .api.logs import router as logs_router from .api.mcp import router as mcp_router from .scheduler import log_cleanup_scheduler from graphiti_pro_core import mcp_status # Lifecycle @asynccontextmanager async def lifespan(app: FastAPI): """Application startup event""" print("🛠️ Initializing backend database...") await init_database() # Initialize and attach SSE observer for MCP status print("🔗 Initializing MCP status SSE observer...") from .api.mcp import get_sse_observer sse_observer = get_sse_observer() mcp_status.attach(sse_observer) print("✅ MCP status SSE observer attached") print("Initializing log cleanup scheduler...") try: log_cleanup_scheduler.initialize() log_cleanup_scheduler.start() print("Log cleanup scheduler initialized and started") except Exception as e: print(f"Warning: Failed to initialize log cleanup scheduler: {e}") print(f"Server starting on port {manager_config.MANAGER_SERVER_PORT}") yield # Cleanup on shutdown print("🔗 Detaching MCP status observer...") mcp_status.detach() print("✅ MCP status observer detached") print("Shutting down log cleanup scheduler...") try: log_cleanup_scheduler.stop() print("Log cleanup scheduler stopped") except Exception as e: print(f"Warning: Error stopping log cleanup scheduler: {e}") # Create FastAPI application app = FastAPI( title="Graphiti MCP Manager API", description="Backend API for managing Graphiti MCP configuration and token usage statistics", version="1.0.0", lifespan=lifespan ) # origins = [ # "http://localhost:*", # "http://manager_frontend:*", # "http://127.0.0.1:*", # ] # Add CORS middleware app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Register routes app.include_router(settings_router, prefix="/api") app.include_router(token_usage_router, prefix="/api") app.include_router(logs_router, prefix="/api") app.include_router(mcp_router, prefix="/api") @app.get("/") async def root(): """Root path""" return {"message": "Graphiti MCP Manager API", "version": "1.0.0"} @app.get("/health") async def health_check(): """Health check""" return {"status": "OK"} async def run_backend_server(): """Run backend server""" config = uvicorn.Config( app, host="0.0.0.0", port=manager_config.MANAGER_SERVER_PORT, reload=False ) server = uvicorn.Server(config) await server.serve()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/itcook/graphiti-mcp-pro'

If you have feedback or need assistance with the MCP directory API, please join our Discord server