feat: add /ws

This commit is contained in:
Sun-ZhenXing
2025-07-21 00:09:53 +08:00
parent bcb5994356
commit 48f2efef7a
10 changed files with 347 additions and 51 deletions

View File

@@ -2,7 +2,9 @@ import contextlib
from fastapi import FastAPI
from .__about__ import __version__
from .app import MCP_MAP
from .config import settings
from .routers.helpers import router as helpers_router
@@ -14,13 +16,21 @@ async def lifespan(app: FastAPI):
yield
app = FastAPI(lifespan=lifespan)
app = FastAPI(
title=settings.app_title,
description=settings.app_description,
version=__version__,
lifespan=lifespan,
)
@app.get("/")
async def root():
"""Root endpoint."""
return {"message": "Welcome!"}
return {
"message": "Welcome!",
"tools": list(MCP_MAP.keys()),
}
@app.get("/health")
@@ -28,12 +38,16 @@ async def health():
"""Check the health of the server and list available tools."""
return {
"status": "healthy",
"tools": list(MCP_MAP.keys()),
}
app.include_router(helpers_router)
if settings.enable_helpers_router:
app.include_router(helpers_router)
for name, mcp in MCP_MAP.items():
app.mount(f"/{name}/compatible", mcp.sse_app())
app.mount(f"/{name}", mcp.streamable_http_app())
if settings.enable_sse:
app.mount(f"/{name}/compatible", mcp.sse_app())
if settings.enable_streamable_http:
app.mount(f"/{name}", mcp.streamable_http_app())
if settings.enable_websocket:
app.mount(f"/{name}/websocket", mcp.ws_app())