-
Notifications
You must be signed in to change notification settings - Fork 24
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
Merged
manoj-pillay-10gen
merged 7 commits into
search-skunkworks-2025
from
search-skunkworks-2025_listSearchIndexes
May 14, 2025
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
859c7bd
Support for listing search indexes
manoj-pillay-10gen 0ba5de8
Update src/tools/mongodb/read/collectionSearchIndexes.ts
manoj-pillay-10gen b40882d
Prettier reformat
manoj-pillay-10gen 5be970c
Fixed extra space.
manoj-pillay-10gen 0192f61
Matching tool description with description of API
manoj-pillay-10gen c0f6676
Addressed feedback and fixed test
manoj-pillay-10gen 10091a1
Fix lint issues.
manoj-pillay-10gen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {DbOperationArgs, MongoDBToolBase} from "../mongodbTool.js"; | ||
import {CallToolResult} from "@modelcontextprotocol/sdk/types.js"; | ||
import { ToolArgs, OperationType } from "../../tool.js"; | ||
import {z} from "zod"; | ||
|
||
export const ListSearchIndexesArgs = { | ||
indexName: z | ||
.string() | ||
.default('') | ||
.optional() | ||
.describe("The name of the index to return information about. Returns all indexes on collection if not provided."), | ||
Check failure on line 11 in src/tools/mongodb/read/collectionSearchIndexes.ts
|
||
} | ||
|
||
export class CollectionSearchIndexesTool extends MongoDBToolBase { | ||
protected name = "collection-search-indexes"; | ||
protected description = "List one or all search indexes on a collection"; | ||
protected argsShape = { | ||
...DbOperationArgs, | ||
...ListSearchIndexesArgs, | ||
}; | ||
|
||
protected operationType: OperationType = "read"; | ||
|
||
protected async execute({ database, collection, indexName }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> { | ||
const provider = await this.ensureConnected(); | ||
const indexes = await provider | ||
.getSearchIndexes(database, collection, indexName); | ||
|
||
return { | ||
content: [ | ||
{ | ||
text: indexName | ||
? `Found ${indexes.length} search indexes in the collection "${collection}" with name "${indexName}":` | ||
: `Found ${indexes.length} search indexes in the collection "${collection}"`, | ||
type: "text", | ||
}, | ||
...(indexes.map((indexDefinition) => { | ||
return { | ||
text: `Name "${indexDefinition.name}", definition: ${JSON.stringify(indexDefinition.latestDefinition)}`, | ||
type: "text", | ||
}; | ||
}) as { text: string; type: "text" }[]), | ||
], | ||
}; | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
tests/integration/tools/mongodb/read/collectionSearchIndexes.test.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describeWithMongoDB } from "../mongodbHelpers.js"; | ||
|
||
import { | ||
databaseCollectionParameters, | ||
databaseCollectionInvalidArgs, | ||
validateThrowsForInvalidArguments, | ||
validateToolMetadata, | ||
} from "../../../helpers.js"; | ||
|
||
describeWithMongoDB("collectionSearchIndexes tool", (integration) => { | ||
validateToolMetadata( | ||
integration, | ||
"collection-search-indexes", | ||
"Describe the search indexes for a collection", | ||
databaseCollectionParameters | ||
); | ||
validateThrowsForInvalidArguments(integration, "collection-search-indexes", databaseCollectionInvalidArgs); | ||
|
||
// Real tests to be added once search indexes are supported in test env. | ||
}); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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