Skip to content

Conversation

ltawfik
Copy link
Collaborator

@ltawfik ltawfik commented Jul 3, 2025

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

- Add strict_mcp_config boolean field to ClaudeCodeOptions
- Pass --strict-mcp-config CLI flag when option is True
- Add tests for the new option
- Add example demonstrating usage
- Update README with MCP server configuration docs

This enables SDK users to ignore all file-based MCP configurations
and use only programmatically specified servers.

Fixes #45

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ltawfik ltawfik self-assigned this Jul 3, 2025
ltawfik added 4 commits July 3, 2025 14:56
- Remove trailing whitespace from test files
- Consolidate strict_mcp_config test into test_default_options
- Keep only the essential transport test for CLI flag verification
- Remove separate strict_mcp_config_example.py file
- Add with_strict_mcp_config_example() to quick_start.py
- Use simpler query() function for consistency
- Add comment to main() about uncommenting MCP example if servers configured
- Simplify quick_start.py to just basic examples (~45 lines)
- Move tools example to dedicated using_tools.py file
- Move MCP configuration example to mcp_servers.py file
- No new content added - just reorganized existing examples

This makes the quick start truly quick and provides dedicated
files for users who need specific advanced features.
@ltawfik ltawfik force-pushed the feat/strict-mcp-config branch from 677801b to affe3c9 Compare July 3, 2025 23:59
@ltawfik ltawfik requested a review from ashwin-ant July 4, 2025 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants