mongodb-mcp-server 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/code_health.yaml +65 -0
- package/.github/workflows/prepare_release.yaml +45 -0
- package/.github/workflows/publish.yaml +70 -0
- package/.prettierignore +5 -0
- package/.prettierrc.json +37 -0
- package/.vscode/launch.json +17 -0
- package/CONTRIBUTING.md +185 -0
- package/LICENSE +202 -0
- package/README.md +234 -0
- package/dist/common/atlas/apiClient.js +147 -0
- package/dist/common/atlas/apiClient.js.map +1 -0
- package/dist/common/atlas/apiClientError.js +17 -0
- package/dist/common/atlas/apiClientError.js.map +1 -0
- package/dist/config.js +85 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.js +97 -0
- package/dist/logger.js.map +1 -0
- package/dist/server.js +45 -0
- package/dist/server.js.map +1 -0
- package/dist/session.js +30 -0
- package/dist/session.js.map +1 -0
- package/dist/tools/atlas/atlasTool.js +9 -0
- package/dist/tools/atlas/atlasTool.js.map +1 -0
- package/dist/tools/atlas/createAccessList.js +64 -0
- package/dist/tools/atlas/createAccessList.js.map +1 -0
- package/dist/tools/atlas/createDBUser.js +58 -0
- package/dist/tools/atlas/createDBUser.js.map +1 -0
- package/dist/tools/atlas/createFreeCluster.js +51 -0
- package/dist/tools/atlas/createFreeCluster.js.map +1 -0
- package/dist/tools/atlas/createProject.js +53 -0
- package/dist/tools/atlas/createProject.js.map +1 -0
- package/dist/tools/atlas/inspectAccessList.js +41 -0
- package/dist/tools/atlas/inspectAccessList.js.map +1 -0
- package/dist/tools/atlas/inspectCluster.js +42 -0
- package/dist/tools/atlas/inspectCluster.js.map +1 -0
- package/dist/tools/atlas/listClusters.js +97 -0
- package/dist/tools/atlas/listClusters.js.map +1 -0
- package/dist/tools/atlas/listDBUsers.js +52 -0
- package/dist/tools/atlas/listDBUsers.js.map +1 -0
- package/dist/tools/atlas/listOrgs.js +30 -0
- package/dist/tools/atlas/listOrgs.js.map +1 -0
- package/dist/tools/atlas/listProjects.js +42 -0
- package/dist/tools/atlas/listProjects.js.map +1 -0
- package/dist/tools/atlas/tools.js +23 -0
- package/dist/tools/atlas/tools.js.map +1 -0
- package/dist/tools/mongodb/create/createCollection.js +23 -0
- package/dist/tools/mongodb/create/createCollection.js.map +1 -0
- package/dist/tools/mongodb/create/createIndex.js +33 -0
- package/dist/tools/mongodb/create/createIndex.js.map +1 -0
- package/dist/tools/mongodb/create/insertMany.js +33 -0
- package/dist/tools/mongodb/create/insertMany.js.map +1 -0
- package/dist/tools/mongodb/delete/deleteMany.js +31 -0
- package/dist/tools/mongodb/delete/deleteMany.js.map +1 -0
- package/dist/tools/mongodb/delete/dropCollection.js +25 -0
- package/dist/tools/mongodb/delete/dropCollection.js.map +1 -0
- package/dist/tools/mongodb/delete/dropDatabase.js +25 -0
- package/dist/tools/mongodb/delete/dropDatabase.js.map +1 -0
- package/dist/tools/mongodb/metadata/collectionSchema.js +38 -0
- package/dist/tools/mongodb/metadata/collectionSchema.js.map +1 -0
- package/dist/tools/mongodb/metadata/collectionStorageSize.js +28 -0
- package/dist/tools/mongodb/metadata/collectionStorageSize.js.map +1 -0
- package/dist/tools/mongodb/metadata/connect.js +86 -0
- package/dist/tools/mongodb/metadata/connect.js.map +1 -0
- package/dist/tools/mongodb/metadata/dbStats.js +28 -0
- package/dist/tools/mongodb/metadata/dbStats.js.map +1 -0
- package/dist/tools/mongodb/metadata/explain.js +77 -0
- package/dist/tools/mongodb/metadata/explain.js.map +1 -0
- package/dist/tools/mongodb/metadata/listCollections.js +35 -0
- package/dist/tools/mongodb/metadata/listCollections.js.map +1 -0
- package/dist/tools/mongodb/metadata/listDatabases.js +23 -0
- package/dist/tools/mongodb/metadata/listDatabases.js.map +1 -0
- package/dist/tools/mongodb/mongodbTool.js +58 -0
- package/dist/tools/mongodb/mongodbTool.js.map +1 -0
- package/dist/tools/mongodb/read/aggregate.js +38 -0
- package/dist/tools/mongodb/read/aggregate.js.map +1 -0
- package/dist/tools/mongodb/read/collectionIndexes.js +23 -0
- package/dist/tools/mongodb/read/collectionIndexes.js.map +1 -0
- package/dist/tools/mongodb/read/count.js +34 -0
- package/dist/tools/mongodb/read/count.js.map +1 -0
- package/dist/tools/mongodb/read/find.js +51 -0
- package/dist/tools/mongodb/read/find.js.map +1 -0
- package/dist/tools/mongodb/tools.js +41 -0
- package/dist/tools/mongodb/tools.js.map +1 -0
- package/dist/tools/mongodb/update/renameCollection.js +31 -0
- package/dist/tools/mongodb/update/renameCollection.js.map +1 -0
- package/dist/tools/mongodb/update/updateMany.js +56 -0
- package/dist/tools/mongodb/update/updateMany.js.map +1 -0
- package/dist/tools/tool.js +56 -0
- package/dist/tools/tool.js.map +1 -0
- package/eslint.config.js +35 -0
- package/jest.config.js +22 -0
- package/package.json +76 -0
- package/scripts/apply.ts +129 -0
- package/scripts/filter.ts +67 -0
- package/scripts/generate.sh +11 -0
- package/src/common/atlas/apiClient.ts +202 -0
- package/src/common/atlas/apiClientError.ts +21 -0
- package/src/common/atlas/openapi.d.ts +5849 -0
- package/src/config.ts +124 -0
- package/src/errors.ts +13 -0
- package/src/index.ts +30 -0
- package/src/logger.ts +117 -0
- package/src/server.ts +64 -0
- package/src/session.ts +37 -0
- package/src/tools/atlas/atlasTool.ts +10 -0
- package/src/tools/atlas/createAccessList.ts +78 -0
- package/src/tools/atlas/createDBUser.ts +70 -0
- package/src/tools/atlas/createFreeCluster.ts +55 -0
- package/src/tools/atlas/createProject.ts +63 -0
- package/src/tools/atlas/inspectAccessList.ts +44 -0
- package/src/tools/atlas/inspectCluster.ts +47 -0
- package/src/tools/atlas/listClusters.ts +104 -0
- package/src/tools/atlas/listDBUsers.ts +62 -0
- package/src/tools/atlas/listOrgs.ts +34 -0
- package/src/tools/atlas/listProjects.ts +46 -0
- package/src/tools/atlas/tools.ts +23 -0
- package/src/tools/mongodb/create/createCollection.ts +26 -0
- package/src/tools/mongodb/create/createIndex.ts +41 -0
- package/src/tools/mongodb/create/insertMany.ts +40 -0
- package/src/tools/mongodb/delete/deleteMany.ts +38 -0
- package/src/tools/mongodb/delete/dropCollection.ts +27 -0
- package/src/tools/mongodb/delete/dropDatabase.ts +26 -0
- package/src/tools/mongodb/metadata/collectionSchema.ts +41 -0
- package/src/tools/mongodb/metadata/collectionStorageSize.ts +30 -0
- package/src/tools/mongodb/metadata/connect.ts +94 -0
- package/src/tools/mongodb/metadata/dbStats.ts +30 -0
- package/src/tools/mongodb/metadata/explain.ts +90 -0
- package/src/tools/mongodb/metadata/listCollections.ts +38 -0
- package/src/tools/mongodb/metadata/listDatabases.ts +26 -0
- package/src/tools/mongodb/mongodbTool.ts +69 -0
- package/src/tools/mongodb/read/aggregate.ts +45 -0
- package/src/tools/mongodb/read/collectionIndexes.ts +24 -0
- package/src/tools/mongodb/read/count.ts +39 -0
- package/src/tools/mongodb/read/find.ts +62 -0
- package/src/tools/mongodb/tools.ts +41 -0
- package/src/tools/mongodb/update/renameCollection.ts +37 -0
- package/src/tools/mongodb/update/updateMany.ts +65 -0
- package/src/tools/tool.ts +90 -0
- package/src/types/mongodb-redact.d.ts +4 -0
- package/tests/integration/helpers.ts +241 -0
- package/tests/integration/inMemoryTransport.ts +58 -0
- package/tests/integration/server.test.ts +35 -0
- package/tests/integration/tools/atlas/accessLists.test.ts +100 -0
- package/tests/integration/tools/atlas/atlasHelpers.ts +110 -0
- package/tests/integration/tools/atlas/clusters.test.ts +122 -0
- package/tests/integration/tools/atlas/dbUsers.test.ts +80 -0
- package/tests/integration/tools/atlas/orgs.test.ts +24 -0
- package/tests/integration/tools/atlas/projects.test.ts +80 -0
- package/tests/integration/tools/mongodb/create/createCollection.test.ts +138 -0
- package/tests/integration/tools/mongodb/create/createIndex.test.ts +249 -0
- package/tests/integration/tools/mongodb/create/insertMany.test.ts +141 -0
- package/tests/integration/tools/mongodb/delete/deleteMany.test.ts +191 -0
- package/tests/integration/tools/mongodb/delete/dropCollection.test.ts +118 -0
- package/tests/integration/tools/mongodb/delete/dropDatabase.test.ts +114 -0
- package/tests/integration/tools/mongodb/metadata/connect.test.ts +137 -0
- package/tests/integration/tools/mongodb/metadata/listCollections.test.ts +104 -0
- package/tests/integration/tools/mongodb/metadata/listDatabases.test.ts +67 -0
- package/tests/integration/tools/mongodb/read/count.test.ts +138 -0
- package/tsconfig.jest.json +10 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AtlasToolBase } from "./atlasTool.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export class ListProjectsTool extends AtlasToolBase {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.name = "atlas-list-projects";
|
|
7
|
+
this.description = "List MongoDB Atlas projects";
|
|
8
|
+
this.operationType = "read";
|
|
9
|
+
this.argsShape = {
|
|
10
|
+
orgId: z.string().describe("Atlas organization ID to filter projects").optional(),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async execute({ orgId }) {
|
|
14
|
+
this.session.ensureAuthenticated();
|
|
15
|
+
const data = orgId
|
|
16
|
+
? await this.session.apiClient.listOrganizationProjects({
|
|
17
|
+
params: {
|
|
18
|
+
path: {
|
|
19
|
+
orgId,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
: await this.session.apiClient.listProjects();
|
|
24
|
+
if (!data?.results?.length) {
|
|
25
|
+
throw new Error("No projects found in your MongoDB Atlas account.");
|
|
26
|
+
}
|
|
27
|
+
// Format projects as a table
|
|
28
|
+
const rows = data.results
|
|
29
|
+
.map((project) => {
|
|
30
|
+
const createdAt = project.created ? new Date(project.created).toLocaleString() : "N/A";
|
|
31
|
+
return `${project.name} | ${project.id} | ${createdAt}`;
|
|
32
|
+
})
|
|
33
|
+
.join("\n");
|
|
34
|
+
const formattedProjects = `Project Name | Project ID | Created At
|
|
35
|
+
----------------| ----------------| ----------------
|
|
36
|
+
${rows}`;
|
|
37
|
+
return {
|
|
38
|
+
content: [{ type: "text", text: formattedProjects }],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=listProjects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listProjects.js","sourceRoot":"","sources":["../../../src/tools/atlas/listProjects.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IAAnD;;QACc,SAAI,GAAG,qBAAqB,CAAC;QAC7B,gBAAW,GAAG,6BAA6B,CAAC;QAC5C,kBAAa,GAAkB,MAAM,CAAC;QACtC,cAAS,GAAG;YAClB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC,CAAC,QAAQ,EAAE;SACpF,CAAC;IAiCN,CAAC;IA/Ba,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,EAAmC;QAC9D,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC;QAEnC,MAAM,IAAI,GAAG,KAAK;YACd,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,wBAAwB,CAAC;gBAClD,MAAM,EAAE;oBACJ,IAAI,EAAE;wBACF,KAAK;qBACR;iBACJ;aACJ,CAAC;YACJ,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;QAElD,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACxE,CAAC;QAED,6BAA6B;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO;aACpB,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACb,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;YACvF,OAAO,GAAG,OAAO,CAAC,IAAI,MAAM,OAAO,CAAC,EAAE,MAAM,SAAS,EAAE,CAAC;QAC5D,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAChB,MAAM,iBAAiB,GAAG;;EAEhC,IAAI,EAAE,CAAC;QACD,OAAO;YACH,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;SACvD,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ListClustersTool } from "./listClusters.js";
|
|
2
|
+
import { ListProjectsTool } from "./listProjects.js";
|
|
3
|
+
import { InspectClusterTool } from "./inspectCluster.js";
|
|
4
|
+
import { CreateFreeClusterTool } from "./createFreeCluster.js";
|
|
5
|
+
import { CreateAccessListTool } from "./createAccessList.js";
|
|
6
|
+
import { InspectAccessListTool } from "./inspectAccessList.js";
|
|
7
|
+
import { ListDBUsersTool } from "./listDBUsers.js";
|
|
8
|
+
import { CreateDBUserTool } from "./createDBUser.js";
|
|
9
|
+
import { CreateProjectTool } from "./createProject.js";
|
|
10
|
+
import { ListOrganizationsTool } from "./listOrgs.js";
|
|
11
|
+
export const AtlasTools = [
|
|
12
|
+
ListClustersTool,
|
|
13
|
+
ListProjectsTool,
|
|
14
|
+
InspectClusterTool,
|
|
15
|
+
CreateFreeClusterTool,
|
|
16
|
+
CreateAccessListTool,
|
|
17
|
+
InspectAccessListTool,
|
|
18
|
+
ListDBUsersTool,
|
|
19
|
+
CreateDBUserTool,
|
|
20
|
+
CreateProjectTool,
|
|
21
|
+
ListOrganizationsTool,
|
|
22
|
+
];
|
|
23
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/tools/atlas/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,CAAC,MAAM,UAAU,GAAG;IACtB,gBAAgB;IAChB,gBAAgB;IAChB,kBAAkB;IAClB,qBAAqB;IACrB,oBAAoB;IACpB,qBAAqB;IACrB,eAAe;IACf,gBAAgB;IAChB,iBAAiB;IACjB,qBAAqB;CACxB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
2
|
+
export class CreateCollectionTool extends MongoDBToolBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.name = "create-collection";
|
|
6
|
+
this.description = "Creates a new collection in a database. If the database doesn't exist, it will be created automatically.";
|
|
7
|
+
this.argsShape = DbOperationArgs;
|
|
8
|
+
this.operationType = "create";
|
|
9
|
+
}
|
|
10
|
+
async execute({ collection, database }) {
|
|
11
|
+
const provider = await this.ensureConnected();
|
|
12
|
+
await provider.createCollection(database, collection);
|
|
13
|
+
return {
|
|
14
|
+
content: [
|
|
15
|
+
{
|
|
16
|
+
type: "text",
|
|
17
|
+
text: `Collection "${collection}" created in database "${database}".`,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=createCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createCollection.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/create/createCollection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,OAAO,oBAAqB,SAAQ,eAAe;IAAzD;;QACc,SAAI,GAAG,mBAAmB,CAAC;QAC3B,gBAAW,GACjB,0GAA0G,CAAC;QACrG,cAAS,GAAG,eAAe,CAAC;QAE5B,kBAAa,GAAkB,QAAQ,CAAC;IAetD,CAAC;IAba,KAAK,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAmC;QAC7E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAEtD,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,eAAe,UAAU,0BAA0B,QAAQ,IAAI;iBACxE;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
3
|
+
export class CreateIndexTool extends MongoDBToolBase {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.name = "create-index";
|
|
7
|
+
this.description = "Create an index for a collection";
|
|
8
|
+
this.argsShape = {
|
|
9
|
+
...DbOperationArgs,
|
|
10
|
+
keys: z.record(z.string(), z.custom()).describe("The index definition"),
|
|
11
|
+
name: z.string().optional().describe("The name of the index"),
|
|
12
|
+
};
|
|
13
|
+
this.operationType = "create";
|
|
14
|
+
}
|
|
15
|
+
async execute({ database, collection, keys, name, }) {
|
|
16
|
+
const provider = await this.ensureConnected();
|
|
17
|
+
const indexes = await provider.createIndexes(database, collection, [
|
|
18
|
+
{
|
|
19
|
+
key: keys,
|
|
20
|
+
name,
|
|
21
|
+
},
|
|
22
|
+
]);
|
|
23
|
+
return {
|
|
24
|
+
content: [
|
|
25
|
+
{
|
|
26
|
+
text: `Created the index "${indexes[0]}" on collection "${collection}" in database "${database}"`,
|
|
27
|
+
type: "text",
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=createIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createIndex.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/create/createIndex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIrE,MAAM,OAAO,eAAgB,SAAQ,eAAe;IAApD;;QACc,SAAI,GAAG,cAAc,CAAC;QACtB,gBAAW,GAAG,kCAAkC,CAAC;QACjD,cAAS,GAAG;YAClB,GAAG,eAAe;YAClB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAkB,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC;YACvF,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC;SAChE,CAAC;QAEQ,kBAAa,GAAkB,QAAQ,CAAC;IAyBtD,CAAC;IAvBa,KAAK,CAAC,OAAO,CAAC,EACpB,QAAQ,EACR,UAAU,EACV,IAAI,EACJ,IAAI,GAC0B;QAC9B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,QAAQ,EAAE,UAAU,EAAE;YAC/D;gBACI,GAAG,EAAE,IAAI;gBACT,IAAI;aACP;SACJ,CAAC,CAAC;QAEH,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,sBAAsB,OAAO,CAAC,CAAC,CAAC,oBAAoB,UAAU,kBAAkB,QAAQ,GAAG;oBACjG,IAAI,EAAE,MAAM;iBACf;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
3
|
+
export class InsertManyTool extends MongoDBToolBase {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.name = "insert-many";
|
|
7
|
+
this.description = "Insert an array of documents into a MongoDB collection";
|
|
8
|
+
this.argsShape = {
|
|
9
|
+
...DbOperationArgs,
|
|
10
|
+
documents: z
|
|
11
|
+
.array(z.object({}).passthrough().describe("An individual MongoDB document"))
|
|
12
|
+
.describe("The array of documents to insert, matching the syntax of the document argument of db.collection.insertMany()"),
|
|
13
|
+
};
|
|
14
|
+
this.operationType = "create";
|
|
15
|
+
}
|
|
16
|
+
async execute({ database, collection, documents, }) {
|
|
17
|
+
const provider = await this.ensureConnected();
|
|
18
|
+
const result = await provider.insertMany(database, collection, documents);
|
|
19
|
+
return {
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
text: `Inserted \`${result.insertedCount}\` document(s) into collection "${collection}"`,
|
|
23
|
+
type: "text",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
text: `Inserted IDs: ${Object.values(result.insertedIds).join(", ")}`,
|
|
27
|
+
type: "text",
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=insertMany.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insertMany.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/create/insertMany.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,OAAO,cAAe,SAAQ,eAAe;IAAnD;;QACc,SAAI,GAAG,aAAa,CAAC;QACrB,gBAAW,GAAG,wDAAwD,CAAC;QACvE,cAAS,GAAG;YAClB,GAAG,eAAe;YAClB,SAAS,EAAE,CAAC;iBACP,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,gCAAgC,CAAC,CAAC;iBAC5E,QAAQ,CACL,8GAA8G,CACjH;SACR,CAAC;QACQ,kBAAa,GAAkB,QAAQ,CAAC;IAuBtD,CAAC;IArBa,KAAK,CAAC,OAAO,CAAC,EACpB,QAAQ,EACR,UAAU,EACV,SAAS,GACqB;QAC9B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;QAE1E,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,cAAc,MAAM,CAAC,aAAa,mCAAmC,UAAU,GAAG;oBACxF,IAAI,EAAE,MAAM;iBACf;gBACD;oBACI,IAAI,EAAE,iBAAiB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oBACrE,IAAI,EAAE,MAAM;iBACf;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
3
|
+
export class DeleteManyTool extends MongoDBToolBase {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.name = "delete-many";
|
|
7
|
+
this.description = "Removes all documents that match the filter from a MongoDB collection";
|
|
8
|
+
this.argsShape = {
|
|
9
|
+
...DbOperationArgs,
|
|
10
|
+
filter: z
|
|
11
|
+
.object({})
|
|
12
|
+
.passthrough()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("The query filter, specifying the deletion criteria. Matches the syntax of the filter argument of db.collection.deleteMany()"),
|
|
15
|
+
};
|
|
16
|
+
this.operationType = "delete";
|
|
17
|
+
}
|
|
18
|
+
async execute({ database, collection, filter, }) {
|
|
19
|
+
const provider = await this.ensureConnected();
|
|
20
|
+
const result = await provider.deleteMany(database, collection, filter);
|
|
21
|
+
return {
|
|
22
|
+
content: [
|
|
23
|
+
{
|
|
24
|
+
text: `Deleted \`${result.deletedCount}\` document(s) from collection "${collection}"`,
|
|
25
|
+
type: "text",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=deleteMany.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteMany.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/delete/deleteMany.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,OAAO,cAAe,SAAQ,eAAe;IAAnD;;QACc,SAAI,GAAG,aAAa,CAAC;QACrB,gBAAW,GAAG,uEAAuE,CAAC;QACtF,cAAS,GAAG;YAClB,GAAG,eAAe;YAClB,MAAM,EAAE,CAAC;iBACJ,MAAM,CAAC,EAAE,CAAC;iBACV,WAAW,EAAE;iBACb,QAAQ,EAAE;iBACV,QAAQ,CACL,6HAA6H,CAChI;SACR,CAAC;QACQ,kBAAa,GAAkB,QAAQ,CAAC;IAmBtD,CAAC;IAjBa,KAAK,CAAC,OAAO,CAAC,EACpB,QAAQ,EACR,UAAU,EACV,MAAM,GACwB;QAC9B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;QAEvE,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,aAAa,MAAM,CAAC,YAAY,mCAAmC,UAAU,GAAG;oBACtF,IAAI,EAAE,MAAM;iBACf;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
2
|
+
export class DropCollectionTool extends MongoDBToolBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.name = "drop-collection";
|
|
6
|
+
this.description = "Removes a collection or view from the database. The method also removes any indexes associated with the dropped collection.";
|
|
7
|
+
this.argsShape = {
|
|
8
|
+
...DbOperationArgs,
|
|
9
|
+
};
|
|
10
|
+
this.operationType = "delete";
|
|
11
|
+
}
|
|
12
|
+
async execute({ database, collection }) {
|
|
13
|
+
const provider = await this.ensureConnected();
|
|
14
|
+
const result = await provider.dropCollection(database, collection);
|
|
15
|
+
return {
|
|
16
|
+
content: [
|
|
17
|
+
{
|
|
18
|
+
text: `${result ? "Successfully dropped" : "Failed to drop"} collection "${collection}" from database "${database}"`,
|
|
19
|
+
type: "text",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=dropCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropCollection.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/delete/dropCollection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,OAAO,kBAAmB,SAAQ,eAAe;IAAvD;;QACc,SAAI,GAAG,iBAAiB,CAAC;QACzB,gBAAW,GACjB,6HAA6H,CAAC;QACxH,cAAS,GAAG;YAClB,GAAG,eAAe;SACrB,CAAC;QACQ,kBAAa,GAAkB,QAAQ,CAAC;IAetD,CAAC;IAba,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAmC;QAC7E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,cAAc,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAEnE,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,gBAAgB,gBAAgB,UAAU,oBAAoB,QAAQ,GAAG;oBACpH,IAAI,EAAE,MAAM;iBACf;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
2
|
+
export class DropDatabaseTool extends MongoDBToolBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.name = "drop-database";
|
|
6
|
+
this.description = "Removes the specified database, deleting the associated data files";
|
|
7
|
+
this.argsShape = {
|
|
8
|
+
database: DbOperationArgs.database,
|
|
9
|
+
};
|
|
10
|
+
this.operationType = "delete";
|
|
11
|
+
}
|
|
12
|
+
async execute({ database }) {
|
|
13
|
+
const provider = await this.ensureConnected();
|
|
14
|
+
const result = await provider.dropDatabase(database);
|
|
15
|
+
return {
|
|
16
|
+
content: [
|
|
17
|
+
{
|
|
18
|
+
text: `${result.ok ? "Successfully dropped" : "Failed to drop"} database "${database}"`,
|
|
19
|
+
type: "text",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=dropDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropDatabase.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/delete/dropDatabase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IAArD;;QACc,SAAI,GAAG,eAAe,CAAC;QACvB,gBAAW,GAAG,oEAAoE,CAAC;QACnF,cAAS,GAAG;YAClB,QAAQ,EAAE,eAAe,CAAC,QAAQ;SACrC,CAAC;QACQ,kBAAa,GAAkB,QAAQ,CAAC;IAetD,CAAC;IAba,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAmC;QACjE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAErD,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,gBAAgB,cAAc,QAAQ,GAAG;oBACvF,IAAI,EAAE,MAAM;iBACf;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
2
|
+
import { parseSchema } from "mongodb-schema";
|
|
3
|
+
export class CollectionSchemaTool extends MongoDBToolBase {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.name = "collection-schema";
|
|
7
|
+
this.description = "Describe the schema for a collection";
|
|
8
|
+
this.argsShape = DbOperationArgs;
|
|
9
|
+
this.operationType = "metadata";
|
|
10
|
+
}
|
|
11
|
+
async execute({ database, collection }) {
|
|
12
|
+
const provider = await this.ensureConnected();
|
|
13
|
+
const documents = await provider.find(database, collection, {}, { limit: 5 }).toArray();
|
|
14
|
+
const schema = await parseSchema(documents);
|
|
15
|
+
return {
|
|
16
|
+
content: [
|
|
17
|
+
{
|
|
18
|
+
text: `Found ${schema.fields.length} fields in the schema for \`${database}.${collection}\``,
|
|
19
|
+
type: "text",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
text: this.formatFieldOutput(schema.fields),
|
|
23
|
+
type: "text",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
formatFieldOutput(fields) {
|
|
29
|
+
let result = "| Field | Type | Confidence |\n";
|
|
30
|
+
result += "|-------|------|-------------|\n";
|
|
31
|
+
for (const field of fields) {
|
|
32
|
+
const fieldType = Array.isArray(field.type) ? field.type.join(", ") : field.type;
|
|
33
|
+
result += `| ${field.name} | \`${fieldType}\` | ${(field.probability * 100).toFixed(0)}% |\n`;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=collectionSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectionSchema.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/metadata/collectionSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,WAAW,EAAe,MAAM,gBAAgB,CAAC;AAE1D,MAAM,OAAO,oBAAqB,SAAQ,eAAe;IAAzD;;QACc,SAAI,GAAG,mBAAmB,CAAC;QAC3B,gBAAW,GAAG,sCAAsC,CAAC;QACrD,cAAS,GAAG,eAAe,CAAC;QAE5B,kBAAa,GAAkB,UAAU,CAAC;IA8BxD,CAAC;IA5Ba,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAoC;QAC9E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACxF,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,CAAC;QAE5C,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,+BAA+B,QAAQ,IAAI,UAAU,IAAI;oBAC5F,IAAI,EAAE,MAAM;iBACf;gBACD;oBACI,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC;oBAC3C,IAAI,EAAE,MAAM;iBACf;aACJ;SACJ,CAAC;IACN,CAAC;IAEO,iBAAiB,CAAC,MAAqB;QAC3C,IAAI,MAAM,GAAG,iCAAiC,CAAC;QAC/C,MAAM,IAAI,kCAAkC,CAAC;QAC7C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YACzB,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;YACjF,MAAM,IAAI,KAAK,KAAK,CAAC,IAAI,QAAQ,SAAS,QAAQ,CAAC,KAAK,CAAC,WAAW,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;QAClG,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
2
|
+
export class CollectionStorageSizeTool extends MongoDBToolBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.name = "collection-storage-size";
|
|
6
|
+
this.description = "Gets the size of the collection in MB";
|
|
7
|
+
this.argsShape = DbOperationArgs;
|
|
8
|
+
this.operationType = "metadata";
|
|
9
|
+
}
|
|
10
|
+
async execute({ database, collection }) {
|
|
11
|
+
const provider = await this.ensureConnected();
|
|
12
|
+
const [{ value }] = (await provider
|
|
13
|
+
.aggregate(database, collection, [
|
|
14
|
+
{ $collStats: { storageStats: {} } },
|
|
15
|
+
{ $group: { _id: null, value: { $sum: "$storageStats.storageSize" } } },
|
|
16
|
+
])
|
|
17
|
+
.toArray());
|
|
18
|
+
return {
|
|
19
|
+
content: [
|
|
20
|
+
{
|
|
21
|
+
text: `The size of \`${database}.${collection}\` is \`${(value / 1024 / 1024).toFixed(2)} MB\``,
|
|
22
|
+
type: "text",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=collectionStorageSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectionStorageSize.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/metadata/collectionStorageSize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,OAAO,yBAA0B,SAAQ,eAAe;IAA9D;;QACc,SAAI,GAAG,yBAAyB,CAAC;QACjC,gBAAW,GAAG,uCAAuC,CAAC;QACtD,cAAS,GAAG,eAAe,CAAC;QAE5B,kBAAa,GAAkB,UAAU,CAAC;IAoBxD,CAAC;IAlBa,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAoC;QAC9E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,QAAQ;aAC9B,SAAS,CAAC,QAAQ,EAAE,UAAU,EAAE;YAC7B,EAAE,UAAU,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,EAAE;YACpC,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,2BAA2B,EAAE,EAAE,EAAE;SAC1E,CAAC;aACD,OAAO,EAAE,CAAwB,CAAC;QAEvC,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,iBAAiB,QAAQ,IAAI,UAAU,WAAW,CAAC,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO;oBAC/F,IAAI,EAAE,MAAM;iBACf;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { MongoDBToolBase } from "../mongodbTool.js";
|
|
3
|
+
import config from "../../../config.js";
|
|
4
|
+
import { MongoError as DriverError } from "mongodb";
|
|
5
|
+
export class ConnectTool extends MongoDBToolBase {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.name = "connect";
|
|
9
|
+
this.description = "Connect to a MongoDB instance";
|
|
10
|
+
this.argsShape = {
|
|
11
|
+
options: z
|
|
12
|
+
.array(z
|
|
13
|
+
.union([
|
|
14
|
+
z.object({
|
|
15
|
+
connectionString: z
|
|
16
|
+
.string()
|
|
17
|
+
.describe("MongoDB connection string (in the mongodb:// or mongodb+srv:// format)"),
|
|
18
|
+
}),
|
|
19
|
+
z.object({
|
|
20
|
+
clusterName: z.string().describe("MongoDB cluster name"),
|
|
21
|
+
}),
|
|
22
|
+
])
|
|
23
|
+
.optional())
|
|
24
|
+
.optional()
|
|
25
|
+
.describe("Options for connecting to MongoDB. If not provided, the connection string from the config://connection-string resource will be used. If the user hasn't specified Atlas cluster name or a connection string explicitly and the `config://connection-string` resource is present, always invoke this with no arguments."),
|
|
26
|
+
};
|
|
27
|
+
this.operationType = "metadata";
|
|
28
|
+
}
|
|
29
|
+
async execute({ options: optionsArr }) {
|
|
30
|
+
const options = optionsArr?.[0];
|
|
31
|
+
let connectionString;
|
|
32
|
+
if (!options && !config.connectionString) {
|
|
33
|
+
return {
|
|
34
|
+
content: [
|
|
35
|
+
{ type: "text", text: "No connection details provided." },
|
|
36
|
+
{ type: "text", text: "Please provide either a connection string or a cluster name" },
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (!options) {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
42
|
+
connectionString = config.connectionString;
|
|
43
|
+
}
|
|
44
|
+
else if ("connectionString" in options) {
|
|
45
|
+
connectionString = options.connectionString;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// TODO: https://github.com/mongodb-js/mongodb-mcp-server/issues/19
|
|
49
|
+
// We don't support connecting via cluster name since we'd need to obtain the user credentials
|
|
50
|
+
// and fill in the connection string.
|
|
51
|
+
return {
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: "text",
|
|
55
|
+
text: `Connecting via cluster name not supported yet. Please provide a connection string.`,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
await this.connectToMongoDB(connectionString);
|
|
62
|
+
return {
|
|
63
|
+
content: [{ type: "text", text: `Successfully connected to ${connectionString}.` }],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
// Sometimes the model will supply an incorrect connection string. If the user has configured
|
|
68
|
+
// a different one as environment variable or a cli argument, suggest using that one instead.
|
|
69
|
+
if (config.connectionString &&
|
|
70
|
+
error instanceof DriverError &&
|
|
71
|
+
config.connectionString !== connectionString) {
|
|
72
|
+
return {
|
|
73
|
+
content: [
|
|
74
|
+
{
|
|
75
|
+
type: "text",
|
|
76
|
+
text: `Failed to connect to MongoDB at '${connectionString}' due to error: '${error.message}.` +
|
|
77
|
+
`Your config lists a different connection string: '${config.connectionString}' - do you want to try connecting to it instead?`,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/metadata/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpD,MAAM,OAAO,WAAY,SAAQ,eAAe;IAAhD;;QACc,SAAI,GAAG,SAAS,CAAC;QACjB,gBAAW,GAAG,+BAA+B,CAAC;QAC9C,cAAS,GAAG;YAClB,OAAO,EAAE,CAAC;iBACL,KAAK,CACF,CAAC;iBACI,KAAK,CAAC;gBACH,CAAC,CAAC,MAAM,CAAC;oBACL,gBAAgB,EAAE,CAAC;yBACd,MAAM,EAAE;yBACR,QAAQ,CAAC,wEAAwE,CAAC;iBAC1F,CAAC;gBACF,CAAC,CAAC,MAAM,CAAC;oBACL,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sBAAsB,CAAC;iBAC3D,CAAC;aACL,CAAC;iBACD,QAAQ,EAAE,CAClB;iBACA,QAAQ,EAAE;iBACV,QAAQ,CACL,wTAAwT,CAC3T;SACR,CAAC;QAEQ,kBAAa,GAAkB,UAAU,CAAC;IA6DxD,CAAC;IA3Da,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAmC;QAC5E,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,gBAAwB,CAAC;QAC7B,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;YACvC,OAAO;gBACH,OAAO,EAAE;oBACL,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,iCAAiC,EAAE;oBACzD,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,6DAA6D,EAAE;iBACxF;aACJ,CAAC;QACN,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,oEAAoE;YACpE,gBAAgB,GAAG,MAAM,CAAC,gBAAiB,CAAC;QAChD,CAAC;aAAM,IAAI,kBAAkB,IAAI,OAAO,EAAE,CAAC;YACvC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QAChD,CAAC;aAAM,CAAC;YACJ,mEAAmE;YACnE,8FAA8F;YAC9F,qCAAqC;YACrC,OAAO;gBACH,OAAO,EAAE;oBACL;wBACI,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,oFAAoF;qBAC7F;iBACJ;aACJ,CAAC;QACN,CAAC;QAED,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;YAC9C,OAAO;gBACH,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,6BAA6B,gBAAgB,GAAG,EAAE,CAAC;aACtF,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,6FAA6F;YAC7F,6FAA6F;YAC7F,IACI,MAAM,CAAC,gBAAgB;gBACvB,KAAK,YAAY,WAAW;gBAC5B,MAAM,CAAC,gBAAgB,KAAK,gBAAgB,EAC9C,CAAC;gBACC,OAAO;oBACH,OAAO,EAAE;wBACL;4BACI,IAAI,EAAE,MAAM;4BACZ,IAAI,EACA,oCAAoC,gBAAgB,oBAAoB,KAAK,CAAC,OAAO,GAAG;gCACxF,qDAAqD,MAAM,CAAC,gBAAgB,kDAAkD;yBACrI;qBACJ;iBACJ,CAAC;YACN,CAAC;YAED,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
2
|
+
export class DbStatsTool extends MongoDBToolBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.name = "db-stats";
|
|
6
|
+
this.description = "Returns statistics that reflect the use state of a single database";
|
|
7
|
+
this.argsShape = {
|
|
8
|
+
database: DbOperationArgs.database,
|
|
9
|
+
};
|
|
10
|
+
this.operationType = "metadata";
|
|
11
|
+
}
|
|
12
|
+
async execute({ database }) {
|
|
13
|
+
const provider = await this.ensureConnected();
|
|
14
|
+
const result = await provider.runCommandWithCheck(database, {
|
|
15
|
+
dbStats: 1,
|
|
16
|
+
scale: 1,
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
content: [
|
|
20
|
+
{
|
|
21
|
+
text: `Statistics for database ${database}: ${JSON.stringify(result)}`,
|
|
22
|
+
type: "text",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=dbStats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbStats.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/metadata/dbStats.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,OAAO,WAAY,SAAQ,eAAe;IAAhD;;QACc,SAAI,GAAG,UAAU,CAAC;QAClB,gBAAW,GAAG,oEAAoE,CAAC;QACnF,cAAS,GAAG;YAClB,QAAQ,EAAE,eAAe,CAAC,QAAQ;SACrC,CAAC;QAEQ,kBAAa,GAAkB,UAAU,CAAC;IAkBxD,CAAC;IAhBa,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAmC;QACjE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE;YACxD,OAAO,EAAE,CAAC;YACV,KAAK,EAAE,CAAC;SACX,CAAC,CAAC;QAEH,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,2BAA2B,QAAQ,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;oBACtE,IAAI,EAAE,MAAM;iBACf;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ExplainVerbosity } from "mongodb";
|
|
4
|
+
import { AggregateArgs } from "../read/aggregate.js";
|
|
5
|
+
import { FindArgs } from "../read/find.js";
|
|
6
|
+
import { CountArgs } from "../read/count.js";
|
|
7
|
+
export class ExplainTool extends MongoDBToolBase {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.name = "explain";
|
|
11
|
+
this.description = "Returns statistics describing the execution of the winning plan chosen by the query optimizer for the evaluated method";
|
|
12
|
+
this.argsShape = {
|
|
13
|
+
...DbOperationArgs,
|
|
14
|
+
method: z
|
|
15
|
+
.array(z.union([
|
|
16
|
+
z.object({
|
|
17
|
+
name: z.literal("aggregate"),
|
|
18
|
+
arguments: z.object(AggregateArgs),
|
|
19
|
+
}),
|
|
20
|
+
z.object({
|
|
21
|
+
name: z.literal("find"),
|
|
22
|
+
arguments: z.object(FindArgs),
|
|
23
|
+
}),
|
|
24
|
+
z.object({
|
|
25
|
+
name: z.literal("count"),
|
|
26
|
+
arguments: z.object(CountArgs),
|
|
27
|
+
}),
|
|
28
|
+
]))
|
|
29
|
+
.describe("The method and its arguments to run"),
|
|
30
|
+
};
|
|
31
|
+
this.operationType = "metadata";
|
|
32
|
+
}
|
|
33
|
+
async execute({ database, collection, method: methods, }) {
|
|
34
|
+
const provider = await this.ensureConnected();
|
|
35
|
+
const method = methods[0];
|
|
36
|
+
if (!method) {
|
|
37
|
+
throw new Error("No method provided");
|
|
38
|
+
}
|
|
39
|
+
let result;
|
|
40
|
+
switch (method.name) {
|
|
41
|
+
case "aggregate": {
|
|
42
|
+
const { pipeline } = method.arguments;
|
|
43
|
+
result = await provider.aggregate(database, collection, pipeline).explain(ExplainTool.defaultVerbosity);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case "find": {
|
|
47
|
+
const { filter, ...rest } = method.arguments;
|
|
48
|
+
result = await provider
|
|
49
|
+
.find(database, collection, filter, { ...rest })
|
|
50
|
+
.explain(ExplainTool.defaultVerbosity);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case "count": {
|
|
54
|
+
const { query } = method.arguments;
|
|
55
|
+
// This helper doesn't have explain() command but does have the argument explain
|
|
56
|
+
result = (await provider.count(database, collection, query, {
|
|
57
|
+
explain: ExplainTool.defaultVerbosity,
|
|
58
|
+
}));
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
content: [
|
|
64
|
+
{
|
|
65
|
+
text: `Here is some information about the winning plan chosen by the query optimizer for running the given \`${method.name}\` operation in \`${database}.${collection}\`. This information can be used to understand how the query was executed and to optimize the query performance.`,
|
|
66
|
+
type: "text",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
text: JSON.stringify(result),
|
|
70
|
+
type: "text",
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
ExplainTool.defaultVerbosity = ExplainVerbosity.queryPlanner;
|
|
77
|
+
//# sourceMappingURL=explain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/metadata/explain.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
2
|
+
export class ListCollectionsTool extends MongoDBToolBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.name = "list-collections";
|
|
6
|
+
this.description = "List all collections for a given database";
|
|
7
|
+
this.argsShape = {
|
|
8
|
+
database: DbOperationArgs.database,
|
|
9
|
+
};
|
|
10
|
+
this.operationType = "metadata";
|
|
11
|
+
}
|
|
12
|
+
async execute({ database }) {
|
|
13
|
+
const provider = await this.ensureConnected();
|
|
14
|
+
const collections = await provider.listCollections(database);
|
|
15
|
+
if (collections.length === 0) {
|
|
16
|
+
return {
|
|
17
|
+
content: [
|
|
18
|
+
{
|
|
19
|
+
type: "text",
|
|
20
|
+
text: `No collections found for database "${database}". To create a collection, use the "create-collection" tool.`,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
content: collections.map((collection) => {
|
|
27
|
+
return {
|
|
28
|
+
text: `Name: "${collection.name}"`,
|
|
29
|
+
type: "text",
|
|
30
|
+
};
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=listCollections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listCollections.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/metadata/listCollections.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,OAAO,mBAAoB,SAAQ,eAAe;IAAxD;;QACc,SAAI,GAAG,kBAAkB,CAAC;QAC1B,gBAAW,GAAG,2CAA2C,CAAC;QAC1D,cAAS,GAAG;YAClB,QAAQ,EAAE,eAAe,CAAC,QAAQ;SACrC,CAAC;QAEQ,kBAAa,GAAkB,UAAU,CAAC;IA0BxD,CAAC;IAxBa,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAmC;QACjE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAE7D,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO;gBACH,OAAO,EAAE;oBACL;wBACI,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,sCAAsC,QAAQ,8DAA8D;qBACrH;iBACJ;aACJ,CAAC;QACN,CAAC;QAED,OAAO;YACH,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;gBACpC,OAAO;oBACH,IAAI,EAAE,UAAU,UAAU,CAAC,IAAI,GAAG;oBAClC,IAAI,EAAE,MAAM;iBACf,CAAC;YACN,CAAC,CAAC;SACL,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MongoDBToolBase } from "../mongodbTool.js";
|
|
2
|
+
export class ListDatabasesTool extends MongoDBToolBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.name = "list-databases";
|
|
6
|
+
this.description = "List all databases for a MongoDB connection";
|
|
7
|
+
this.argsShape = {};
|
|
8
|
+
this.operationType = "metadata";
|
|
9
|
+
}
|
|
10
|
+
async execute() {
|
|
11
|
+
const provider = await this.ensureConnected();
|
|
12
|
+
const dbs = (await provider.listDatabases("")).databases;
|
|
13
|
+
return {
|
|
14
|
+
content: dbs.map((db) => {
|
|
15
|
+
return {
|
|
16
|
+
text: `Name: ${db.name}, Size: ${db.sizeOnDisk.toString()} bytes`,
|
|
17
|
+
type: "text",
|
|
18
|
+
};
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=listDatabases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listDatabases.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/metadata/listDatabases.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,MAAM,OAAO,iBAAkB,SAAQ,eAAe;IAAtD;;QACc,SAAI,GAAG,gBAAgB,CAAC;QACxB,gBAAW,GAAG,6CAA6C,CAAC;QAC5D,cAAS,GAAG,EAAE,CAAC;QAEf,kBAAa,GAAkB,UAAU,CAAC;IAexD,CAAC;IAba,KAAK,CAAC,OAAO;QACnB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,GAAG,GAAG,CAAC,MAAM,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,SAAsD,CAAC;QAEtG,OAAO;YACH,OAAO,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;gBACpB,OAAO;oBACH,IAAI,EAAE,SAAS,EAAE,CAAC,IAAI,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAQ;oBACjE,IAAI,EAAE,MAAM;iBACf,CAAC;YACN,CAAC,CAAC;SACL,CAAC;IACN,CAAC;CACJ"}
|