claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

Can I pass custom tools?

Open amitok2 opened this issue 1 year ago • 2 comments

Can i use custom tools to ClaudeOptions, I want to create my own CustomBash tool.

Image

If does, how to do that? where should i configure my tool?

amitok2 avatar Jul 30 '25 15:07 amitok2

@amitok2 it's not possible , you can add your custom MCP instead , claude code use built in tools

alm0ra avatar Aug 01 '25 00:08 alm0ra

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.

qing-ant avatar Mar 24 '26 12:03 qing-ant