• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / mongodb-mcp-server / 15030421235

14 May 2025 08:28PM UTC coverage: 74.11%. First build
15030421235

Pull #252

github

web-flow
Merge 741147a95 into fa6224105
Pull Request #252: feat: Add vector index create and update

207 of 363 branches covered (57.02%)

Branch coverage included in aggregate %.

13 of 22 new or added lines in 3 files covered. (59.09%)

792 of 985 relevant lines covered (80.41%)

52.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.5
/src/tools/mongodb/create/createVectorIndex.ts
1
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
import { buildVectorFields, DbOperationArgs, MongoDBToolBase, VectorIndexArgs } from "../mongodbTool.js";
3
import { OperationType, ToolArgs } from "../../tool.js";
4

5
const VECTOR_INDEX_TYPE = "vectorSearch";
35✔
6
export class CreateVectorIndexTool extends MongoDBToolBase {
7
    protected name = "create-vector-index";
32✔
8
    protected description = "Create an Atlas Vector Search Index for a collection.";
32✔
9
    protected argsShape = {
32✔
10
        ...DbOperationArgs,
11
        name: VectorIndexArgs.name,
12
        vectorDefinition: VectorIndexArgs.vectorDefinition,
13
        filterFields: VectorIndexArgs.filterFields,
14
    };
15

16
    protected operationType: OperationType = "create";
32✔
17

18
    protected async execute({
19
        database,
20
        collection,
21
        name,
22
        vectorDefinition,
23
        filterFields,
24
    }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
NEW
25
        const provider = await this.ensureConnected();
×
26

NEW
27
        const indexes = await provider.createSearchIndexes(database, collection, [
×
28
            {
29
                name,
30
                type: VECTOR_INDEX_TYPE,
31
                definition: { fields: buildVectorFields(vectorDefinition, filterFields) },
32
            },
33
        ]);
34

NEW
35
        return {
×
36
            content: [
37
                {
38
                    text: `Created the vector index ${indexes[0]} on collection "${collection}" in database "${database}"`,
39
                    type: "text",
40
                },
41
            ],
42
        };
43
    }
44
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc