feat: add mcp TransportSecuritySettings

This commit is contained in:
Sun-ZhenXing
2025-12-24 13:23:03 +08:00
parent 66b47a16bf
commit ac1de02173
6 changed files with 93 additions and 56 deletions

View File

@@ -1,10 +1,19 @@
from operator import add, mul, sub, truediv
from mcp.server.fastmcp import FastMCP
from mcp.server.transport_security import TransportSecuritySettings
from mcp_template_python.config import settings
mcp = FastMCP("math", instructions=settings.mcp.instructions)
mcp = FastMCP(
"math",
instructions=settings.mcp.instructions,
transport_security=TransportSecuritySettings(
allowed_hosts=settings.cors.allow_hosts.split(","),
allowed_origins=settings.cors.allow_origins.split(","),
enable_dns_rebinding_protection=settings.mcp.enable_dns_rebinding_protection,
),
)
@mcp.tool()

View File

@@ -11,6 +11,9 @@ class CORSSettings(BaseSettings):
extra="ignore",
)
allow_hosts: str = "*"
"""CORS allow hosts, defaults to '*'."""
allow_origins: str = "*"
"""CORS allow origins, defaults to '*'."""

View File

@@ -25,3 +25,6 @@ class MCPSettings(BaseSettings):
enable_streamable_http: bool = True
"""Enable streamable HTTP for the MCP server."""
enable_dns_rebinding_protection: bool = True
"""Enable DNS rebinding protection for MCP server."""