Skip to content

feat: allow schema inference from collection validators MCP-603 - #908

Merged
nirinchev merged 3 commits into
mainfrom
ni/schema-validators
Oct 2, 2026
Merged

nirinchev merged 3 commits into
mainfrom
ni/schema-validators

Conversation

@nirinchev

Copy link
Copy Markdown
Contributor

Description

Adds convertMongoDBJSONSchemaToSimplified helper that reads the json schema validator and constructs simplified schema from it instead of using sampling.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 10:08
@nirinchev
nirinchev requested review from a team as code owners October 2, 2026 10:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Several conversions report types that the validator does not permit or omit valid types it accepts.

Review effort: Balanced
Findings: 1 High severity · 5 Medium severity

Open (6)
What changed in this PR

Adds conversion of MongoDB collection validators into simplified schemas without document sampling.

Changes:

  • Adds BSON/JSON Schema type conversion, unions, arrays, documents, encryption, and DBRef handling.
  • Exports and documents the converter.
  • Adds comprehensive tests and updates schema types.
File Description
packages/​mongodb-schema/​src/​types.ts Extends validator schema types.
packages/​mongodb-schema/​src/​schema-converters/​mongodb-to-simplified.ts Implements validator conversion.
packages/​mongodb-schema/​src/​schema-converters/​mongodb-to-simplified.test.ts Tests conversion behavior.
packages/​mongodb-schema/​src/​schema-analyzer.ts Aligns simplified BSON type names.
packages/​mongodb-schema/​src/​index.ts Exports the converter.
packages/​mongodb-schema/​README.md Documents validator-based inference.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/mongodb-schema/src/schema-converters/mongodb-to-simplified.ts Outdated
Comment thread packages/mongodb-schema/src/schema-converters/mongodb-to-simplified.ts Outdated
Comment thread packages/mongodb-schema/src/schema-converters/mongodb-to-simplified.ts Outdated
Comment thread packages/mongodb-schema/src/schema-converters/mongodb-to-simplified.ts Outdated
Comment thread packages/mongodb-schema/src/schema-converters/mongodb-to-simplified.ts Outdated
Comment thread packages/mongodb-schema/src/types.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Array unions, tuple additional items, DBRef detection, and the exported BSON type union currently produce inaccurate results.

Review effort: Balanced
Findings: 3 Medium severity

Open (3)
Resolved since last review (5)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Include Number, RegExp, and Symbol in the public schema type union

packages/​mongodb-schema/​src/​schema-analyzer.ts:131

This newly exported public type is knowingly narrower than the values returned by getSimplifiedSchema: ordinary JavaScript numbers, regular expressions, and symbols produce Number, RegExp, and Symbol. Consumers can therefore write an apparently exhaustive mapping that compiles but fails on valid simplified schemas (the test generator already has to patch in Number). Include all runtime values in the public union and update downstream mappings accordingly.

Medium severity Detect DBRefs from raw properties without type information

packages/​mongodb-schema/​src/​schema-converters/​mongodb-to-simplified.ts:335

DBRef detection is based on fields, but collectFields deliberately omits properties whose subschema has no type information. A valid DBRef-shaped validator commonly uses $id: {} (the repository's standard DBRef definition does this), so even with both names required this path returns Document instead of the DBRef sampling would observe. Detect the two property names from the raw properties map, while continuing to use fields for the simplified document shape.

@nirinchev
nirinchev merged commit c61f784 into main Oct 2, 2026
19 checks passed
@nirinchev
nirinchev deleted the ni/schema-validators branch October 2, 2026 14:34
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.

3 participants