diff --git a/examples/quick_start.py b/examples/quick_start.py index 37d93b0..5387a56 100644 --- a/examples/quick_start.py +++ b/examples/quick_start.py @@ -65,11 +65,42 @@ async def with_tools_example(): print() +async def with_strict_mcp_config_example(): + """Example using strict MCP configuration.""" + print("=== Strict MCP Config Example ===") + + # This ensures ONLY the MCP servers specified here will be used, + # ignoring any global or project-level MCP configurations + options = ClaudeCodeOptions( + mcp_servers={ + "memory-server": { + "command": "npx", + "args": ["@modelcontextprotocol/server-memory"], + } + }, + strict_mcp_config=True, # Ignore all file-based MCP configurations + ) + + async for message in query( + prompt="List the available MCP tools from the memory server", + options=options, + ): + if isinstance(message, AssistantMessage): + for block in message.content: + if isinstance(block, TextBlock): + print(f"Claude: {block.text}") + elif isinstance(message, ResultMessage): + print(f"\nResult: {message.subtype}") + print() + + async def main(): """Run all examples.""" await basic_example() await with_options_example() await with_tools_example() + # Note: Uncomment the line below if you have MCP servers configured + # await with_strict_mcp_config_example() if __name__ == "__main__": diff --git a/examples/strict_mcp_config_example.py b/examples/strict_mcp_config_example.py deleted file mode 100644 index e604353..0000000 --- a/examples/strict_mcp_config_example.py +++ /dev/null @@ -1,41 +0,0 @@ -"""Example demonstrating how to use strict MCP config with Claude SDK. - -This example shows how to use the strict_mcp_config option to ensure -only your programmatically specified MCP servers are used, ignoring -any global or project-level MCP configurations. -""" - -from claude_code_sdk import ClaudeCodeSDK, ClaudeCodeOptions - -async def main(): - # Create options with strict MCP config enabled - # This ensures ONLY the MCP servers specified here will be used - options = ClaudeCodeOptions( - mcp_servers={ - "my-custom-server": { - "command": "npx", - "args": ["@modelcontextprotocol/server-memory"], - } - }, - strict_mcp_config=True, # Ignore all file-based MCP configurations - ) - - # Create SDK instance - sdk = ClaudeCodeSDK() - - # Query Claude with strict MCP config - async with await sdk.query( - "List the available MCP tools from the memory server", - options=options - ) as session: - async for message in session.stream(): - if message.type == "assistant": - print(f"Claude: {message.message.content}") - elif message.type == "result": - print(f"\nResult: {message.subtype}") - if message.result: - print(f"Final output: {message.result}") - -if __name__ == "__main__": - import asyncio - asyncio.run(main()) \ No newline at end of file