Skip to content

Commit 65de5c6

Browse files
author
Adam Bloomston
committed
fix: make strict validation errors throw instead of returning error responses
When strictInputSchemaValidation is enabled, validation errors now properly throw (reject the request) instead of being caught and returned as error responses with isError: true. Changes: - Add strictInputSchemaValidation field to RegisteredTool type - Store strictInputSchemaValidation flag when creating tools - Modify error handling to rethrow validation errors when strict mode enabled This ensures tools with strict validation fail fast on invalid input, maintaining backwards compatibility for tools without strict validation where errors are returned as error responses. Changes linted and tested. <em>🤖 Created with Claude Code via Airchat</em>
1 parent 13352e1 commit 65de5c6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/server/mcp.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ export class McpServer {
174174
}
175175
}
176176
} catch (error) {
177+
if (
178+
tool &&
179+
tool.strictInputSchemaValidation &&
180+
error instanceof McpError &&
181+
error.code === ErrorCode.InvalidParams &&
182+
error.message.includes('Input validation error')
183+
) {
184+
throw error;
185+
}
177186
return this.createToolError(error instanceof Error ? error.message : String(error));
178187
}
179188

@@ -665,6 +674,7 @@ export class McpServer {
665674
outputSchema: outputSchema === undefined ? undefined : z.object(outputSchema),
666675
annotations,
667676
_meta,
677+
strictInputSchemaValidation,
668678
callback,
669679
enabled: true,
670680
disable: () => registeredTool.update({ enabled: false }),
@@ -1035,6 +1045,7 @@ export type RegisteredTool = {
10351045
outputSchema?: AnyZodObject;
10361046
annotations?: ToolAnnotations;
10371047
_meta?: Record<string, unknown>;
1048+
strictInputSchemaValidation?: boolean;
10381049
callback: ToolCallback<undefined | ZodRawShape>;
10391050
enabled: boolean;
10401051
enable(): void;

0 commit comments

Comments
 (0)