Generate custom tool boilerplate with @tool decorator.
Generate custom tool boilerplate with @tool decorator for Claude SDK agents. Use when you need to create reusable functions that extend agent capabilities with structured inputs/outputs.
/plugin marketplace add melodic-software/claude-code-plugins/plugin install google-ecosystem@melodic-softwareGenerate custom tool boilerplate with @tool decorator.
$1: Tool name (snake_case)$ARGUMENTS: Tool description and purpose (after name)You are creating a custom tool for use in custom agents.
Extract:
$1 (required, snake_case)If no name provided, STOP and ask for tool name. If no description provided, STOP and ask for tool purpose.
Based on the tool purpose, determine:
Create tool using @tool decorator:
from typing import Any
from claude_agent_sdk import tool
@tool(
"[tool_name]",
"[Description for agent - when to use this tool]",
{
"param1": str,
"param2": int,
}
)
async def [tool_name](args: dict[str, Any]) -> dict[str, Any]:
"""
[Brief docstring]
"""
try:
# Extract parameters
param1 = args["param1"]
param2 = args.get("param2", default_value)
# Validate inputs
if not param1:
return {
"content": [{"type": "text", "text": "Error: param1 required"}],
"is_error": True
}
# Perform operation
result = perform_operation(param1, param2)
# Return success
return {
"content": [{"type": "text", "text": str(result)}]
}
except Exception as e:
return {
"content": [{"type": "text", "text": f"Error: {str(e)}"}],
"is_error": True
}
from claude_agent_sdk import create_sdk_mcp_server
# Create server with tool
[server_name]_server = create_sdk_mcp_server(
name="[server_name]",
version="1.0.0",
tools=[[tool_name]]
)
from claude_agent_sdk import ClaudeAgentOptions, ClaudeSDKClient
options = ClaudeAgentOptions(
mcp_servers={"[server_name]": [server_name]_server},
allowed_tools=["mcp__[server_name]__[tool_name]"],
system_prompt=system_prompt,
model="opus",
)
# IMPORTANT: Use ClaudeSDKClient for custom tools
async with ClaudeSDKClient(options=options) as client:
await client.query(prompt)
async for message in client.receive_response():
pass
## Tool Created
**Name:** [tool_name]
**Server:** [server_name]
**Tool ID:** mcp__[server_name]__[tool_name]
### Tool Definition
```python
[Generated @tool decorated function]
[Generated server setup]
[Generated configuration]
| Name | Type | Required | Description |
|---|---|---|---|
| param1 | str | Yes | [description] |
| param2 | int | No | [description], default: [value] |
Agent prompt: "[example prompt that triggers tool]" Expected call: [tool_name](param1="value", param2=10) Expected result: "[expected output]"
# Test the tool directly
result = await [tool_name]({"param1": "test", "param2": 10})
assert "content" in result
assert not result.get("is_error", False)
## Notes
- See @tool-design skill for design workflow
- See @custom-tool-patterns.md for patterns
- CRITICAL: Use ClaudeSDKClient (not query()) for custom tools