Add support for DNS rebinding protections (#861)
This commit is contained in:
parent
a2f8766a8a
commit
86bb54cb28
1 changed files with 799 additions and 13 deletions
|
|
@ -23,6 +23,7 @@ from mcp.client.sse import sse_client
|
|||
from mcp.client.streamable_http import streamablehttp_client
|
||||
from mcp.server.fastmcp import Context, FastMCP
|
||||
from mcp.server.fastmcp.resources import FunctionResource
|
||||
from mcp.server.transport_security import TransportSecuritySettings
|
||||
from mcp.shared.context import RequestContext
|
||||
from mcp.types import (
|
||||
Completion,
|
||||
|
|
@ -92,7 +93,10 @@ def stateless_http_server_url(stateless_http_server_port: int) -> str:
|
|||
# Create a function to make the FastMCP server app
|
||||
def make_fastmcp_app():
|
||||
"""Create a FastMCP server without auth settings."""
|
||||
mcp = FastMCP(name="NoAuthServer")
|
||||
transport_security = TransportSecuritySettings(
|
||||
allowed_hosts=["127.0.0.1:*", "localhost:*"], allowed_origins=["http://127.0.0.1:*", "http://localhost:*"]
|
||||
)
|
||||
mcp = FastMCP(name="NoAuthServer", transport_security=transport_security)
|
||||
|
||||
# Add a simple tool
|
||||
@mcp.tool(description="A simple echo tool")
|
||||
|
|
@ -121,9 +125,10 @@ def make_fastmcp_app():
|
|||
|
||||
def make_everything_fastmcp() -> FastMCP:
|
||||
"""Create a FastMCP server with all features enabled for testing."""
|
||||
from mcp.server.fastmcp import Context
|
||||
|
||||
mcp = FastMCP(name="EverythingServer")
|
||||
transport_security = TransportSecuritySettings(
|
||||
allowed_hosts=["127.0.0.1:*", "localhost:*"], allowed_origins=["http://127.0.0.1:*", "http://localhost:*"]
|
||||
)
|
||||
mcp = FastMCP(name="EverythingServer", transport_security=transport_security)
|
||||
|
||||
# Tool with context for logging and progress
|
||||
@mcp.tool(description="A tool that demonstrates logging and progress", title="Progress Tool")
|
||||
|
|
@ -333,8 +338,10 @@ def make_everything_fastmcp_app():
|
|||
|
||||
def make_fastmcp_streamable_http_app():
|
||||
"""Create a FastMCP server with StreamableHTTP transport."""
|
||||
|
||||
mcp = FastMCP(name="NoAuthServer")
|
||||
transport_security = TransportSecuritySettings(
|
||||
allowed_hosts=["127.0.0.1:*", "localhost:*"], allowed_origins=["http://127.0.0.1:*", "http://localhost:*"]
|
||||
)
|
||||
mcp = FastMCP(name="NoAuthServer", transport_security=transport_security)
|
||||
|
||||
# Add a simple tool
|
||||
@mcp.tool(description="A simple echo tool")
|
||||
|
|
@ -359,8 +366,10 @@ def make_everything_fastmcp_streamable_http_app():
|
|||
|
||||
def make_fastmcp_stateless_http_app():
|
||||
"""Create a FastMCP server with stateless StreamableHTTP transport."""
|
||||
|
||||
mcp = FastMCP(name="StatelessServer", stateless_http=True)
|
||||
transport_security = TransportSecuritySettings(
|
||||
allowed_hosts=["127.0.0.1:*", "localhost:*"], allowed_origins=["http://127.0.0.1:*", "http://localhost:*"]
|
||||
)
|
||||
mcp = FastMCP(name="StatelessServer", stateless_http=True, transport_security=transport_security)
|
||||
|
||||
# Add a simple tool
|
||||
@mcp.tool(description="A simple echo tool")
|
||||
|
|
|
|||
Loading…
Reference in a new issue