Custom Tools Best Practices
Ten practices for designing internal tools that agents call safely and correctly.
Search across all documentation pages
Ten practices for designing internal tools that agents call safely and correctly.
Use this list when reviewing a new tool PR, an MCP server exposure, or a post-incident hardening pass.
http_request, free SQL RW, raw shell).additionalProperties: false, and host-side Pydantic (or equivalent) validation that returns field-level errors.error_code, retryable, and short messages; logs hold stacks and secrets stay out of model context.| Stage | Habits | Exit criterion |
|---|---|---|
| Design | 1-3 | Tool map + schemas + descriptions reviewed |
| Secure | 4-6 | Roles, idempotency, approval matrix documented |
| Ship | 7-8 | Caps and error contract implemented |
| Operate | 9-10 | Version policy + evals + dashboards live |
v2 tool or dual-run.# Pattern: validate → scoped I/O → compact result / structured error
def tool_entry(name: str, arguments_json: str) -> str:
args = validate(name, arguments_json) # raises → INVALID_ARG
try:
data = HANDLERS[name](args) # uses scoped client, timeout, caps
return ok(data)
except RateLimitError:
return err("RATE_LIMIT", retryable=True)
except PermissionError:
return err("AUTH", retryable=False)
except UpstreamError:
return err("UPSTREAM", retryable=True)Least privilege (4), timeouts/caps (7), and structured errors (8). Without them, good descriptions will not save you from incidents.
As few as the task needs. Large catalogs increase wrong-tool choice; use tool search or staging of tools when the set grows.
No. Curate domain actions. Facades beat 1:1 OpenAPI dumps for agent success and safety.
When specialized tools cannot cover open-ended computation and you can sandbox with no egress and hard resource limits.
MCP is a transport and discovery layer. These practices still apply to every tool the server exposes.
Rarely for normal reads. Gate bulk export of sensitive PII and high-cost warehouse scans.
Success rate, p95 latency, retryable error rate, arg validation failures, and eval pass rate per tool - not just "agent finished."
At least each release that touches schemas, and quarterly for deprecations, privilege creep, and unused tools.
Related: What Makes an Internal API a Good Agent Tool
Related: Custom Tools Basics
Related: Wrapping a REST API as an Agent Tool
Related: Versioning and Deprecating Agent Tools Without Breaking Agents
Related: Database Query Tools: Read-Only vs Read-Write Access
Related: Code Execution Tools: Sandboxed Python and Shell Access
Stack versions: Pins from the category manifest (verify at build): OpenRouter (~315+ models, July 2026 pricing/fees); LangGraph 1.0+; CrewAI 1.14+; Microsoft Agent Framework 1.0; Vercel AI SDK 6; Pydantic AI (latest); LlamaIndex (latest); OpenAI Agents SDK (latest + MCP); MCP (Linux Foundation governance); A2A (HTTP+SSE+JSON-RPC 2.0); Solana
@solana/web3.js+@solana/spl-token.
Reviewed by Chris St. John·Last updated Jul 16, 2026