A tool schema is an interface for a model, not just a validator for a human. The model sees the tool name, description, and JSON Schema. If those are vague, it will guess. A schema that accepts anything is not flexible; it is ambiguous.
Start with one job
Name the tool after the outcome, not the implementation:
search_issuesinstead ofgithub_apiread_file_rangeinstead offilesystemcreate_invoice_draftinstead ofstripe
One tool should have one clear side-effect profile. If one operation reads and another writes, split them. This lets a client apply different approval rules and lets a model choose safely.
Make constraints explicit
import { z } from "zod";
const inputSchema = {
query: z.string().min(2).max(200).describe("Issue search text. Plain words, not GitHub search syntax."),
state: z.enum(["open", "closed", "all"]).default("open").describe("Issue state filter."),
limit: z.number().int().min(1).max(50).default(10).describe("Maximum results to return, 1-50."),
cursor: z.string().optional().describe("Opaque pagination cursor from a previous response."),
};
Required, optional, and default values are visible. Units are in field descriptions. Enums remove guesswork. The cursor is opaque so the server can change its pagination implementation without changing the tool contract.
Do not accept a free-form options object that mirrors an upstream API. Expose the two or three fields the task needs. Every extra field is another way for the model to make a mistake and another permission for the server to hold.
Return results the model can use
A useful result is small, labeled, and stable:
return {
content: [
{
type: "text",
text: JSON.stringify({
items: results.map((issue) => ({
id: issue.id,
title: issue.title,
state: issue.state,
url: issue.url,
})),
nextCursor: page.nextCursor ?? null,
}),
},
],
};
Keep raw API payloads out of the model context. Include identifiers and URLs so the result can be verified. If a field is unknown, return null rather than inventing a value. When the tool fails, return an error result instead of a success-shaped string:
return {
isError: true,
content: [{ type: "text", text: "GitHub returned 403 for this repository. Check token scopes." }],
};
The protocol call succeeded; the operation did not. That distinction matters to the agent and to your logs.
Annotations are promises, not decoration
Annotations communicate behavior to clients:
annotations: {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: true,
}
If readOnlyHint is true, the tool must not mutate state. A mislabeled write tool can bypass a user’s expectations. For destructive tools, set destructiveHint: true and design a confirmation path in the client or the workflow. Annotations do not enforce anything by themselves.
Paginate and bound
An unbounded query is a denial-of-service waiting for a large account. Require a limit, default it low, cap it, and return a cursor. For scroll-like operations, return enough metadata for the model to continue without replaying work.
For text content, cap characters and tell the caller what was truncated. For binary content or images, return the appropriate content type only if the client supports it; otherwise return a resource link or an explanation.
Test the contract, not just the happy path
Write tests for:
- Valid minimal input.
- Missing required fields.
- Out-of-range numbers.
- Unknown enum values.
- A permission failure from the upstream API.
- A pagination continuation.
- A result that is too large and must be truncated.
Use the SDK’s in-memory transport for handler tests where possible, and MCP Inspector for an end-to-end check. A schema that passes unit validation but fails every real agent call is not a good schema.
Common anti-patterns
- The universal tool: one
executefunction that takes arbitrary JSON. It looks flexible, but it gives the model no meaningful contract and gives the server no enforceable boundary. - Implicit secrets: accepting an API key as a tool argument. Credentials belong in server configuration, not in model context.
- Silent coercion: converting
"10"to10without telling the caller. It hides client bugs and makes contract drift harder to detect. - Success-shaped failures: returning
"error"as plain text withoutisError. The agent may report success.
Design the schema first, implement second, and test with real agent prompts. The Config Doctor cannot fix tool semantics, but the error guide for schema validation covers the failure path when a model sends the wrong shape.
Sources
Sources were checked on Oct 23, 2026. Versions and client behavior can change; confirm the current documentation before relying on a configuration.