claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

feat: add strict_mcp_config option to Python SDK

Open ltawfik opened this issue 5 months ago • 0 comments

Summary

  • Add strict_mcp_config option to Python SDK to enable users to ignore all file-based MCP configurations
  • This is a follow-up to anthropics/claude-cli-internal#4392 which added the --strict-mcp-config CLI flag

Changes

  • Add strict_mcp_config: bool = False field to ClaudeCodeOptions dataclass
  • Update SubprocessCLITransport to pass --strict-mcp-config flag when option is True
  • Add tests for the new option in both types and transport tests
  • Add example demonstrating usage (examples/strict_mcp_config_example.py)
  • Update README with MCP server configuration documentation

Testing

  • Added unit tests for the new field in test_types.py
  • Added transport tests to verify CLI flag is passed correctly
  • All existing tests pass

Example Usage

from claude_code_sdk import ClaudeCodeSDK, ClaudeCodeOptions

# Use strict MCP config to ensure ONLY specified servers are used
options = ClaudeCodeOptions(
    mcp_servers={
        "my-server": {
            "command": "node",
            "args": ["my-mcp-server.js"]
        }
    },
    strict_mcp_config=True  # Ignore all file-based MCP configurations
)

Related

  • CLI implementation: anthropics/claude-cli-internal#4392
  • Original issue: anthropics/claude-cli-internal#45

🤖 Generated with Claude Code

ltawfik avatar Jul 03 '25 21:07 ltawfik