-
Notifications
You must be signed in to change notification settings - Fork 31
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
Changes from 5 commits
859c7bd
0ba5de8
b40882d
5be970c
0192f61
c0f6676
10091a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||
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." | ||||||
), | ||||||
}; | ||||||
|
||||||
export class CollectionSearchIndexesTool extends MongoDBToolBase { | ||||||
protected name = "collection-search-indexes"; | ||||||
protected description = "Describe the search indexes for 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)}`, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
type: "text", | ||||||
}; | ||||||
}) as { text: string; type: "text" }[]), | ||||||
], | ||||||
}; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describeWithMongoDB } from "../mongodbHelpers.js"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Altered directory structure to use proposal in #181 |
||
|
||
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. | ||
}); |
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.
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