claude-agent-sdk-python
claude-agent-sdk-python copied to clipboard
Can I pass custom tools?
Can i use custom tools to ClaudeOptions, I want to create my own CustomBash tool.
If does, how to do that? where should i configure my tool?
@amitok2 it's not possible , you can add your custom MCP instead , claude code use built in tools
Yes, custom tools are supported via SDK MCP servers. Use the @tool decorator and create_sdk_mcp_server():
from claude_agent_sdk import tool, create_sdk_mcp_server, query, ClaudeAgentOptions
@tool("custom_bash", "Run a custom bash command", {"command": str})
async def custom_bash(args):
# Your custom implementation
return {"content": [{"type": "text", "text": f"Ran: {args['command']}"}]}
server = create_sdk_mcp_server("my_tools", tools=[custom_bash])
async for msg in query(
prompt="Run my custom command",
options=ClaudeAgentOptions(
mcp_servers={"my_tools": server},
allowed_tools=["mcp__my_tools__custom_bash"],
),
):
print(msg)
See examples/mcp_calculator.py for a working example. Closing as answered.