Schema design and error handling¶
Input schema (required)¶
Every tool must define an inputSchema under Model Context Protocol (MCP) specification 2026-07-28:
- Set
inputSchemato a valid JSON Schema object with roottype: "object", nevernull. - Default to JSON Schema 2020-12 when no
$schemafield is present. - For parameterless tools, specification 2026-07-28 recommends
{"type": "object", "additionalProperties": false}, though{"type": "object"}is also valid. - Keep tool names (
SHOULD) unique per server, case-sensitive, 1 to 128 characters, with onlyA-Z,a-z,0-9,_,-, and..
Changed in 2026-07-28
Specification 2026-07-28, under Specification Enhancement Proposal (SEP) SEP-2106, permits any Became the default dialect in MCP specification 2025-11-25 under SEP-1613. keyword and adds 2 rules. Implementations must not auto-dereference a $ref that resolves to a network URI, and any opt-in must default off. They should bound composition by depth, subschema count, and time against denial of service. Servers should return tools/list in deterministic order for caching. See What's new.
Keep schemas simple and self-documenting. Property descriptions state valid values and when to choose each option.
Good input schema
{
"type": "object",
"additionalProperties": false,
"properties": {
"customer_email": {
"type": "string",
"format": "email",
"maxLength": 254,
"description": "Customer email address for communication and ticket tracking."
},
"issue_type": {
"type": "string",
"enum": ["billing", "technical", "account"],
"description": "Category of the support request. Use 'billing' for payment issues, 'technical' for product problems, or 'account' for login and access issues."
},
"priority": {
"type": "string",
"enum": ["low", "normal", "high", "urgent"],
"default": "normal",
"description": "Urgency level. Use 'urgent' only for system outages affecting multiple users. Default is 'normal' for standard requests."
},
"description": {
"type": "string",
"maxLength": 2000,
"description": "Detailed description of the issue in the customer's own words, including error messages or symptoms."
}
},
"required": ["customer_email", "issue_type", "description"]
}
This schema works for 5 reasons:
"additionalProperties": falserejects unexpected fields before execution (MCP-04).maxLengthcaps free-text payloads (MCP-04).- Enums constrain valid values.
- Descriptions explain when to pick each option.
- Required fields and defaults cover mandatory and common inputs.
In 2020-12, format is an annotation by default. Enable format assertion or add pattern.
Output schema (optional)¶
Tools can define an outputSchema to validate structured results. Three rules apply when you define one:
- Servers must return structured results that conform to the schema.
- MCP clients should validate results against the schema.
- Results can include both unstructured
contentand structuredstructuredContentfields.
Output content guidelines¶
Return structured JSON, not HTML or verbose prose. Use richer content, such as base64 images or resource links, only for media.
Avoid unstructured prose:
{
"message": "Ticket #12345 created successfully. Assigned to IT team. Customer will be notified via email."
}
Return structuredContent with serialized JSON in content for compatibility:
{
"resultType": "complete",
"content": [
{
"type": "text",
"text": "{\"ticket_id\":\"12345\",\"status\":\"open\",\"assigned_team\":\"IT\",\"estimated_response_time\":\"2 hours\",\"next_steps\":[\"Customer notified via email\",\"IT team alerted\",\"Agent will follow up if no response in 2 hours\"]}"
}
],
"structuredContent": {
"ticket_id": "12345",
"status": "open",
"assigned_team": "IT",
"estimated_response_time": "2 hours",
"next_steps": [
"Customer notified via email",
"IT team alerted",
"Agent will follow up if no response in 2 hours"
]
}
}
Two types of errors¶
Tool execution errors. Set isError: true for actionable failures like denied permissions, validation errors, or rate limits:
{
"resultType": "complete",
"content": [
{
"type": "text",
"text": "User lacks permission to approve expenses over $5000. Required role: Finance.Approver. Your roles: Employee. Suggested action: Request approval from the finance team."
}
],
"isError": true
}
Protocol errors. Return JSON-RPC error objects for failures such as malformed requests, unknown tools, or invalid headers.
Changed in 2026-07-28
Specification 2026-07-28 requires resultType on results, such as "complete", "input_required", or "task". Resource-not-found moves from -32002 to -32602 (SEP-2164). Clients should still accept -32002 from older servers. MCP reserves codes -32020 through -32099, such as -32020 (HeaderMismatch), -32021 (MissingRequiredClientCapability), and -32022 (UnsupportedProtocolVersion). See What's new.
Writing effective error messages¶
State what failed, why, and the next step in each tool error.
Effective error messages
Rate limit:
Rate limit exceeded: 100 requests per minute. Current usage: 103 requests.
Wait 45 seconds before retrying or reduce request frequency.
Validation error:
Invalid date format in 'start_date' field. Received: '2024/12/23'.
Expected format: YYYY-MM-DD (for example, '2024-12-23').
Permission error:
Insufficient permissions to delete customer records. Required role: Admin.
Your roles: Viewer, Editor. Contact your administrator to request Admin access.
Resource not found:
No order #12345 is in your account. Verify the order ID and try again.
Never return vague messages such as "Error", "Invalid input", "Permission denied", or "Not found". They give no recovery step.
Security considerations¶
Balance helpfulness with information disclosure
Error messages must help agents recover without exposing sensitive system details.
Never expose these details in error messages:
- Internal file paths, stack traces, or database schemas.
- Other users' data, such as emails, names, or account details.
- Resource existence, which enables enumeration.
- API keys, connection strings, or credentials.
- Internal system architecture or backend service names.
Include safe details:
- The failed operation, like a refund or ticket.
- The business reason, like insufficient permissions or invalid date format.
- The next step, like wait 45 seconds or request approval.
- A sanitized request or correlation ID.
Log full errors server-side for diagnostics, and return sanitized messages.
Secure versus insecure error messages
Insecure (information disclosure):
User john.doe@company.com does not exist in database table 'users'
(connection: sql-prod-eastus.database.windows.net)
Secure alternative:
Unable to process request. Verify the email address and try again.
Request ID: req-abc-123
Insecure (excessive technical detail):
NullReferenceException at OrderService.cs:142 in GetCustomerOrders().
Stack trace: [...]
Secure alternative:
Unable to retrieve orders at this time. Try again or contact support.
Request ID: req-xyz-789
Include tracing information¶
Add a sanitized request ID to correlate tool errors with server logs:
{
"resultType": "complete",
"content": [
{
"type": "text",
"text": "Unable to create ticket due to a temporary service issue. Request ID: req-abc-123. Retry in a few moments."
}
],
"isError": true
}
Specification 2026-07-28 reserves _meta keys traceparent, tracestate, and baggage for OpenTelemetry (SEP-414). When sent, these optional keys must follow W3C Trace Context and W3C Baggage formats. Log stack traces, redacted inputs, user identity, and backend names only server-side, as in Application Insights and Log Analytics.
Schema and error checklist¶
Verify before you expose tools:
- Define a valid 2020-12
inputSchemafor every tool with"additionalProperties": false, string bounds, and no network$refauto-fetch (MCP-04). - Bound schema composition by depth, subschema count, and time (MCP-11).
- Return structured JSON with
resultTypeand conform tooutputSchemawhen declared. - State what failed, why, and the next step without internal paths, schemas, or credentials.
- Add a sanitized request ID for log correlation.
Related risks¶
OWASP MCP Top 10, 2025 edition risks: MCP05 Command Injection and Execution, MCP08 Lack of Audit and Telemetry, MCP10 Context Injection and Over-Sharing