Skip to content

fix: correct NumberSchema minimum/maximum/default types from integer to number#2713

Closed
dashitongzhi wants to merge 1 commit into
modelcontextprotocol:mainfrom
dashitongzhi:fix/number-schema-minimum-maximum-type
Closed

fix: correct NumberSchema minimum/maximum/default types from integer to number#2713
dashitongzhi wants to merge 1 commit into
modelcontextprotocol:mainfrom
dashitongzhi:fix/number-schema-minimum-maximum-type

Conversation

@dashitongzhi
Copy link
Copy Markdown

Summary

Fixes #2698

The --defaultNumberType integer flag in scripts/generate-schemas.ts converts all TypeScript number types to JSON Schema integer during schema generation. While this is correct for most fields (request IDs, ports, etc.), it incorrectly converts NumberSchema's minimum, maximum, and default properties to integer type. These fields should be number type because they define constraints for schemas that can have "type": "number".

Changes

scripts/generate-schemas.ts

  • Added fixNumberSchemaTypes() post-processing function that corrects NumberSchema.minimum, NumberSchema.maximum, and NumberSchema.default from integer to number in generated JSON schemas
  • Applied the fix in both the generation path and the check/validation path to ensure consistency

schema/2025-11-25/schema.json and schema/draft/schema.json

  • Changed NumberSchema.default, NumberSchema.maximum, and NumberSchema.minimum from "type": "integer" to "type": "number"

Before

"minimum": { "type": "integer" },
"maximum": { "type": "integer" },
"default": { "type": "integer" }

After

"minimum": { "type": "number" },
"maximum": { "type": "number" },
"default": { "type": "number" }

…to number

The  flag in the schema generation script
converts all TypeScript  types to JSON Schema . While
correct for most fields, NumberSchema's , , and
 properties must remain  type since they define
constraints for schemas that may have .

Fixes modelcontextprotocol#2698
Copilot AI review requested due to automatic review settings May 12, 2026 01:33
@dashitongzhi dashitongzhi requested a review from a team as a code owner May 12, 2026 01:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes schema generation so NumberSchema.minimum, NumberSchema.maximum, and NumberSchema.default are emitted as JSON Schema "type": "number" (not "integer"), resolving #2698 and ensuring numeric constraints can represent non-integers.

Changes:

  • Added a post-processing step in scripts/generate-schemas.ts to correct NumberSchema min/max/default types after generation (and in --check mode).
  • Updated the generated JSON schemas (draft and 2025-11-25) to reflect "type": "number" for those properties.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
scripts/generate-schemas.ts Adds post-processing to correct NumberSchema property types during generation and check paths.
schema/draft/schema.json Updates NumberSchema min/max/default to "number".
schema/2025-11-25/schema.json Updates NumberSchema min/max/default to "number".

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +32 to +44
let content = readFileSync(schemaPath, 'utf-8');
const schema = JSON.parse(content);

const numberSchema = schema.$defs?.NumberSchema ?? schema.definitions?.NumberSchema;
if (numberSchema?.properties) {
for (const prop of ['minimum', 'maximum', 'default']) {
if (numberSchema.properties[prop]?.type === 'integer') {
numberSchema.properties[prop].type = 'number';
}
}
}

writeFileSync(schemaPath, JSON.stringify(schema, null, 2) + '\n', 'utf-8');
Comment on lines +104 to 118
// Fix NumberSchema properties that were incorrectly converted to integer
const parsedSchema = JSON.parse(expectedSchema);
const numberSchema = parsedSchema.$defs?.NumberSchema ?? parsedSchema.definitions?.NumberSchema;
if (numberSchema?.properties) {
for (const prop of ['minimum', 'maximum', 'default']) {
if (numberSchema.properties[prop]?.type === 'integer') {
numberSchema.properties[prop].type = 'number';
}
}
}
expectedSchema = JSON.stringify(parsedSchema, null, 2) + '\n';

// Compare
if (existingSchema.trim() !== expectedSchema.trim()) {
console.error(` ✗ Schema ${version} is out of date!`);
@localden
Copy link
Copy Markdown
Contributor

#2710

@localden localden closed this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NumberSchema shows "minimum", "maximum" as integer rather than number

3 participants