mirror of
https://github.com/Sun-ZhenXing/mcp-template-python.git
synced 2026-03-24 11:48:05 +00:00
feat: support stateless mcp
This commit is contained in:
@@ -76,6 +76,7 @@ def main(
|
||||
if selected_mcp is None:
|
||||
click.echo(f"Error: MCP '{mcp}' not found.", err=True)
|
||||
sys.exit(1)
|
||||
assert selected_mcp is not None
|
||||
selected_mcp.run()
|
||||
else:
|
||||
run_server(
|
||||
|
||||
@@ -13,6 +13,7 @@ mcp = FastMCP(
|
||||
allowed_origins=settings.cors.allow_origins.split(","),
|
||||
enable_dns_rebinding_protection=settings.mcp.enable_dns_rebinding_protection,
|
||||
),
|
||||
stateless_http=settings.mcp.stateless_http,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -14,17 +14,20 @@ class MCPSettings(BaseSettings):
|
||||
default_mcp: str = "math"
|
||||
"""Default MCP to be used by the application."""
|
||||
|
||||
stateless_http: bool = True
|
||||
"""Whether the MCP server should operate in stateless mode."""
|
||||
|
||||
instructions: str | None = None
|
||||
"""Instructions to be used by the MCP server, defaults to None."""
|
||||
|
||||
enable_helpers_router: bool = True
|
||||
"""Enable the helpers router for the MCP server."""
|
||||
|
||||
enable_sse: bool = True
|
||||
enable_sse: bool = False
|
||||
"""Enable Server-Sent Events (SSE) for the MCP server."""
|
||||
|
||||
enable_streamable_http: bool = True
|
||||
"""Enable streamable HTTP for the MCP server."""
|
||||
|
||||
enable_dns_rebinding_protection: bool = True
|
||||
enable_dns_rebinding_protection: bool = False
|
||||
"""Enable DNS rebinding protection for MCP server."""
|
||||
|
||||
@@ -25,7 +25,7 @@ app = FastAPI(
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
CORSMiddleware, # type: ignore[arg-type]
|
||||
allow_origins=settings.cors.allow_origins.split(","),
|
||||
allow_credentials=settings.cors.allow_credentials,
|
||||
allow_methods=settings.cors.allow_methods.split(","),
|
||||
|
||||
Reference in New Issue
Block a user