mirror of
https://github.com/Sun-ZhenXing/mcp-template-python.git
synced 2026-02-04 10:13:31 +00:00
init repo
This commit is contained in:
24
src/mcp_template_python/server.py
Normal file
24
src/mcp_template_python/server.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import contextlib
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from .app.math import mcp as math
|
||||
|
||||
MCP_MAP = {
|
||||
"math": math,
|
||||
}
|
||||
|
||||
|
||||
@contextlib.asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
async with contextlib.AsyncExitStack() as stack:
|
||||
for mcp in MCP_MAP.values():
|
||||
await stack.enter_async_context(mcp.session_manager.run())
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
for name, mcp in MCP_MAP.items():
|
||||
app.mount(f"/{name}/compatible", mcp.sse_app())
|
||||
app.mount(f"/{name}", mcp.streamable_http_app())
|
||||
Reference in New Issue
Block a user