Skip to content

feat: support for listing search indexes #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

manoj-pillay-10gen
Copy link
Collaborator

Description

Adding tool support for listSearchIndexes utility
Screenshot 2025-05-13 at 3 47 27 PM

Testing

Shell code added. Waiting for test env setup before submitting actual tests.

@manoj-pillay-10gen manoj-pillay-10gen requested a review from a team as a code owner May 13, 2025 22:48
@manoj-pillay-10gen manoj-pillay-10gen requested review from Copilot and removed request for a team May 13, 2025 22:48
Copy link
Contributor

@Copilot 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 introduces support for listing search indexes in MongoDB collections by adding a dedicated tool and initial integration tests. Key changes include:

  • Addition of the CollectionSearchIndexesTool in the MongoDB tools.
  • Integration tests scaffolding for validating tool metadata and argument handling.
  • Updates to the tool registry to include the new tool.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/integration/tools/mongodb/read/collectionSearchIndexes.test.ts Adds integration test scaffolding for the new search indexes tool.
src/tools/mongodb/tools.ts Registers the new CollectionSearchIndexesTool.
src/tools/mongodb/read/collectionSearchIndexes.ts Implements the tool to list search indexes for a collection.
Comments suppressed due to low confidence (1)

tests/integration/tools/mongodb/read/collectionSearchIndexes.test.ts:19

  • The integration test currently contains a placeholder comment. Once the test environment is set up, please add comprehensive tests to validate the actual functionality of listing search indexes.
    // Real tests to be added once search indexes are supported in test env.

Removing space as suggested by copilot

Co-authored-by: Copilot <[email protected]>
Copy link
Contributor

@Copilot 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 adds support for listing search indexes on a collection by implementing a new tool and creating corresponding integration tests. The changes include:

  • Adding an integration test file with placeholder tests for search indexes.
  • Implementing the CollectionSearchIndexesTool to return search index details.
  • Updating the MongoDbTools list to include the new tool.

Reviewed Changes

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

File Description
tests/integration/tools/mongodb/read/collectionSearchIndexes.test.ts Added a placeholder integration test file for collection search indexes.
src/tools/mongodb/tools.ts Updated the tools registry to include the new CollectionSearchIndexesTool.
src/tools/mongodb/read/collectionSearchIndexes.ts Implemented the new tool logic for listing search indexes.
Comments suppressed due to low confidence (2)

src/tools/mongodb/read/collectionSearchIndexes.ts:6

  • [nitpick] The constant 'ListSearchIndexesArgs' is used in a tool class named 'CollectionSearchIndexesTool'. For consistency, consider renaming it to 'CollectionSearchIndexesArgs'.
export const ListSearchIndexesArgs = {

tests/integration/tools/mongodb/read/collectionSearchIndexes.test.ts:19

  • Ensure to add actual test cases once the test environment supports search indexes to validate the tool's behavior.
// Real tests to be added once search indexes are supported in test env.

Copy link
Contributor

@Copilot 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 adds tool support for listing search indexes in a MongoDB collection. Key changes include the addition of:

  • An integration test file for the new collectionSearchIndexes tool (placeholder tests pending environment setup)
  • An update to the MongoDB tools export to include the new CollectionSearchIndexesTool
  • A new implementation of CollectionSearchIndexesTool that fetches and formats search index data

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/integration/tools/mongodb/read/collectionSearchIndexes.test.ts New integration test file that verifies tool metadata and invalid arguments (tests to be extended as environment is set up)
src/tools/mongodb/tools.ts Updated to include the new CollectionSearchIndexesTool in the MongoDB tools export array
src/tools/mongodb/read/collectionSearchIndexes.ts New tool implementation for listing search indexes with a formatted output
Comments suppressed due to low confidence (1)

tests/integration/tools/mongodb/read/collectionSearchIndexes.test.ts:19

  • [nitpick] Consider adding a TODO referencing the pending issue and outlining detailed test cases to be added once the test environment supports search indexes.
// Real tests to be added once search indexes are supported in test env.

},
...(indexes.map((indexDefinition) => {
return {
text: `Name "${indexDefinition.name}", definition: ${JSON.stringify(indexDefinition.latestDefinition)}`,
Copy link
Preview

Copilot AI May 13, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider formatting the JSON output for better readability if the output is intended for human review, or ensure that downstream consumers are designed to handle the unformatted JSON.

Suggested change
text: `Name "${indexDefinition.name}", definition: ${JSON.stringify(indexDefinition.latestDefinition)}`,
text: `Name "${indexDefinition.name}", definition: ${JSON.stringify(indexDefinition.latestDefinition, null, 2)}`,

Copilot uses AI. Check for mistakes.

@@ -0,0 +1,20 @@
import { describeWithMongoDB } from "../mongodbHelpers.js";
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the WIP PR https://github.com/mongodb-js/mongodb-mcp-server/tree/f556cc3691a62d8e98f374be4ebaa14c4a555642/tests/integration/tools/atlas-search, there's a separate directory for atlas search tests since the setup is different.

Is it worth keeping that directory structure and moving this into an atlas-search directory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Altered directory structure to use proposal in #181

indexName,
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
const provider = await this.ensureConnected();
const indexes = await provider.getSearchIndexes(database, collection, indexName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Would it make sense to cast the result of getSearchIndexes to a known interface with common fields (like name)

Ie I think in some of the tests, we may call getSearchIndexes as well and check if certain properties match what's expected

Copy link
Contributor

@Copilot 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 introduces tool support for listing search indexes within a MongoDB collection by adding a new tool along with its test scaffolding.

  • Added an integration test file for the collection search indexes tool.
  • Introduced a parameter definition for search index parameters in the test helpers.
  • Implemented the CollectionSearchIndexesTool and registered it in the MongoDB tools array.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/integration/tools/atlas-search/read/collectionSearchIndexes.test.ts Added initial integration tests for metadata and invalid arguments validation for search indexes.
tests/integration/helpers.ts Included new collectionWithSearchIndexParameters to support the search indexes utility.
src/tools/mongodb/tools.ts Registered the new CollectionSearchIndexesTool in the MongoDB tools list.
src/tools/mongodb/read/collectionSearchIndexes.ts Implemented the tool to fetch and format search index information from the database.
Comments suppressed due to low confidence (1)

tests/integration/tools/atlas-search/read/collectionSearchIndexes.test.ts:18

  • The current integration test is a placeholder; please add comprehensive tests for listing search indexes once the testing environment supports them.
// Real tests to be added once search indexes are supported in test env.

},
...(indexes.map((indexDefinition) => {
return {
text: `\nName: "${indexDefinition.name}"\nDefinition: ${JSON.stringify(indexDefinition.latestDefinition, null, 2)}\n`,
Copy link
Preview

Copilot AI May 14, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider removing the leading newline in the index detail message to improve the output formatting.

Suggested change
text: `\nName: "${indexDefinition.name}"\nDefinition: ${JSON.stringify(indexDefinition.latestDefinition, null, 2)}\n`,
text: `Name: "${indexDefinition.name}"\nDefinition: ${JSON.stringify(indexDefinition.latestDefinition, null, 2)}\n`,

Copilot uses AI. Check for mistakes.

@manoj-pillay-10gen manoj-pillay-10gen changed the title Support for listing search indexes feat: support for listing search indexes May 14, 2025
@manoj-pillay-10gen manoj-pillay-10gen merged commit da43f52 into search-skunkworks-2025 May 14, 2025
9 checks passed
@manoj-pillay-10gen manoj-pillay-10gen deleted the search-skunkworks-2025_listSearchIndexes branch May 14, 2025 19:25
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.

2 participants