claude-agent-sdk-python
claude-agent-sdk-python copied to clipboard
feat: add strict_mcp_config option to Python SDK
Summary
- Add
strict_mcp_configoption 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-configCLI flag
Changes
- Add
strict_mcp_config: bool = Falsefield toClaudeCodeOptionsdataclass - Update
SubprocessCLITransportto pass--strict-mcp-configflag 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