Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
5 changes: 4 additions & 1 deletion src/claude_agent_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
10 changes: 5 additions & 5 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down