Skip to content

fix(github): use z.coerce.number() for numeric parameters to accept string inputs from LLMs #3779

@shin-i-snneko

Description

@shin-i-snneko

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.tsissue_number, milestone, page, per_page
  • src/github/operations/pulls.tspull_number, page, per_page
  • src/github/operations/commits.tspage, per_page
  • src/github/operations/repository.ts — numeric params
  • src/github/operations/search.tspage, 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions