[UPDATE PRIMITIVE] Report all validation errors at once instead of one-at-a-time#227
Merged
data-douser merged 5 commits intomainfrom Apr 7, 2026
Merged
Conversation
2 tasks
- Create server/src/lib/tool-validation.ts with formatAllValidationErrors() and patchValidateToolInput() that overrides the SDK's one-at-a-time error reporting - Integrate patchValidateToolInput into server startup - Add comprehensive unit tests in server/test/src/lib/tool-validation.test.ts Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/306c50e7-31e0-4a39-bba5-9cacb4dd1674 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/306c50e7-31e0-4a39-bba5-9cacb4dd1674 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add feature to report all validation errors at once
[UPDATE PRIMITIVE] Report all validation errors at once instead of one-at-a-time
Apr 7, 2026
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances MCP tool input validation so that Zod validation failures report all issues in a single, human-readable error message (instead of only the first issue), applied server-wide by patching the server instance’s validateToolInput.
Changes:
- Adds
server/src/lib/tool-validation.tsto aggregate Zod issues into one message and patchMcpServer.validateToolInput. - Applies the patch during server startup in
server/src/codeql-development-mcp-server.ts. - Adds unit + E2E (InMemoryTransport) tests for aggregated validation messaging and updates the built bundle.
Show a summary per file
| File | Description |
|---|---|
| server/src/lib/tool-validation.ts | New validation formatter + server instance patch to aggregate Zod issues. |
| server/src/codeql-development-mcp-server.ts | Calls patchValidateToolInput(server) during startup to enable the behavior server-wide. |
| server/test/src/lib/tool-validation.test.ts | New unit + E2E tests covering missing required fields, mixed errors, nested paths, and protocol behavior. |
| server/dist/codeql-development-mcp-server.js | Rebuilt bundle reflecting the new validation behavior. |
Copilot's findings
- Files reviewed: 3/5 changed files
- Comments generated: 3
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves server-wide MCP tool input validation by overriding the MCP SDK’s default validateToolInput behavior to report all Zod validation issues in a single error message, reducing iterative retry loops for missing/invalid parameters.
Changes:
- Added aggregated Zod issue formatting (
formatAllValidationErrors) and an instance patch (patchValidateToolInput) to overrideMcpServer.validateToolInput. - Applied the patch during server startup so it affects all registered tools consistently.
- Added unit and E2E (InMemoryTransport) tests to verify aggregated error reporting through both direct calls and the MCP protocol.
Show a summary per file
| File | Description |
|---|---|
| server/src/lib/tool-validation.ts | New module implementing aggregated validation error formatting and the validateToolInput instance patch. |
| server/src/codeql-development-mcp-server.ts | Applies the validation patch at server startup to enable server-wide behavior change. |
| server/test/src/lib/tool-validation.test.ts | Adds unit + E2E tests validating aggregated errors and patched behavior. |
| server/dist/codeql-development-mcp-server.js | Rebuilt bundle including the new validation behavior. |
Copilot's findings
- Files reviewed: 3/5 changed files
- Comments generated: 2
data-douser
approved these changes
Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Update Information
Primitive Details
McpServer.validateToolInput)✅ ALLOWED FILES:
server/src/**/*.ts)server/src/lib/*.ts)server/test/**/*.ts)🚫 FORBIDDEN FILES: None included.
🛑 MANDATORY PR VALIDATION CHECKLIST
Update Metadata
🎯 Changes Description
Current Behavior
The MCP SDK's
getParseErrorMessage()extracts only the first Zod issue when validation fails. Missing three required fields forces three round-trips:Updated Behavior
All violations are reported in one response:
Mixed error types are semicolon-separated:
Motivation
The SDK's
getParseErrorMessage()checkserror.messagefirst (a raw JSON blob fromZodError) then falls back toerror.issues[0]— either way only one issue is surfaced. Zod already collects all errors; the bottleneck is formatting.🔄 Before vs. After Comparison
Functionality Changes
API Changes
No schema changes. The
McpErrorthrown on validation failure now contains an aggregated message instead of a single-issue message. The error code (InvalidParams/-32602) is unchanged.Output Format Changes
🧪 Testing & Validation
Test Coverage Updates
InMemoryTransportverify full MCP protocol flowValidation Scenarios
safeParseAsynccall, different message formattingTest Results
📋 Implementation Details
Files Modified
server/src/lib/tool-validation.ts(new, 133 lines)server/src/codeql-development-mcp-server.ts(+5 lines)server/test/src/lib/tool-validation.test.ts(new, 19 tests)Code Changes Summary
Dependencies
zodand@modelcontextprotocol/sdkexports🔍 Quality Improvements
Bug Fixes (if applicable)
getParseErrorMessage()returnserror.issues[0]despite Zod collecting all issuesvalidateToolInputon the server instance with aggregated error formattingCode Quality Enhancements
formatAllValidationErrorsexported for direct unit testingresolveZodSchemahandles all schema types the SDK supports🔗 References
Related Issues/PRs
🚀 Compatibility & Migration
Backward Compatibility
API Evolution
McpErrortype, same protocol behavior👥 Review Guidelines
For Reviewers
Testing Instructions
📊 Impact Assessment
Server Impact
AI Assistant Impact