Skip to content

Conversation

@himanshusinghs
Copy link
Collaborator

Proposed changes

Users were unable to use VectorSearch stage because Zod was using our catch all stage (AnyAggregateStage) before VectorSearchStage to parse and validate even the vector search stage input and it passed through because that schema is a catch all schema.

Because of that, in the input that we received, outputDimension was not transformed ever.

This commit changes the order of application of schema so that VectorSearchStage schema is validated first and then the catch all stage schema.

Checklist

Users were unable to use VectorSearch stage because Zod was using our
catch all stage (AnyAggregateStage) before VectorSearchStage to parse
and validate even the vector seach stage input and it passed through
because that schema is a catch all schema.

Because of that, in the input that we received, outputDimension was not
transformed ever.

This commit changes the order of application of schema so that
VectorSeachStage schema is validated first and then the catch all stage
schema.
@himanshusinghs himanshusinghs requested a review from a team as a code owner December 11, 2025 10:36
Copilot AI review requested due to automatic review settings December 11, 2025 10:36
Copy link
Contributor

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

This PR fixes a bug in the aggregate tool where vector search stages with string outputDimension values were not being properly transformed to numbers. The issue occurred because Zod's catch-all AnyAggregateStage schema was evaluated before the more specific VectorSearchStage schema, preventing proper validation and transformation.

Key Changes:

  • Reordered union schema evaluation to prioritize VectorSearchStage over AnyAggregateStage
  • Added comprehensive integration tests to verify outputDimension string-to-number transformation

Reviewed changes

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

File Description
src/tools/mongodb/read/aggregate.ts Fixed schema union order to evaluate VectorSearchStage before AnyAggregateStage
tests/integration/tools/mongodb/read/aggregate.test.ts Added integration tests for outputDimension transformation and moved import to top of file

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 20130214852

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 80.03%

Totals Coverage Status
Change from base Build 20105837382: 0.0%
Covered Lines: 6631
Relevant Lines: 8204

💛 - Coveralls

@himanshusinghs himanshusinghs merged commit 2762666 into main Dec 11, 2025
19 checks passed
@himanshusinghs himanshusinghs deleted the fix/MCP-336-fixes-aggregate-vector-search-stage branch December 11, 2025 10:47
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.

4 participants