1- import { DbOperationArgs , MongoDBToolBase } from "../mongodbTool.js" ;
2- import { CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
1+ import { DbOperationArgs , MongoDBToolBase } from "../mongodbTool.js" ;
2+ import { CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
33import { ToolArgs , OperationType } from "../../tool.js" ;
4- import { z } from "zod" ;
4+ import { z } from "zod" ;
55
66export const ListSearchIndexesArgs = {
7- indexName : z
8- . string ( )
9- . default ( '' )
10- . optional ( )
11- . describe ( "The name of the index to return information about. Returns all indexes on collection if not provided." ) ,
12- }
7+ indexName : z
8+ . string ( )
9+ . default ( "" )
10+ . optional ( )
11+ . describe (
12+ "The name of the index to return information about. Returns all indexes on collection if not provided."
13+ ) ,
14+ } ;
1315
1416export class CollectionSearchIndexesTool extends MongoDBToolBase {
15- protected name = "collection-search-indexes" ;
16- protected description = "List one or all search indexes on a collection" ;
17- protected argsShape = {
18- ...DbOperationArgs ,
19- ...ListSearchIndexesArgs ,
20- } ;
17+ protected name = "collection-search-indexes" ;
18+ protected description = "List one or all search indexes on a collection" ;
19+ protected argsShape = {
20+ ...DbOperationArgs ,
21+ ...ListSearchIndexesArgs ,
22+ } ;
2123
22- protected operationType : OperationType = "read" ;
24+ protected operationType : OperationType = "read" ;
2325
24- protected async execute ( { database, collection, indexName } : ToolArgs < typeof this . argsShape > ) : Promise < CallToolResult > {
25- const provider = await this . ensureConnected ( ) ;
26- const indexes = await provider
27- . getSearchIndexes ( database , collection , indexName ) ;
26+ protected async execute ( {
27+ database,
28+ collection,
29+ indexName,
30+ } : ToolArgs < typeof this . argsShape > ) : Promise < CallToolResult > {
31+ const provider = await this . ensureConnected ( ) ;
32+ const indexes = await provider . getSearchIndexes ( database , collection , indexName ) ;
2833
29- return {
30- content : [
31- {
32- text : indexName
33- ? `Found ${ indexes . length } search indexes in the collection "${ collection } " with name "${ indexName } ":`
34- : `Found ${ indexes . length } search indexes in the collection "${ collection } "` ,
35- type : "text" ,
36- } ,
37- ...( indexes . map ( ( indexDefinition ) => {
38- return {
39- text : `Name "${ indexDefinition . name } ", definition: ${ JSON . stringify ( indexDefinition . latestDefinition ) } ` ,
40- type : "text" ,
41- } ;
42- } ) as { text : string ; type : "text" } [ ] ) ,
43- ] ,
44- } ;
45- }
46- }
34+ return {
35+ content : [
36+ {
37+ text : indexName
38+ ? `Found ${ indexes . length } search indexes in the collection "${ collection } " with name "${ indexName } ":`
39+ : `Found ${ indexes . length } search indexes in the collection "${ collection } "` ,
40+ type : "text" ,
41+ } ,
42+ ...( indexes . map ( ( indexDefinition ) => {
43+ return {
44+ text : `Name "${ indexDefinition . name } ", definition: ${ JSON . stringify ( indexDefinition . latestDefinition ) } ` ,
45+ type : "text" ,
46+ } ;
47+ } ) as { text : string ; type : "text" } [ ] ) ,
48+ ] ,
49+ } ;
50+ }
51+ }
0 commit comments