-
Notifications
You must be signed in to change notification settings - Fork 133
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)}`, | ||||||
|
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.
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. | ||
}); |
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