This directory contains examples demonstrating the integration between Claude Code SDK and the Tool Management API.
-
Install the Claude Code SDK:
pip install claude-code-sdk
-
Ensure you have access to the Tool Management API (default: https://arthurcolle--registry.modal.run)
Demonstrates fundamental operations:
- Direct Tool API usage
- Searching for tools
- Executing tools
- Automatic tool execution with
query_with_tools - Tool discovery and availability checking
python examples/tools/basic_tool_usage.pyShows advanced search capabilities:
- Search by capability description
- Find similar tools using vector similarity
- Get tool suggestions for specific tasks
- List tools by namespace/category
python examples/tools/tool_search_and_suggest.pyDemonstrates creating and managing custom tools:
- Creating Python-based tools
- Creating HTTP-based tools
- Batch tool creation
- Updating existing tools
python examples/tools/custom_tool_creation.pyAdvanced examples using execution hooks:
- Monitoring tool usage
- Remote tool execution
- Tool filtering and access control
- Collecting usage metrics
python examples/tools/tool_execution_hooks.pyThe ToolManagementClient provides direct access to the Tool Management API:
from claude_code_sdk.tools import ToolManagementClient
async with ToolManagementClient() as client:
# Search for tools
tools = await client.search_tools("calculator")
# Execute a tool
result = await client.execute_tool(
tool_id=tools[0].id,
input_data={"expression": "2 + 2"}
)The query_with_tools function extends the standard Claude Code query with tool management:
from claude_code_sdk.tools import query_with_tools
async for message in query_with_tools(
prompt="Calculate 10 * 25",
use_remote_tools=True
):
print(message)Hooks allow you to intercept and control tool execution:
from claude_code_sdk.tools import ToolExecutionHooks
hooks = ToolExecutionHooks(
on_tool_use=lambda t: print(f"Using tool: {t.name}"),
on_tool_result=lambda r: print(f"Result: {r.content}"),
use_remote_tools=True
)The ToolDiscovery class provides utilities for finding and suggesting tools:
from claude_code_sdk.tools import ToolDiscovery
discovery = ToolDiscovery(client)
suggestions = await discovery.suggest_tools_for_task(
"analyze sentiment in text"
)The Tool Management API provides these main endpoints:
GET /tools- List all toolsPOST /tools- Create a new toolGET /tools/{id}- Get specific toolPUT /tools/{id}- Update toolDELETE /tools/{id}- Delete toolPOST /tools/search- Search toolsPOST /tools/retrieve- Vector similarity searchPOST /execute_tool- Execute single toolPOST /execute_tools_sequential- Execute tools in sequencePOST /execute_tools_parallel- Execute tools in parallel
Tools can have different action types:
- Python - Execute Python code
- JavaScript - Execute JavaScript code
- HTTP - Make HTTP requests
- Service - Call registered services
- Error Handling: Always wrap tool execution in try-except blocks
- Caching: Use
ToolRegistryfor efficient tool lookups - Monitoring: Use hooks to track tool usage and performance
- Security: Validate tool inputs and outputs
- Namespaces: Organize tools by namespace for better management
If you can't connect to the Tool Management API:
- Check your network connection
- Verify the API URL is correct
- Ensure you have proper authentication (if required)
If tools aren't found:
- Check the tool name spelling
- Try searching with different keywords
- Verify the tool exists in the registry
If tool execution fails:
- Check the input data format matches the tool's schema
- Verify the tool's action configuration is correct
- Check the API logs for detailed error messages