validate_tool_args
Validates a tool-call arguments object against a specified shape, returning validity status, error details, and a ready-to-send retry hint for the LLM to correct mistakes.
Instructions
Validate a tool-call args object against a small shape spec. Returns { valid, error?, retry_hint? } where retry_hint is a ready-to-send LLM feedback message describing exactly what was wrong.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tool_name | Yes | Name of the tool being called (surfaces in retry_hint). | |
| args | Yes | The args object the LLM wants to pass. | |
| shape | Yes | Shape spec mapping field name to type. Types: "string", "number", "boolean", "array", "object". Suffix with "?" for optional. Example: { "name": "string", "age": "number", "tags": "array", "notes": "string?" } |
Implementation Reference
- src/server.ts:137-166 (handler)The function `validateToolArgsTool` that implements the core logic of the 'validate_tool_args' tool. It uses `adapters.shape` to create a validator from the shape spec, calls `validate()`, and returns { valid, error?, retry_hint? }.
function validateToolArgsTool(input: { tool_name: string; args: any; shape: any }) { const validator = adapters.shape(input.shape); const result = validate(input.tool_name, validator, input.args); if (result.valid) { return { content: [ { type: 'text', text: JSON.stringify({ valid: true }, null, 2), }, ], }; } return { content: [ { type: 'text', text: JSON.stringify( { valid: false, error: result.error.validationError, retry_hint: result.error.toLLMFeedback?.() ?? result.error.message, }, null, 2, ), }, ], }; } - src/server.ts:46-51 (schema)The SHAPE_SCHEMA constant defining the shape spec input schema for the tool.
const SHAPE_SCHEMA = { type: 'object', description: 'Shape spec mapping field name to type. Types: "string", "number", "boolean", "array", "object". Suffix with "?" for optional. Example: { "name": "string", "age": "number", "tags": "array", "notes": "string?" }', additionalProperties: { type: 'string' }, } as const; - src/server.ts:53-73 (registration)The tool registration entry for 'validate_tool_args' in the TOOLS array, including its name, description, and inputSchema.
const TOOLS = [ { name: 'validate_tool_args', description: 'Validate a tool-call args object against a small shape spec. Returns { valid, error?, retry_hint? } where retry_hint is a ready-to-send LLM feedback message describing exactly what was wrong.', inputSchema: { type: 'object', properties: { tool_name: { type: 'string', description: 'Name of the tool being called (surfaces in retry_hint).', }, args: { type: 'object', description: 'The args object the LLM wants to pass.', }, shape: SHAPE_SCHEMA, }, required: ['tool_name', 'args', 'shape'], }, }, - src/server.ts:117-123 (registration)The dispatch handler that routes CallToolRequestSchema requests for 'validate_tool_args' to validateToolArgsTool.
server.setRequestHandler(CallToolRequestSchema, async (req) => { const { name, arguments: args } = req.params; try { switch (name) { case 'validate_tool_args': return validateToolArgsTool(args as { tool_name: string; args: any; shape: any }); case 'lint_tool_definition':