feat(mcp-server): curated tool registry & input validation (MCP Prompt 10)#4011
feat(mcp-server): curated tool registry & input validation (MCP Prompt 10)#4011gilgardosh wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a curated tool registry (ToolRegistry) and validation layer (validateToolInput) using Zod schemas for strict input validation, along with corresponding unit tests. The feedback suggests replacing the non-standard z.toJSONSchema method with the explicitly imported zodToJsonSchema function from zod-to-json-schema to ensure runtime compatibility and type safety.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| return this.list().map(tool => ({ | ||
| name: tool.name, | ||
| description: tool.description, | ||
| inputSchema: z.toJSONSchema(tool.inputSchema) as Record<string, unknown>, |
There was a problem hiding this comment.
Use the explicitly imported zodToJsonSchema function instead of the non-standard z.toJSONSchema to ensure compatibility, type safety, and avoid runtime errors.
| inputSchema: z.toJSONSchema(tool.inputSchema) as Record<string, unknown>, | |
| inputSchema: zodToJsonSchema(tool.inputSchema) as Record<string, unknown>, |
There was a problem hiding this comment.
Declining: z.toJSONSchema() is a built-in zod v4 API (the repo pins zod@4.4.3), not global monkey-patching. Verified against the installed version — it returns a valid JSON Schema with additionalProperties: false. Pulling in the separate zod-to-json-schema package (the zod v3 approach) would add an unnecessary dependency. Keeping the built-in.
Generated by Claude Code
| @@ -0,0 +1,169 @@ | |||
| import { z } from 'zod'; | |||
There was a problem hiding this comment.
743418f to
9080929
Compare
Add the production-ready tool registry abstraction (docs/mcp/spec.md §8.3). - src/tools/registry.ts: ToolDefinition (name, description, strict zod input schema, auth policy, pure handler); ToolRegistry with register/get/has/list and duplicate-name rejection; describe() renders input schemas to JSON Schema (additionalProperties:false) for tools/list - validateToolInput(): strict parsing with unknown-field rejection and a deterministic VALIDATION_ERROR payload (code, message, field-path issues) - ToolAuthPolicy / DataClassification / ToolExecutionContext contracts for the policy evaluator and handlers in later steps - unit tests for registration, duplicates, ordering, describe(), and schema validation (valid, missing required, unknown field, type mismatch) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SPMszz9gdZFhNjobRm6Ndo
cc1631c to
94a27f0
Compare
Summary
Implements Prompt 10 – Tool registry contracts and input validation (see
docs/mcp/spec.md§8.3). Adds the curated toolregistry abstraction that later production tools plug into.
Changes
src/tools/registry.tsToolDefinition<Schema>—name,description, a strictzodinputSchema, aToolAuthPolicy, and a purehandler(input, context).ToolAuthPolicy(requiredRoles,requiresBusinessScope,dataClassification) andToolExecutionContext(auth,readScope,correlationId) — contracts the policy evaluator (Prompt 11) and handlers (Prompt 13+) consume.ToolRegistry—register/has/get/list(registration order preserved) withDuplicateToolErroron name collisions;describe()renders each input schema to JSON Schema (additionalProperties: false) fortools/list.validateToolInput()— strict parse (unknown fields rejected) returning either the typed data or a deterministicVALIDATION_ERRORpayload (code,message, field-pathissues).describe()JSON Schema, and validation (valid, missing-required, unknown-field, type-mismatch). 120 tests total.Validation
yarn workspace @accounter/mcp-server test→ 120 passedyarn workspace @accounter/mcp-server lint/typecheck/build→ passNotes
POST /mcp— the smoke tool still answerstools/list/tools/calldirectly. The registry becomes the source of truth once the first real tool + the policy evaluator land (Prompts 11/13); the smoke stub is removed at final wiring (Prompt 24).dataClassification/requiredRolesare defined here but enforced in Prompt 11.🤖 Generated with Claude Code
Generated by Claude Code