fix: correct NumberSchema minimum/maximum/default types from integer to number#2713
Closed
dashitongzhi wants to merge 1 commit into
Closed
Conversation
…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
There was a problem hiding this comment.
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.tsto correctNumberSchemamin/max/default types after generation (and in--checkmode). - Updated the generated JSON schemas (
draftand2025-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!`); |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2698
The
--defaultNumberType integerflag inscripts/generate-schemas.tsconverts all TypeScriptnumbertypes to JSON Schemaintegerduring schema generation. While this is correct for most fields (request IDs, ports, etc.), it incorrectly convertsNumberSchema'sminimum,maximum, anddefaultproperties tointegertype. These fields should benumbertype because they define constraints for schemas that can have"type": "number".Changes
scripts/generate-schemas.ts
fixNumberSchemaTypes()post-processing function that correctsNumberSchema.minimum,NumberSchema.maximum, andNumberSchema.defaultfromintegertonumberin generated JSON schemasschema/2025-11-25/schema.json and schema/draft/schema.json
NumberSchema.default,NumberSchema.maximum, andNumberSchema.minimumfrom"type": "integer"to"type": "number"Before
After