-
Notifications
You must be signed in to change notification settings - Fork 10.2k
fix(github): use z.coerce.number() for numeric parameters to accept string inputs from LLMs #3779
Description
Background
When an LLM calls tools in @modelcontextprotocol/server-github, numeric parameters such as issue_number, pull_number, page, and per_page are sometimes serialized as strings (e.g., "70" instead of 70). The current Zod schemas use z.number(), which strictly rejects string inputs and returns a validation error.
Problem
MCP error -32602: Input validation error: Invalid arguments for tool get_issue:
[{ "code": "invalid_type", "expected": "number", "received": "string", ... }]
This causes tools like get_issue, update_issue, add_issue_comment, get_pull_request, etc. to fail when called by Claude Code (and likely other LLM clients).
Proposed Fix
Replace z.number() with z.coerce.number() for all numeric input parameters in the operations files:
src/github/operations/issues.ts—issue_number,milestone,page,per_pagesrc/github/operations/pulls.ts—pull_number,page,per_pagesrc/github/operations/commits.ts—page,per_pagesrc/github/operations/repository.ts— numeric paramssrc/github/operations/search.ts—page,per_page
z.coerce.number() accepts both 70 and "70", making the server robust to string serialization by LLM clients without changing the validated output type.
Notes
This is a defensive coding practice already used by other MCP server implementations. LLMs tend to produce string values even for numeric fields, so coercion at the boundary is preferable to strict rejection.