Replace runtime Ajv with registry-derived Zod validation#53
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Motivation
server.registerTooland the handler-boundary check so there is no divergence between declared and enforced schemas.Description
Ajvimport and the module-scope Ajv instance andvalidatorsmap, and replaced runtime validation with registry-derived Zod schemas stored intoolSchemasused by bothserver.registerTool(inputSchema)and handler validation. (file:lib/mcp-server.js)zodObjectFromJsonSchema/zodForPropertyconversions with support forenum,typevariants (string,number,integer,boolean,object,array), numeric/string/array bounds (minimum/maximum/exclusiveMinimum/exclusiveMaximum,minLength/maxLength,pattern,minItems/maxItems), andadditionalProperties:false->.strict(). (file:lib/mcp-server.js)assertSupportedSchemathat throws on any unrecognized JSON Schema keyword so unsupported features fail loudly at build/test time. (file:lib/mcp-server.js)safeParse, and on failure the existingerrorResultshape is returned with the preserved message"Invalid tool arguments."plus readable Zod issue details. (file:lib/mcp-server.js)server.validateToolInput = async (_tool, args) => args;so the SDK internal input-path does not preempt the handler-boundary correctiveisErrorshape expected by tests and consumers. (file:lib/mcp-server.js)ajvfromdependenciesand regenerated the lockfile, and bumped package/BUILD patch version from1.4.1to1.4.2. (files:package.json,package-lock.json,lib/registry.js)tests/worker.vitest.mjs,tests/registry.test.mjs)Replace runtime Ajv with registry-derived Zod validationaffectinglib/mcp-server.js,lib/registry.js,package.json,package-lock.json,tests/worker.vitest.mjs, andtests/registry.test.mjs.Testing
npm ciandnpm run lintand both completed successfully; lint checks on the modified files passed.npm test(node test suite) andnpm run test:workers(Vitest workerd suite) and all tests passed locally after the change.npm run validate:json,npm run validate:registry, andnpm run wrangler:dry-runand each command succeeded locally.originremote is configured (fatal: 'origin' does not appear to be a git repository), so GitHub Actions CI could not be polled from this checkout and external push/CI verification remains required.Codex Task