Skip to content

fix: use z.coerce.number() for numeric tool parameters #16

Description

@aborruso

Problem

Numeric parameters (rows, page_size, start, limit, offset, etc.) are defined with z.number() in Zod schemas. Some MCP clients pass these values as JSON strings instead of numbers, causing validation errors:

MCP error -32602: Input validation error:
  "code": "invalid_type",
  "expected": "number",
  "received": "string",
  "path": ["rows"]

Affected files

  • src/tools/package.ts — 11 occurrences (rows, start, facet_limit, page, page_size, content_recent_days, limit, boost weights)
  • src/tools/organization.ts — 2 occurrences (limit, offset)
  • src/tools/datastore.ts — 2 occurrences (limit, offset)

Fix

Replace z.number() with z.coerce.number() for all numeric tool parameters. Zod's coerce converts string "3" → number 3 transparently, with no behavioral change when the value is already a number.

Reproduction

Call ckan_package_search with rows: "3" (string) via a local stdio MCP client — validation fails. The hosted version already handles this correctly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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