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,58 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ToolBase } from "../tool.js";
|
|
3
|
+
import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver";
|
|
4
|
+
import { ErrorCodes, MongoDBError } from "../../errors.js";
|
|
5
|
+
import config from "../../config.js";
|
|
6
|
+
export const DbOperationArgs = {
|
|
7
|
+
database: z.string().describe("Database name"),
|
|
8
|
+
collection: z.string().describe("Collection name"),
|
|
9
|
+
};
|
|
10
|
+
export class MongoDBToolBase extends ToolBase {
|
|
11
|
+
constructor(session) {
|
|
12
|
+
super(session);
|
|
13
|
+
this.category = "mongodb";
|
|
14
|
+
}
|
|
15
|
+
async ensureConnected() {
|
|
16
|
+
if (!this.session.serviceProvider && config.connectionString) {
|
|
17
|
+
await this.connectToMongoDB(config.connectionString);
|
|
18
|
+
}
|
|
19
|
+
if (!this.session.serviceProvider) {
|
|
20
|
+
throw new MongoDBError(ErrorCodes.NotConnectedToMongoDB, "Not connected to MongoDB");
|
|
21
|
+
}
|
|
22
|
+
return this.session.serviceProvider;
|
|
23
|
+
}
|
|
24
|
+
handleError(error) {
|
|
25
|
+
if (error instanceof MongoDBError && error.code === ErrorCodes.NotConnectedToMongoDB) {
|
|
26
|
+
return {
|
|
27
|
+
content: [
|
|
28
|
+
{
|
|
29
|
+
type: "text",
|
|
30
|
+
text: "You need to connect to a MongoDB instance before you can access its data.",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: "text",
|
|
34
|
+
text: "Please use the 'connect' tool to connect to a MongoDB instance.",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
isError: true,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return super.handleError(error);
|
|
41
|
+
}
|
|
42
|
+
async connectToMongoDB(connectionString) {
|
|
43
|
+
const provider = await NodeDriverServiceProvider.connect(connectionString, {
|
|
44
|
+
productDocsLink: "https://docs.mongodb.com/todo-mcp",
|
|
45
|
+
productName: "MongoDB MCP",
|
|
46
|
+
readConcern: {
|
|
47
|
+
level: config.connectOptions.readConcern,
|
|
48
|
+
},
|
|
49
|
+
readPreference: config.connectOptions.readPreference,
|
|
50
|
+
writeConcern: {
|
|
51
|
+
w: config.connectOptions.writeConcern,
|
|
52
|
+
},
|
|
53
|
+
timeoutMS: config.connectOptions.timeoutMS,
|
|
54
|
+
});
|
|
55
|
+
this.session.serviceProvider = provider;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=mongodbTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongodbTool.js","sourceRoot":"","sources":["../../../src/tools/mongodb/mongodbTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAgB,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAElF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,MAAM,CAAC,MAAM,eAAe,GAAG;IAC3B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;IAC9C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;CACrD,CAAC;AAEF,MAAM,OAAg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CAAC,EAAE,MAAM,CAAC,cAAc,CAAC,YAAY;aACxC;YACD,SAAS,EAAE,MAAM,CAAC,cAAc,CAAC,SAAS;SAC7C,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,CAAC,eAAe,GAAG,QAAQ,CAAC;IAC5C,CAAC;CACJ"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
3
|
+
export const AggregateArgs = {
|
|
4
|
+
pipeline: z.array(z.object({}).passthrough()).describe("An array of aggregation stages to execute"),
|
|
5
|
+
limit: z.number().optional().default(10).describe("The maximum number of documents to return"),
|
|
6
|
+
};
|
|
7
|
+
export class AggregateTool extends MongoDBToolBase {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.name = "aggregate";
|
|
11
|
+
this.description = "Run an aggregation against a MongoDB collection";
|
|
12
|
+
this.argsShape = {
|
|
13
|
+
...DbOperationArgs,
|
|
14
|
+
...AggregateArgs,
|
|
15
|
+
};
|
|
16
|
+
this.operationType = "read";
|
|
17
|
+
}
|
|
18
|
+
async execute({ database, collection, pipeline, }) {
|
|
19
|
+
const provider = await this.ensureConnected();
|
|
20
|
+
const documents = await provider.aggregate(database, collection, pipeline).toArray();
|
|
21
|
+
const content = [
|
|
22
|
+
{
|
|
23
|
+
text: `Found ${documents.length} documents in the collection \`${collection}\`:`,
|
|
24
|
+
type: "text",
|
|
25
|
+
},
|
|
26
|
+
...documents.map((doc) => {
|
|
27
|
+
return {
|
|
28
|
+
text: JSON.stringify(doc),
|
|
29
|
+
type: "text",
|
|
30
|
+
};
|
|
31
|
+
}),
|
|
32
|
+
];
|
|
33
|
+
return {
|
|
34
|
+
content,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=aggregate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agg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,MAAM;iBACmB,CAAC;YACxC,CAAC,CAAC;SACL,CAAC;QAEF,OAAO;YACH,OAAO;SACV,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
2
|
+
export class CollectionIndexesTool extends MongoDBToolBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.name = "collection-indexes";
|
|
6
|
+
this.description = "Describe the indexes for a collection";
|
|
7
|
+
this.argsShape = DbOperationArgs;
|
|
8
|
+
this.operationType = "read";
|
|
9
|
+
}
|
|
10
|
+
async execute({ database, collection }) {
|
|
11
|
+
const provider = await this.ensureConnected();
|
|
12
|
+
const indexes = await provider.getIndexes(database, collection);
|
|
13
|
+
return {
|
|
14
|
+
content: indexes.map((indexDefinition) => {
|
|
15
|
+
return {
|
|
16
|
+
text: `Field: ${indexDefinition.name}: ${JSON.stringify(indexDefinition.key)}`,
|
|
17
|
+
type: "text",
|
|
18
|
+
};
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=collectionIndexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectionIndexes.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/read/collectionIndexes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IAA1D;;QACc,SAAI,GAAG,oBAAoB,CAAC;QAC5B,gBAAW,GAAG,uCAAuC,CAAC;QACtD,cAAS,GAAG,eAAe,CAAC;QAC5B,kBAAa,GAAkB,MAAM,CAAC;IAepD,CAAC;IAba,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAoC;QAC9E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAEhE,OAAO;YACH,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,eAAe,EAAE,EAAE;gBACrC,OAAO;oBACH,IAAI,EAAE,UAAU,eAAe,CAAC,IAAI,KAAK,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE;oBAC9E,IAAI,EAAE,MAAM;iBACf,CAAC;YACN,CAAC,CAAC;SACL,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export const CountArgs = {
|
|
4
|
+
query: z
|
|
5
|
+
.object({})
|
|
6
|
+
.passthrough()
|
|
7
|
+
.optional()
|
|
8
|
+
.describe("The query filter to count documents. Matches the syntax of the filter argument of db.collection.count()"),
|
|
9
|
+
};
|
|
10
|
+
export class CountTool extends MongoDBToolBase {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.name = "count";
|
|
14
|
+
this.description = "Gets the number of documents in a MongoDB collection";
|
|
15
|
+
this.argsShape = {
|
|
16
|
+
...DbOperationArgs,
|
|
17
|
+
...CountArgs,
|
|
18
|
+
};
|
|
19
|
+
this.operationType = "read";
|
|
20
|
+
}
|
|
21
|
+
async execute({ database, collection, query }) {
|
|
22
|
+
const provider = await this.ensureConnected();
|
|
23
|
+
const count = await provider.count(database, collection, query);
|
|
24
|
+
return {
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
text: `Found ${count} documents in the collection "${collection}"`,
|
|
28
|
+
type: "text",
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=count.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"count.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/read/count.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,SAAS,GAAG;IACrB,KAAK,EAAE,CAAC;SACH,MAAM,CAAC,EAAE,CAAC;SACV,WAAW,EAAE;SACb,QAAQ,EAAE;SACV,QAAQ,CACL,yGAAyG,CAC5G;CACR,CAAC;AAEF,MAAM,OAAO,SAAU,SAAQ,eAAe;IAA9C;;QACc,SAAI,GAAG,OAAO,CAAC;QACf,gBAAW,GAAG,sDAAsD,CAAC;QACrE,cAAS,GAAG;YAClB,GAAG,eAAe;YAClB,GAAG,SAAS;SACf,CAAC;QAEQ,kBAAa,GAAkB,MAAM,CAAC;IAepD,CAAC;IAba,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAmC;QACpF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;QAEhE,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,SAAS,KAAK,iCAAiC,UAAU,GAAG;oBAClE,IAAI,EAAE,MAAM;iBACf;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
3
|
+
export const FindArgs = {
|
|
4
|
+
filter: z
|
|
5
|
+
.object({})
|
|
6
|
+
.passthrough()
|
|
7
|
+
.optional()
|
|
8
|
+
.describe("The query filter, matching the syntax of the query argument of db.collection.find()"),
|
|
9
|
+
projection: z
|
|
10
|
+
.object({})
|
|
11
|
+
.passthrough()
|
|
12
|
+
.optional()
|
|
13
|
+
.describe("The projection, matching the syntax of the projection argument of db.collection.find()"),
|
|
14
|
+
limit: z.number().optional().default(10).describe("The maximum number of documents to return"),
|
|
15
|
+
sort: z
|
|
16
|
+
.record(z.string(), z.custom())
|
|
17
|
+
.optional()
|
|
18
|
+
.describe("A document, describing the sort order, matching the syntax of the sort argument of cursor.sort()"),
|
|
19
|
+
};
|
|
20
|
+
export class FindTool extends MongoDBToolBase {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(...arguments);
|
|
23
|
+
this.name = "find";
|
|
24
|
+
this.description = "Run a find query against a MongoDB collection";
|
|
25
|
+
this.argsShape = {
|
|
26
|
+
...DbOperationArgs,
|
|
27
|
+
...FindArgs,
|
|
28
|
+
};
|
|
29
|
+
this.operationType = "read";
|
|
30
|
+
}
|
|
31
|
+
async execute({ database, collection, filter, projection, limit, sort, }) {
|
|
32
|
+
const provider = await this.ensureConnected();
|
|
33
|
+
const documents = await provider.find(database, collection, filter, { projection, limit, sort }).toArray();
|
|
34
|
+
const content = [
|
|
35
|
+
{
|
|
36
|
+
text: `Found ${documents.length} documents in the collection \`${collection}\`:`,
|
|
37
|
+
type: "text",
|
|
38
|
+
},
|
|
39
|
+
...documents.map((doc) => {
|
|
40
|
+
return {
|
|
41
|
+
text: JSON.stringify(doc),
|
|
42
|
+
type: "text",
|
|
43
|
+
};
|
|
44
|
+
}),
|
|
45
|
+
];
|
|
46
|
+
return {
|
|
47
|
+
content,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=find.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/read/find.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,E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AAC,MAAM,kCAAkC,UAAU,KAAK;gBAChF,IAAI,EAAE,MAAM;aACf;YACD,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;gBACrB,OAAO;oBACH,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;oBACzB,IAAI,EAAE,MAAM;iBACmB,CAAC;YACxC,CAAC,CAAC;SACL,CAAC;QAEF,OAAO;YACH,OAAO;SACV,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ConnectTool } from "./metadata/connect.js";
|
|
2
|
+
import { ListCollectionsTool } from "./metadata/listCollections.js";
|
|
3
|
+
import { CollectionIndexesTool } from "./read/collectionIndexes.js";
|
|
4
|
+
import { ListDatabasesTool } from "./metadata/listDatabases.js";
|
|
5
|
+
import { CreateIndexTool } from "./create/createIndex.js";
|
|
6
|
+
import { CollectionSchemaTool } from "./metadata/collectionSchema.js";
|
|
7
|
+
import { FindTool } from "./read/find.js";
|
|
8
|
+
import { InsertManyTool } from "./create/insertMany.js";
|
|
9
|
+
import { DeleteManyTool } from "./delete/deleteMany.js";
|
|
10
|
+
import { CollectionStorageSizeTool } from "./metadata/collectionStorageSize.js";
|
|
11
|
+
import { CountTool } from "./read/count.js";
|
|
12
|
+
import { DbStatsTool } from "./metadata/dbStats.js";
|
|
13
|
+
import { AggregateTool } from "./read/aggregate.js";
|
|
14
|
+
import { UpdateManyTool } from "./update/updateMany.js";
|
|
15
|
+
import { RenameCollectionTool } from "./update/renameCollection.js";
|
|
16
|
+
import { DropDatabaseTool } from "./delete/dropDatabase.js";
|
|
17
|
+
import { DropCollectionTool } from "./delete/dropCollection.js";
|
|
18
|
+
import { ExplainTool } from "./metadata/explain.js";
|
|
19
|
+
import { CreateCollectionTool } from "./create/createCollection.js";
|
|
20
|
+
export const MongoDbTools = [
|
|
21
|
+
ConnectTool,
|
|
22
|
+
ListCollectionsTool,
|
|
23
|
+
ListDatabasesTool,
|
|
24
|
+
CollectionIndexesTool,
|
|
25
|
+
CreateIndexTool,
|
|
26
|
+
CollectionSchemaTool,
|
|
27
|
+
FindTool,
|
|
28
|
+
InsertManyTool,
|
|
29
|
+
DeleteManyTool,
|
|
30
|
+
CollectionStorageSizeTool,
|
|
31
|
+
CountTool,
|
|
32
|
+
DbStatsTool,
|
|
33
|
+
AggregateTool,
|
|
34
|
+
UpdateManyTool,
|
|
35
|
+
RenameCollectionTool,
|
|
36
|
+
DropDatabaseTool,
|
|
37
|
+
DropCollectionTool,
|
|
38
|
+
ExplainTool,
|
|
39
|
+
CreateCollectionTool,
|
|
40
|
+
];
|
|
41
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/tools/mongodb/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB,WAAW;IACX,mBAAmB;IACnB,iBAAiB;IACjB,qBAAqB;IACrB,eAAe;IACf,oBAAoB;IACpB,QAAQ;IACR,cAAc;IACd,cAAc;IACd,yBAAyB;IACzB,SAAS;IACT,WAAW;IACX,aAAa;IACb,cAAc;IACd,oBAAoB;IACpB,gBAAgB;IAChB,kBAAkB;IAClB,WAAW;IACX,oBAAoB;CACvB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { MongoDBToolBase } from "../mongodbTool.js";
|
|
3
|
+
export class RenameCollectionTool extends MongoDBToolBase {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.name = "rename-collection";
|
|
7
|
+
this.description = "Renames a collection in a MongoDB database";
|
|
8
|
+
this.argsShape = {
|
|
9
|
+
collection: z.string().describe("Collection name"),
|
|
10
|
+
database: z.string().describe("Database name"),
|
|
11
|
+
newName: z.string().describe("The new name for the collection"),
|
|
12
|
+
dropTarget: z.boolean().optional().default(false).describe("If true, drops the target collection if it exists"),
|
|
13
|
+
};
|
|
14
|
+
this.operationType = "update";
|
|
15
|
+
}
|
|
16
|
+
async execute({ database, collection, newName, dropTarget, }) {
|
|
17
|
+
const provider = await this.ensureConnected();
|
|
18
|
+
const result = await provider.renameCollection(database, collection, newName, {
|
|
19
|
+
dropTarget,
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
content: [
|
|
23
|
+
{
|
|
24
|
+
text: `Collection \`${collection}\` renamed to \`${result.collectionName}\` in database \`${database}\`.`,
|
|
25
|
+
type: "text",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=renameCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameCollection.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/update/renameCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,MAAM,OAAO,oBAAqB,SAAQ,eAAe;IAAzD;;QACc,SAAI,GAAG,mBAAmB,CAAC;QAC3B,gBAAW,GAAG,4CAA4C,CAAC;QAC3D,cAAS,GAAG;YAClB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YAClD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;YAC9C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;YAC/D,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,mDAAmD,CAAC;SAClH,CAAC;QACQ,kBAAa,GAAkB,QAAQ,CAAC;IAsBtD,CAAC;IApBa,KAAK,CAAC,OAAO,CAAC,EACpB,QAAQ,EACR,UAAU,EACV,OAAO,EACP,UAAU,GACoB;QAC9B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE;YAC1E,UAAU;SACb,CAAC,CAAC;QAEH,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,gBAAgB,UAAU,mBAAmB,MAAM,CAAC,cAAc,oBAAoB,QAAQ,KAAK;oBACzG,IAAI,EAAE,MAAM;iBACf;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { MongoDBToolBase } from "../mongodbTool.js";
|
|
3
|
+
export class UpdateManyTool extends MongoDBToolBase {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.name = "update-many";
|
|
7
|
+
this.description = "Updates all documents that match the specified filter for a collection";
|
|
8
|
+
this.argsShape = {
|
|
9
|
+
collection: z.string().describe("Collection name"),
|
|
10
|
+
database: z.string().describe("Database name"),
|
|
11
|
+
filter: z
|
|
12
|
+
.object({})
|
|
13
|
+
.passthrough()
|
|
14
|
+
.optional()
|
|
15
|
+
.describe("The selection criteria for the update, matching the syntax of the filter argument of db.collection.updateOne()"),
|
|
16
|
+
update: z
|
|
17
|
+
.object({})
|
|
18
|
+
.passthrough()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe("An update document describing the modifications to apply using update operator expressions"),
|
|
21
|
+
upsert: z
|
|
22
|
+
.boolean()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("Controls whether to insert a new document if no documents match the filter"),
|
|
25
|
+
};
|
|
26
|
+
this.operationType = "update";
|
|
27
|
+
}
|
|
28
|
+
async execute({ database, collection, filter, update, upsert, }) {
|
|
29
|
+
const provider = await this.ensureConnected();
|
|
30
|
+
const result = await provider.updateMany(database, collection, filter, update, {
|
|
31
|
+
upsert,
|
|
32
|
+
});
|
|
33
|
+
let message = "";
|
|
34
|
+
if (result.matchedCount === 0) {
|
|
35
|
+
message = `No documents matched the filter.`;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
message = `Matched ${result.matchedCount} document(s).`;
|
|
39
|
+
if (result.modifiedCount > 0) {
|
|
40
|
+
message += ` Modified ${result.modifiedCount} document(s).`;
|
|
41
|
+
}
|
|
42
|
+
if (result.upsertedCount > 0) {
|
|
43
|
+
message += ` Upserted ${result.upsertedCount} document(s) (with id: ${result.upsertedId?.toString()}).`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
text: message,
|
|
50
|
+
type: "text",
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=updateMany.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateMany.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/update/updateMany.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,MAAM,OAAO,cAAe,SAAQ,eAAe;IAAnD;;QACc,SAAI,GAAG,aAAa,CAAC;QACrB,gBAAW,GAAG,wEAAwE,CAAC;QACvF,cAAS,GAAG;YAClB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YAClD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;YAC9C,MAAM,EAAE,CAAC;iBACJ,MAAM,CAAC,EAAE,CAAC;iBACV,WAAW,EAAE;iBACb,QAAQ,EAAE;iBACV,QAAQ,CACL,gHAAgH,CACnH;YACL,MAAM,EAAE,CAAC;iBACJ,MAAM,CAAC,EAAE,CAAC;iBACV,WAAW,EAAE;iBACb,QAAQ,EAAE;iBACV,QAAQ,CAAC,4FAA4F,CAAC;YAC3G,MAAM,EAAE,CAAC;iBACJ,OAAO,EAAE;iBACT,QAAQ,EAAE;iBACV,QAAQ,CAAC,4EAA4E,CAAC;SAC9F,CAAC;QACQ,kBAAa,GAAkB,QAAQ,CAAC;IAoCtD,CAAC;IAlCa,KAAK,CAAC,OAAO,CAAC,EACpB,QAAQ,EACR,UAAU,EACV,MAAM,EACN,MAAM,EACN,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,EAAE,MAAM,EAAE;YAC3E,MAAM;SACT,CAAC,CAAC;QAEH,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,IAAI,MAAM,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;YAC5B,OAAO,GAAG,kCAAkC,CAAC;QACjD,CAAC;aAAM,CAAC;YACJ,OAAO,GAAG,WAAW,MAAM,CAAC,YAAY,eAAe,CAAC;YACxD,IAAI,MAAM,CAAC,aAAa,GAAG,CAAC,EAAE,CAAC;gBAC3B,OAAO,IAAI,aAAa,MAAM,CAAC,aAAa,eAAe,CAAC;YAChE,CAAC;YACD,IAAI,MAAM,CAAC,aAAa,GAAG,CAAC,EAAE,CAAC;gBAC3B,OAAO,IAAI,aAAa,MAAM,CAAC,aAAa,0BAA0B,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC;YAC5G,CAAC;QACL,CAAC;QAED,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,OAAO;oBACb,IAAI,EAAE,MAAM;iBACf;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import logger from "../logger.js";
|
|
2
|
+
import { mongoLogId } from "mongodb-log-writer";
|
|
3
|
+
import config from "../config.js";
|
|
4
|
+
export class ToolBase {
|
|
5
|
+
constructor(session) {
|
|
6
|
+
this.session = session;
|
|
7
|
+
}
|
|
8
|
+
register(server) {
|
|
9
|
+
if (!this.verifyAllowed()) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const callback = async (...args) => {
|
|
13
|
+
try {
|
|
14
|
+
// TODO: add telemetry here
|
|
15
|
+
logger.debug(mongoLogId(1000006), "tool", `Executing ${this.name} with args: ${JSON.stringify(args)}`);
|
|
16
|
+
return await this.execute(...args);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
logger.error(mongoLogId(1000000), "tool", `Error executing ${this.name}: ${error}`);
|
|
20
|
+
return await this.handleError(error);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
server.tool(this.name, this.description, this.argsShape, callback);
|
|
24
|
+
}
|
|
25
|
+
// Checks if a tool is allowed to run based on the config
|
|
26
|
+
verifyAllowed() {
|
|
27
|
+
let errorClarification;
|
|
28
|
+
if (config.disabledTools.includes(this.category)) {
|
|
29
|
+
errorClarification = `its category, \`${this.category}\`,`;
|
|
30
|
+
}
|
|
31
|
+
else if (config.disabledTools.includes(this.operationType)) {
|
|
32
|
+
errorClarification = `its operation type, \`${this.operationType}\`,`;
|
|
33
|
+
}
|
|
34
|
+
else if (config.disabledTools.includes(this.name)) {
|
|
35
|
+
errorClarification = `it`;
|
|
36
|
+
}
|
|
37
|
+
if (errorClarification) {
|
|
38
|
+
logger.debug(mongoLogId(1000010), "tool", `Prevented registration of ${this.name} because ${errorClarification} is disabled in the config`);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
// This method is intended to be overridden by subclasses to handle errors
|
|
44
|
+
handleError(error) {
|
|
45
|
+
return {
|
|
46
|
+
content: [
|
|
47
|
+
{
|
|
48
|
+
type: "text",
|
|
49
|
+
text: `Error running ${this.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
isError: true,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=tool.js.map
|
|
@@ -0,0 +1 @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QAAQ,CAAC,EAAE,CAAC;YAC/C,kBAAkB,GAAG,mBAAmB,IAAI,CAAC,QAAQ,KAAK,CAAC;QAC/D,CAAC;aAAM,IAAI,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAC3D,kBAAkB,GAAG,yBAAyB,IAAI,CAAC,aAAa,KAAK,CAAC;QAC1E,CAAC;aAAM,IAAI,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAClD,kBAAkB,GAAG,IAAI,CAAC;QAC9B,CAAC;QAED,IAAI,kBAAkB,EAAE,CAAC;YACrB,MAAM,CAAC,KAAK,CACR,UAAU,CAAC,OAAS,CAAC,EACrB,MAAM,EACN,6BAA6B,IAAI,CAAC,IAAI,YAAY,kBAAkB,4BAA4B,CACnG,CAAC;YAEF,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,0EAA0E;IAChE,WAAW,CAAC,KAAc;QAChC,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,iBAAiB,IAAI,CAAC,IAAI,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;iBAChG;aACJ;YACD,OAAO,EAAE,IAAI;SAChB,CAAC;IACN,CAAC;CACJ"}
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
2
|
+
import js from "@eslint/js";
|
|
3
|
+
import globals from "globals";
|
|
4
|
+
import tseslint from "typescript-eslint";
|
|
5
|
+
import eslintConfigPrettier from "eslint-config-prettier/flat";
|
|
6
|
+
|
|
7
|
+
const files = ["src/**/*.ts", "scripts/**/*.ts", "tests/**/*.test.ts", "eslint.config.js", "jest.config.js"];
|
|
8
|
+
|
|
9
|
+
export default defineConfig([
|
|
10
|
+
{ files, plugins: { js }, extends: ["js/recommended"] },
|
|
11
|
+
{ files, languageOptions: { globals: globals.node } },
|
|
12
|
+
tseslint.configs.recommendedTypeChecked,
|
|
13
|
+
{
|
|
14
|
+
languageOptions: {
|
|
15
|
+
parserOptions: {
|
|
16
|
+
projectService: true,
|
|
17
|
+
tsconfigRootDir: import.meta.dirname,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
files,
|
|
23
|
+
rules: {
|
|
24
|
+
"@typescript-eslint/switch-exhaustiveness-check": "error",
|
|
25
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
// Ignore features specific to TypeScript resolved rules
|
|
29
|
+
tseslint.config({
|
|
30
|
+
// TODO: Configure tests and scripts to work with this.
|
|
31
|
+
ignores: ["eslint.config.js", "jest.config.js", "tests/**/*.ts", "scripts/**/*.ts"],
|
|
32
|
+
}),
|
|
33
|
+
globalIgnores(["node_modules", "dist", "src/common/atlas/openapi.d.ts", "coverage"]),
|
|
34
|
+
eslintConfigPrettier,
|
|
35
|
+
]);
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} **/
|
|
2
|
+
export default {
|
|
3
|
+
preset: "ts-jest/presets/default-esm",
|
|
4
|
+
testEnvironment: "node",
|
|
5
|
+
extensionsToTreatAsEsm: [".ts"],
|
|
6
|
+
testTimeout: 3600000, // 3600 seconds
|
|
7
|
+
moduleNameMapper: {
|
|
8
|
+
"^(\\.{1,2}/.*)\\.js$": "$1", // Map .js to real paths for ESM
|
|
9
|
+
},
|
|
10
|
+
transform: {
|
|
11
|
+
"^.+\\.tsx?$": [
|
|
12
|
+
"ts-jest",
|
|
13
|
+
{
|
|
14
|
+
useESM: true,
|
|
15
|
+
tsconfig: "tsconfig.jest.json", // Use specific tsconfig file for Jest
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
|
|
20
|
+
setupFilesAfterEnv: ["jest-extended/all"],
|
|
21
|
+
coveragePathIgnorePatterns: ["node_modules", "tests", "dist"],
|
|
22
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mongodb-mcp-server",
|
|
3
|
+
"description": "MongoDB Model Context Protocol Server",
|
|
4
|
+
"version": "0.0.4",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"author": "MongoDB <info@mongodb.com>",
|
|
7
|
+
"homepage": "https://github.com/mongodb-js/mongodb-mcp-server",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/mongodb-js/mongodb-mcp-server.git"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"mongodb-mcp-server": "dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"prepare": "npm run build",
|
|
20
|
+
"build:clean": "rm -rf dist",
|
|
21
|
+
"build:compile": "tsc",
|
|
22
|
+
"build:chmod": "chmod +x dist/index.js",
|
|
23
|
+
"build": "npm run build:clean && npm run build:compile && npm run build:chmod",
|
|
24
|
+
"inspect": "npm run build && mcp-inspector -- dist/index.js",
|
|
25
|
+
"prettier": "prettier",
|
|
26
|
+
"check": "npm run build && npm run check:lint && npm run check:format",
|
|
27
|
+
"check:lint": "eslint .",
|
|
28
|
+
"check:format": "prettier -c .",
|
|
29
|
+
"reformat": "prettier --write .",
|
|
30
|
+
"generate": "./scripts/generate.sh",
|
|
31
|
+
"test": "jest --coverage"
|
|
32
|
+
},
|
|
33
|
+
"license": "Apache-2.0",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@eslint/js": "^9.24.0",
|
|
36
|
+
"@jest/globals": "^29.7.0",
|
|
37
|
+
"@modelcontextprotocol/inspector": "^0.8.2",
|
|
38
|
+
"@redocly/cli": "^1.34.2",
|
|
39
|
+
"@types/jest": "^29.5.14",
|
|
40
|
+
"@types/node": "^22.14.0",
|
|
41
|
+
"@types/simple-oauth2": "^5.0.7",
|
|
42
|
+
"@types/yargs-parser": "^21.0.3",
|
|
43
|
+
"eslint": "^9.24.0",
|
|
44
|
+
"eslint-config-prettier": "^10.1.1",
|
|
45
|
+
"globals": "^16.0.0",
|
|
46
|
+
"jest": "^29.7.0",
|
|
47
|
+
"jest-environment-node": "^29.7.0",
|
|
48
|
+
"jest-extended": "^4.0.2",
|
|
49
|
+
"mongodb-runner": "^5.8.2",
|
|
50
|
+
"openapi-types": "^12.1.3",
|
|
51
|
+
"openapi-typescript": "^7.6.1",
|
|
52
|
+
"prettier": "^3.5.3",
|
|
53
|
+
"ts-jest": "^29.3.1",
|
|
54
|
+
"tsx": "^4.19.3",
|
|
55
|
+
"typescript": "^5.8.2",
|
|
56
|
+
"typescript-eslint": "^8.29.1",
|
|
57
|
+
"yaml": "^2.7.1"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@modelcontextprotocol/sdk": "^1.8.0",
|
|
61
|
+
"@mongodb-js/devtools-connect": "^3.7.2",
|
|
62
|
+
"@mongosh/service-provider-node-driver": "^3.6.0",
|
|
63
|
+
"bson": "^6.10.3",
|
|
64
|
+
"mongodb": "^6.15.0",
|
|
65
|
+
"mongodb-log-writer": "^2.4.1",
|
|
66
|
+
"mongodb-redact": "^1.1.6",
|
|
67
|
+
"mongodb-schema": "^12.6.2",
|
|
68
|
+
"openapi-fetch": "^0.13.5",
|
|
69
|
+
"simple-oauth2": "^5.1.0",
|
|
70
|
+
"yargs-parser": "^21.1.1",
|
|
71
|
+
"zod": "^3.24.2"
|
|
72
|
+
},
|
|
73
|
+
"engines": {
|
|
74
|
+
"node": ">=20.0.0"
|
|
75
|
+
}
|
|
76
|
+
}
|