A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
feat(mcp): add cli option to disable DNS rebinding protection for the MCP server (#8464)
Kyrre Wahl Kongsgård2c8adc624b61
diff --git a/docs/guides/editor_features/mcp.md b/docs/guides/editor_features/mcp.mdindex 4180c9390e..a0859b24e6 100644--- a/docs/guides/editor_features/mcp.md+++ b/docs/guides/editor_features/mcp.md@@ -99,6 +99,14 @@ Create a .vscode/mcp.json file in your workspace and configure it to connect to}```+### DNS rebinding protection++marimo's MCP server enables DNS rebinding protection by default, which validates the `Host` header on incoming requests. This is common when using proxies, gateways (e.g., ECS), CDNs (Cloudflare), or custom domains, where the forwarded `Host` header won't match the expected local host, causing `421 Misdirected Request` or `Invalid Host Header` errors. Pass `--mcp-allow-remote` to disable this check:++```bash+marimo edit notebook.py --mcp --mcp-allow-remote+```+## MCP Clientmarimo can connect to external MCP servers to add additional tools and context to the [chat panel](ai_completion.md#chat-panel).diff --git a/marimo/_cli/cli.py b/marimo/_cli/cli.pyindex 7c96e1b7dc..61afb73a96 100644--- a/marimo/_cli/cli.py+++ b/marimo/_cli/cli.py@@ -374,6 +374,14 @@ edit_help_msg = "\n".join(hidden=True,help="Enable MCP server endpoint at /mcp/server for LLM integration.",)+ "--mcp-allow-remote",+ is_flag=True,+ default=False,+ type=bool,+ hidden=True,+ help="Allow remote access to MCP server by disabling DNS rebinding protection.",+)@click.option("--server-startup-command",default=None,@@ -426,6 +434,7 @@ def edit(remote_url: Optional[str],convert: bool,mcp: bool,+ mcp_allow_remote: bool,server_startup_command: Optional[str],asset_url: Optional[str],timeout: Optional[float],@@ -573,6 +582,7 @@ def edit(ttl_seconds=session_ttl,remote_url=remote_url,mcp=mcp,+ mcp_allow_remote=mcp_allow_remote,server_startup_command=server_startup_command,asset_url=asset_url,timeout=timeout,diff --git a/marimo/_mcp/server/main.py b/marimo/_mcp/server/main.pyindex 23f90090e5..52bbd3a9ff 100644--- a/marimo/_mcp/server/main.py+++ b/marimo/_mcp/server/main.py@@ -24,13 +24,14 @@ if TYPE_CHECKING:from starlette.types import Receive, Scope, Send-def setup_mcp_server(app: Starlette) -> None:+def setup_mcp_server(app: Starlette, allow_remote: bool = False) -> None:"""Create and configure MCP server for marimo integration.Args:app: Starlette application instance for accessing marimo stateserver_name: Name for the MCP server instancestateless_http: Whether to use stateless HTTP mode+ allow_remote: If True, disable DNS rebinding protection to allow remote access behind proxies.Returns:StreamableHTTPSessionManager: MCP session manager@@ -50,12 +51,21 @@ def setup_mcp_server(app: Starlette) -> None:SUPPORTED_MCP_PROMPTS,)+ transport_security = None+ if allow_remote:+ from mcp.server.transport_security import TransportSecuritySettings++ transport_security = TransportSecuritySettings(+ enable_dns_rebinding_protection=False,+ )+mcp = FastMCP("marimo-mcp-server",stateless_http=True,log_level="WARNING",# Change base path from /mcp to /serverstreamable_http_path="/server",+ transport_security=transport_security,)# Create context for tools and promptsdiff --git a/marimo/_server/start.py b/marimo/_server/start.pyindex 3a7528fb96..c30329331b 100644--- a/marimo/_server/start.py+++ b/marimo/_server/start.py@@ -178,6 +178,7 @@ def start(skew_protection: bool,remote_url: Optional[str] = None,mcp: bool = False,+ mcp_allow_remote: bool = False,server_startup_command: Optional[str] = None,asset_url: Optional[str] = None,timeout: Optional[float] = None,@@ -299,7 +300,7 @@ def start()if mcp_enabled:- setup_mcp_server(app)+ setup_mcp_server(app, allow_remote=mcp_allow_remote)init_state = StarletteServerStateInit(port=external_port,