Skip to content

Commit 49a75e8

Browse files
committed
save
1 parent 4e68c4a commit 49a75e8

File tree

2 files changed

+71
-15
lines changed

2 files changed

+71
-15
lines changed
Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1+
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
12
import { DbOperationArgs, MongoDBToolBase, SearchIndexArgs } from "../mongodbTool.js";
3+
import { OperationType, ToolArgs } from "../../tool.js";
24

35
export class CreateSearchIndexTool extends MongoDBToolBase {
4-
constructor() {
5-
super(...arguments);
6-
this.name = "create-search-index";
7-
this.description = "Create an Atlas Search index for a collection";
8-
this.argsShape = {
9-
...DbOperationArgs,
10-
name: SearchIndexArgs.name,
11-
type: SearchIndexArgs.type,
12-
analyzer: SearchIndexArgs.analyzer,
13-
mappings: SearchIndexArgs.mappings,
14-
};
15-
this.operationType = "create";
16-
}
17-
async execute({ database, collection, name, type, analyzer, mappings, }) {
6+
protected name = "create-search-index";
7+
protected description = "Create an Atlas Search index for a collection";
8+
protected argsShape = {
9+
...DbOperationArgs,
10+
name: SearchIndexArgs.name,
11+
type: SearchIndexArgs.type,
12+
analyzer: SearchIndexArgs.analyzer,
13+
mappings: SearchIndexArgs.mappings,
14+
};
15+
16+
protected operationType: OperationType = "create";
17+
18+
protected async execute({
19+
database,
20+
collection,
21+
name,
22+
type,
23+
analyzer,
24+
mappings,
25+
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
1826
const provider = await this.ensureConnected();
1927
const indexes = await provider.createSearchIndexes(database, collection, [
2028
{
@@ -26,6 +34,7 @@ export class CreateSearchIndexTool extends MongoDBToolBase {
2634
},
2735
},
2836
]);
37+
2938
return {
3039
content: [
3140
{
@@ -35,4 +44,4 @@ export class CreateSearchIndexTool extends MongoDBToolBase {
3544
],
3645
};
3746
}
38-
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2+
import { DbOperationArgs, MongoDBToolBase, SearchIndexArgs } from "../mongodbTool.js";
3+
import { OperationType, ToolArgs } from "../../tool.js";
4+
import logger, { LogId } from "../../../logger.js";
5+
6+
export class UpdateSearchIndexTool extends MongoDBToolBase {
7+
protected name = "update-search-index";
8+
protected description = "Updates a search index for a collection";
9+
protected argsShape = {
10+
...DbOperationArgs,
11+
name: SearchIndexArgs.name,
12+
analyzer: SearchIndexArgs.analyzer,
13+
mappings: SearchIndexArgs.mappings,
14+
};
15+
16+
protected operationType: OperationType = "update";
17+
18+
protected async execute({
19+
database,
20+
collection,
21+
name,
22+
analyzer,
23+
mappings,
24+
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
25+
const provider = await this.ensureConnected();
26+
logger.info(
27+
LogId.toolExecute,
28+
"server",
29+
`Server started with transport ${JSON.stringify({ definition: { analyzer, mappings } })}`
30+
);
31+
// @ts-expect-error: Interface expects a SearchIndexDefinition. However,
32+
// passing analyzer/mappings at the root for the definition is necessary for the call to succeed.
33+
await provider.updateSearchIndex(database, collection, name, {
34+
analyzer,
35+
mappings,
36+
});
37+
38+
return {
39+
content: [
40+
{
41+
text: `Successfully updated index "${name}" on collection "${collection}" in database "${database}"`,
42+
type: "text",
43+
},
44+
],
45+
};
46+
}
47+
}

0 commit comments

Comments
 (0)