From 241d5c055b05ac2473f1f7bb4398a3407c21fbb4 Mon Sep 17 00:00:00 2001 From: camysidron1 Date: Mon, 27 Jul 2026 17:28:09 -0700 Subject: [PATCH] Default to strict MCP configuration --- README.md | 9 +++++++++ src/claude_agent_sdk/types.py | 5 ++++- tests/test_transport.py | 10 +++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8d8445238..66c7d53e3 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,15 @@ options = ClaudeAgentOptions( ) ``` +By default, the SDK uses only the MCP servers supplied through `mcp_servers`. +It does not implicitly load project `.mcp.json`, user/global settings, or +plugin-provided MCP servers. Applications that intentionally rely on Claude +Code's ambient MCP discovery can restore that behavior explicitly: + +```python +options = ClaudeAgentOptions(strict_mcp_config=False) +``` + ### Hooks A **hook** is a Python function that the Claude Code _application_ (_not_ Claude) invokes at specific points of the Claude agent loop. Hooks can provide deterministic processing and automated feedback for Claude. Read more in [Intercept and control agent behavior with hooks](https://platform.claude.com/docs/en/agent-sdk/hooks). diff --git a/src/claude_agent_sdk/types.py b/src/claude_agent_sdk/types.py index c5fb86893..fa13de9cb 100644 --- a/src/claude_agent_sdk/types.py +++ b/src/claude_agent_sdk/types.py @@ -1800,10 +1800,13 @@ class ClaudeAgentOptions: to an MCP config JSON file. """ - strict_mcp_config: bool = False + strict_mcp_config: bool = True """When ``True``, only use MCP servers passed via :attr:`mcp_servers`, ignoring all other MCP configurations the CLI would otherwise load (e.g. project ``.mcp.json``, user/global settings, plugin-provided servers). + Defaults to ``True`` so SDK applications do not implicitly execute MCP + servers discovered from their working directory. Set this to ``False`` to + retain Claude Code's ambient MCP discovery behavior. Maps to the CLI's ``--strict-mcp-config`` flag and matches the TypeScript SDK's ``strictMcpConfig`` option.""" diff --git a/tests/test_transport.py b/tests/test_transport.py index 4c1a5abcf..1918bf837 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -92,13 +92,13 @@ def test_build_command_include_hook_events(self): assert "--include-hook-events" not in cmd_off def test_build_command_strict_mcp_config(self): - """Test that --strict-mcp-config is emitted only when enabled.""" - transport = SubprocessCLITransport( - prompt="test", options=make_options(strict_mcp_config=True) - ) + """Test strict MCP isolation is the default and can be disabled.""" + transport = SubprocessCLITransport(prompt="test", options=make_options()) assert "--strict-mcp-config" in transport._build_command() - transport = SubprocessCLITransport(prompt="test", options=make_options()) + transport = SubprocessCLITransport( + prompt="test", options=make_options(strict_mcp_config=False) + ) assert "--strict-mcp-config" not in transport._build_command() def test_build_command_resume_and_session_id(self):