# Practical ways to use the Claude Agent SDK
๐ง Define your internal APIs, databases, and domain logic with `
@tool` and let Claude call them.
Custom Tools lets you define your own functions as in-process MCP servers using the `
@tool` decorator, making them callable by Claude during conversations.
๐ Title: Providing Custom Tools to Claude
๐ URL:
๐งฉ Overview
Define tools with `
@tool` (Python) / `tool()` (TypeScript) specifying name, description, schema, and handler. Wrap with `create_sdk_mcp_server` and pass to `mcp_servers`. Annotate side-effect-free tools with `readOnlyHint: true` for parallel execution.
๐ How to use it
Define tools with `
@tool` (Python) / `tool()` (TypeScript) specifying name, description, schema, and handler. Wrap with `create_sdk_mcp_server` and pass to `mcp_servers={"weather": server}`. Tools are exposed to Claude as `mcp__weather__get_temperature`.
๐ Practical usage
- Define internal APIs (customer info, inventory, order status) as `
@tool` and build agents that respond to natural language queries.
- Add `readOnlyHint: true` to read-only tools for parallel execution and lower latency.
- Catch exceptions in handlers and return `is_error=True` so the agent loop continues and Claude retries or tries alternatives.
- Return chart images via `image` blocks (base64) for Claude to analyze visually.
๐ก Use cases
๐ข Natural language access to internal APIs
๐ Chart generation + image analysis pipeline
๐ Fault-tolerant autonomous retry
โ ๏ธ Watch out
Uncaught exceptions in handlers crash the entire `query()`. Always handle errors. Use `tools: ["Read","Grep"]` to restrict which built-in tools are available.
#
ClaudeAgentSDK# #
AI#