mongodb-mcp-server 0.0.5 → 0.0.7
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/CODEOWNERS +3 -0
- package/.github/dependabot.yml +10 -0
- package/.github/workflows/code_health.yaml +9 -27
- package/.github/workflows/code_health_fork.yaml +106 -0
- package/.github/workflows/codeql.yml +34 -0
- package/.github/workflows/lint.yml +37 -0
- package/.github/workflows/prepare_release.yaml +12 -4
- package/.github/workflows/publish.yaml +6 -3
- package/.prettierrc.json +1 -1
- package/README.md +16 -0
- package/dist/common/atlas/apiClient.js +1 -5
- package/dist/common/atlas/apiClient.js.map +1 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/logger.js +20 -1
- package/dist/logger.js.map +1 -1
- package/dist/server.js +44 -3
- package/dist/server.js.map +1 -1
- package/dist/session.js +50 -5
- package/dist/session.js.map +1 -1
- package/dist/telemetry/constants.js.map +1 -1
- package/dist/telemetry/telemetry.js +7 -6
- package/dist/telemetry/telemetry.js.map +1 -1
- package/dist/tools/atlas/{createAccessList.js → create/createAccessList.js} +1 -1
- package/dist/tools/atlas/create/createAccessList.js.map +1 -0
- package/dist/tools/atlas/{createDBUser.js → create/createDBUser.js} +1 -1
- package/dist/tools/atlas/create/createDBUser.js.map +1 -0
- package/dist/tools/atlas/{createFreeCluster.js → create/createFreeCluster.js} +5 -2
- package/dist/tools/atlas/create/createFreeCluster.js.map +1 -0
- package/dist/tools/atlas/{createProject.js → create/createProject.js} +1 -1
- package/dist/tools/atlas/create/createProject.js.map +1 -0
- package/dist/tools/atlas/metadata/connectCluster.js +97 -0
- package/dist/tools/atlas/metadata/connectCluster.js.map +1 -0
- package/dist/tools/atlas/{inspectAccessList.js → read/inspectAccessList.js} +1 -1
- package/dist/tools/atlas/read/inspectAccessList.js.map +1 -0
- package/dist/tools/atlas/{inspectCluster.js → read/inspectCluster.js} +1 -1
- package/dist/tools/atlas/read/inspectCluster.js.map +1 -0
- package/dist/tools/atlas/{listClusters.js → read/listClusters.js} +1 -1
- package/dist/tools/atlas/read/listClusters.js.map +1 -0
- package/dist/tools/atlas/{listDBUsers.js → read/listDBUsers.js} +1 -1
- package/dist/tools/atlas/read/listDBUsers.js.map +1 -0
- package/dist/tools/atlas/{listOrgs.js → read/listOrgs.js} +1 -1
- package/dist/tools/atlas/read/listOrgs.js.map +1 -0
- package/dist/tools/atlas/{listProjects.js → read/listProjects.js} +1 -1
- package/dist/tools/atlas/read/listProjects.js.map +1 -0
- package/dist/tools/atlas/tools.js +12 -10
- package/dist/tools/atlas/tools.js.map +1 -1
- package/dist/tools/mongodb/create/insertMany.js +1 -1
- package/dist/tools/mongodb/create/insertMany.js.map +1 -1
- package/dist/tools/mongodb/delete/deleteMany.js +1 -2
- package/dist/tools/mongodb/delete/deleteMany.js.map +1 -1
- package/dist/tools/mongodb/metadata/connect.js +59 -71
- package/dist/tools/mongodb/metadata/connect.js.map +1 -1
- package/dist/tools/mongodb/mongodbTool.js +37 -30
- package/dist/tools/mongodb/mongodbTool.js.map +1 -1
- package/dist/tools/mongodb/read/aggregate.js +1 -1
- package/dist/tools/mongodb/read/aggregate.js.map +1 -1
- package/dist/tools/mongodb/read/count.js +1 -2
- package/dist/tools/mongodb/read/count.js.map +1 -1
- package/dist/tools/mongodb/read/find.js +2 -4
- package/dist/tools/mongodb/read/find.js.map +1 -1
- package/dist/tools/mongodb/tools.js +4 -2
- package/dist/tools/mongodb/tools.js.map +1 -1
- package/dist/tools/mongodb/update/updateMany.js +2 -4
- package/dist/tools/mongodb/update/updateMany.js.map +1 -1
- package/dist/tools/tool.js +30 -6
- package/dist/tools/tool.js.map +1 -1
- package/package.json +3 -3
- package/src/common/atlas/apiClient.ts +3 -11
- package/src/config.ts +13 -8
- package/src/errors.ts +1 -1
- package/src/index.ts +3 -3
- package/src/logger.ts +26 -1
- package/src/server.ts +60 -5
- package/src/session.ts +69 -6
- package/src/telemetry/constants.ts +2 -2
- package/src/telemetry/telemetry.ts +9 -21
- package/src/telemetry/types.ts +28 -11
- package/src/tools/atlas/{createAccessList.ts → create/createAccessList.ts} +2 -2
- package/src/tools/atlas/{createDBUser.ts → create/createDBUser.ts} +3 -3
- package/src/tools/atlas/{createFreeCluster.ts → create/createFreeCluster.ts} +7 -4
- package/src/tools/atlas/{createProject.ts → create/createProject.ts} +3 -3
- package/src/tools/atlas/metadata/connectCluster.ts +114 -0
- package/src/tools/atlas/{inspectAccessList.ts → read/inspectAccessList.ts} +2 -2
- package/src/tools/atlas/{inspectCluster.ts → read/inspectCluster.ts} +3 -3
- package/src/tools/atlas/{listClusters.ts → read/listClusters.ts} +3 -3
- package/src/tools/atlas/{listDBUsers.ts → read/listDBUsers.ts} +3 -3
- package/src/tools/atlas/{listOrgs.ts → read/listOrgs.ts} +2 -2
- package/src/tools/atlas/{listProjects.ts → read/listProjects.ts} +3 -3
- package/src/tools/atlas/tools.ts +12 -10
- package/src/tools/mongodb/create/insertMany.ts +1 -1
- package/src/tools/mongodb/delete/deleteMany.ts +1 -2
- package/src/tools/mongodb/metadata/connect.ts +78 -75
- package/src/tools/mongodb/mongodbTool.ts +40 -30
- package/src/tools/mongodb/read/aggregate.ts +1 -1
- package/src/tools/mongodb/read/count.ts +1 -2
- package/src/tools/mongodb/read/find.ts +2 -4
- package/src/tools/mongodb/tools.ts +4 -2
- package/src/tools/mongodb/update/updateMany.ts +2 -4
- package/src/tools/tool.ts +40 -13
- package/tests/integration/helpers.ts +13 -3
- package/tests/integration/server.test.ts +46 -20
- package/tests/integration/tools/atlas/atlasHelpers.ts +7 -5
- package/tests/integration/tools/atlas/clusters.test.ts +68 -4
- package/tests/integration/tools/mongodb/metadata/connect.test.ts +85 -100
- package/tests/integration/tools/mongodb/mongodbHelpers.ts +32 -21
- package/tests/unit/telemetry.test.ts +200 -0
- package/dist/tools/atlas/createAccessList.js.map +0 -1
- package/dist/tools/atlas/createDBUser.js.map +0 -1
- package/dist/tools/atlas/createFreeCluster.js.map +0 -1
- package/dist/tools/atlas/createProject.js.map +0 -1
- package/dist/tools/atlas/inspectAccessList.js.map +0 -1
- package/dist/tools/atlas/inspectCluster.js.map +0 -1
- package/dist/tools/atlas/listClusters.js.map +0 -1
- package/dist/tools/atlas/listDBUsers.js.map +0 -1
- package/dist/tools/atlas/listOrgs.js.map +0 -1
- package/dist/tools/atlas/listProjects.js.map +0 -1
|
@@ -1,84 +1,72 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { MongoDBToolBase } from "../mongodbTool.js";
|
|
3
|
-
import
|
|
3
|
+
import assert from "assert";
|
|
4
|
+
const disconnectedSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
connectionString: z.string().describe("MongoDB connection string (in the mongodb:// or mongodb+srv:// format)"),
|
|
7
|
+
})
|
|
8
|
+
.describe("Options for connecting to MongoDB.");
|
|
9
|
+
const connectedSchema = z
|
|
10
|
+
.object({
|
|
11
|
+
connectionString: z
|
|
12
|
+
.string()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("MongoDB connection string to switch to (in the mongodb:// or mongodb+srv:// format)"),
|
|
15
|
+
})
|
|
16
|
+
.describe("Options for switching the current MongoDB connection. If a connection string is not provided, the connection string from the config will be used.");
|
|
17
|
+
const connectedName = "switch-connection";
|
|
18
|
+
const disconnectedName = "connect";
|
|
19
|
+
const connectedDescription = "Switch to a different MongoDB connection. If the user has configured a connection string or has previously called the connect tool, a connection is already established and there's no need to call this tool unless the user has explicitly requested to switch to a new instance.";
|
|
20
|
+
const disconnectedDescription = "Connect to a MongoDB instance";
|
|
4
21
|
export class ConnectTool extends MongoDBToolBase {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(
|
|
7
|
-
this.name =
|
|
8
|
-
this.description =
|
|
22
|
+
constructor(session, config, telemetry) {
|
|
23
|
+
super(session, config, telemetry);
|
|
24
|
+
this.name = disconnectedName;
|
|
25
|
+
this.description = disconnectedDescription;
|
|
26
|
+
// Here the default is empty just to trigger registration, but we're going to override it with the correct
|
|
27
|
+
// schema in the register method.
|
|
9
28
|
this.argsShape = {
|
|
10
|
-
|
|
11
|
-
.array(z
|
|
12
|
-
.union([
|
|
13
|
-
z.object({
|
|
14
|
-
connectionString: z
|
|
15
|
-
.string()
|
|
16
|
-
.describe("MongoDB connection string (in the mongodb:// or mongodb+srv:// format)"),
|
|
17
|
-
}),
|
|
18
|
-
z.object({
|
|
19
|
-
clusterName: z.string().describe("MongoDB cluster name"),
|
|
20
|
-
}),
|
|
21
|
-
])
|
|
22
|
-
.optional())
|
|
23
|
-
.optional()
|
|
24
|
-
.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."),
|
|
29
|
+
connectionString: z.string().optional(),
|
|
25
30
|
};
|
|
26
31
|
this.operationType = "metadata";
|
|
32
|
+
session.on("close", () => {
|
|
33
|
+
this.updateMetadata();
|
|
34
|
+
});
|
|
27
35
|
}
|
|
28
|
-
async execute({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
36
|
+
async execute({ connectionString }) {
|
|
37
|
+
switch (this.name) {
|
|
38
|
+
case disconnectedName:
|
|
39
|
+
assert(connectionString, "Connection string is required");
|
|
40
|
+
break;
|
|
41
|
+
case connectedName:
|
|
42
|
+
connectionString ?? (connectionString = this.config.connectionString);
|
|
43
|
+
assert(connectionString, "Cannot switch to a new connection because no connection string was provided and no default connection string is configured.");
|
|
44
|
+
break;
|
|
38
45
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
await this.connectToMongoDB(connectionString);
|
|
47
|
+
this.updateMetadata();
|
|
48
|
+
return {
|
|
49
|
+
content: [{ type: "text", text: "Successfully connected to MongoDB." }],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
register(server) {
|
|
53
|
+
super.register(server);
|
|
54
|
+
this.updateMetadata();
|
|
55
|
+
}
|
|
56
|
+
updateMetadata() {
|
|
57
|
+
if (this.config.connectionString || this.session.serviceProvider) {
|
|
58
|
+
this.update?.({
|
|
59
|
+
name: connectedName,
|
|
60
|
+
description: connectedDescription,
|
|
61
|
+
inputSchema: connectedSchema,
|
|
62
|
+
});
|
|
45
63
|
}
|
|
46
64
|
else {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
type: "text",
|
|
54
|
-
text: `Connecting via cluster name not supported yet. Please provide a connection string.`,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
await this.connectToMongoDB(connectionString);
|
|
61
|
-
return {
|
|
62
|
-
content: [{ type: "text", text: `Successfully connected to ${connectionString}.` }],
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
// Sometimes the model will supply an incorrect connection string. If the user has configured
|
|
67
|
-
// a different one as environment variable or a cli argument, suggest using that one instead.
|
|
68
|
-
if (this.config.connectionString &&
|
|
69
|
-
error instanceof DriverError &&
|
|
70
|
-
this.config.connectionString !== connectionString) {
|
|
71
|
-
return {
|
|
72
|
-
content: [
|
|
73
|
-
{
|
|
74
|
-
type: "text",
|
|
75
|
-
text: `Failed to connect to MongoDB at '${connectionString}' due to error: '${error.message}.` +
|
|
76
|
-
`Your config lists a different connection string: '${this.config.connectionString}' - do you want to try connecting to it instead?`,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
throw error;
|
|
65
|
+
this.update?.({
|
|
66
|
+
name: disconnectedName,
|
|
67
|
+
description: disconnectedDescription,
|
|
68
|
+
inputSchema: disconnectedSchema,
|
|
69
|
+
});
|
|
82
70
|
}
|
|
83
71
|
}
|
|
84
72
|
}
|
|
@@ -1 +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;
|
|
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;AAGpD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAK5B,MAAM,kBAAkB,GAAG,CAAC;KACvB,MAAM,CAAC;IACJ,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wEAAwE,CAAC;CAClH,CAAC;KACD,QAAQ,CAAC,oCAAoC,CAAC,CAAC;AAEpD,MAAM,eAAe,GAAG,CAAC;KACpB,MAAM,CAAC;IACJ,gBAAgB,EAAE,CAAC;SACd,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CAAC,qFAAqF,CAAC;CACvG,CAAC;KACD,QAAQ,CACL,mJAAmJ,CACtJ,CAAC;AAEN,MAAM,aAAa,GAAG,mBAA4B,CAAC;AACnD,MAAM,gBAAgB,GAAG,SAAkB,CAAC;AAE5C,MAAM,oBAAoB,GACtB,qRAAqR,CAAC;AAC1R,MAAM,uBAAuB,GAAG,+BAA+B,CAAC;AAEhE,MAAM,OAAO,WAAY,SAAQ,eAAe;IAY5C,YAAY,OAAgB,EAAE,MAAkB,EAAE,SAAoB;QAClE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QAZ5B,SAA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B;gBACjC,WAAW,EAAE,eAAe;aAC/B,CAAC,CAAC;QACP,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,MAAM,EAAE,CAAC;gBACV,IAAI,EAAE,gBAAgB;gBACtB,WAAW,EAAE,uBAAuB;gBACpC,WAAW,EAAE,kBAAkB;aAClC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { ToolBase } from "../tool.js";
|
|
3
|
-
import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver";
|
|
4
3
|
import { ErrorCodes, MongoDBError } from "../../errors.js";
|
|
4
|
+
import logger, { LogId } from "../../logger.js";
|
|
5
5
|
export const DbOperationArgs = {
|
|
6
6
|
database: z.string().describe("Database name"),
|
|
7
7
|
collection: z.string().describe("Collection name"),
|
|
@@ -13,7 +13,13 @@ export class MongoDBToolBase extends ToolBase {
|
|
|
13
13
|
}
|
|
14
14
|
async ensureConnected() {
|
|
15
15
|
if (!this.session.serviceProvider && this.config.connectionString) {
|
|
16
|
-
|
|
16
|
+
try {
|
|
17
|
+
await this.connectToMongoDB(this.config.connectionString);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
logger.error(LogId.mongodbConnectFailure, "mongodbTool", `Failed to connect to MongoDB instance using the connection string from the config: ${error}`);
|
|
21
|
+
throw new MongoDBError(ErrorCodes.MisconfiguredConnectionString, "Not connected to MongoDB.");
|
|
22
|
+
}
|
|
17
23
|
}
|
|
18
24
|
if (!this.session.serviceProvider) {
|
|
19
25
|
throw new MongoDBError(ErrorCodes.NotConnectedToMongoDB, "Not connected to MongoDB");
|
|
@@ -21,37 +27,38 @@ export class MongoDBToolBase extends ToolBase {
|
|
|
21
27
|
return this.session.serviceProvider;
|
|
22
28
|
}
|
|
23
29
|
handleError(error, args) {
|
|
24
|
-
if (error instanceof MongoDBError
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
if (error instanceof MongoDBError) {
|
|
31
|
+
switch (error.code) {
|
|
32
|
+
case ErrorCodes.NotConnectedToMongoDB:
|
|
33
|
+
return {
|
|
34
|
+
content: [
|
|
35
|
+
{
|
|
36
|
+
type: "text",
|
|
37
|
+
text: "You need to connect to a MongoDB instance before you can access its data.",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: "text",
|
|
41
|
+
text: "Please use the 'connect' or 'switch-connection' tool to connect to a MongoDB instance.",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
isError: true,
|
|
45
|
+
};
|
|
46
|
+
case ErrorCodes.MisconfiguredConnectionString:
|
|
47
|
+
return {
|
|
48
|
+
content: [
|
|
49
|
+
{
|
|
50
|
+
type: "text",
|
|
51
|
+
text: "The configured connection string is not valid. Please check the connection string and confirm it points to a valid MongoDB instance. Alternatively, use the 'switch-connection' tool to connect to a different instance.",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
isError: true,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
38
57
|
}
|
|
39
58
|
return super.handleError(error, args);
|
|
40
59
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
productDocsLink: "https://docs.mongodb.com/todo-mcp",
|
|
44
|
-
productName: "MongoDB MCP",
|
|
45
|
-
readConcern: {
|
|
46
|
-
level: this.config.connectOptions.readConcern,
|
|
47
|
-
},
|
|
48
|
-
readPreference: this.config.connectOptions.readPreference,
|
|
49
|
-
writeConcern: {
|
|
50
|
-
w: this.config.connectOptions.writeConcern,
|
|
51
|
-
},
|
|
52
|
-
timeoutMS: this.config.connectOptions.timeoutMS,
|
|
53
|
-
});
|
|
54
|
-
this.session.serviceProvider = provider;
|
|
60
|
+
connectToMongoDB(connectionString) {
|
|
61
|
+
return this.session.connectToMongoDB(connectionString, this.config.connectOptions);
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
//# sourceMappingURL=mongodbTool.js.map
|
|
@@ -1 +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,EAAY,QAAQ,EAAgB,MAAM,YAAY,CAAC;
|
|
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,EAAY,QAAQ,EAAgB,MAAM,YAAY,CAAC;AAG9D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEhD,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,OAAgB,eAAgB,SAAQ,QAAQ;IAAtD;;QACc,aAAQ,GAAiB,SAAS,CAAC;IA8DjD,CAAC;IA5Da,KAAK,CAAC,eAAe;QAC3B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAChE,IAAI,CAAC;gBACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;YAC9D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,MAAM,CAAC,KAAK,CACR,KA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oDBToolBase } from "../mongodbTool.js";
|
|
3
3
|
import { EJSON } from "bson";
|
|
4
4
|
export const AggregateArgs = {
|
|
5
|
-
pipeline: z.array(z.
|
|
5
|
+
pipeline: z.array(z.record(z.string(), z.unknown())).describe("An array of aggregation stages to execute"),
|
|
6
6
|
};
|
|
7
7
|
export class AggregateTool extends MongoDBToolBase {
|
|
8
8
|
constructor() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/read/aggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7B,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"aggregate.js","sourceRoot":"","sources":["../../../../src/tools/mongodb/read/aggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7B,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,2CAA2C,CAAC;CAC7G,CAAC;AAEF,MAAM,OAAO,aAAc,SAAQ,eAAe;IAAlD;;QACc,SAAI,GAAG,WAAW,CAAC;QACnB,gBAAW,GAAG,iDAAiD,CAAC;QAChE,cAAS,GAAG;YAClB,GAAG,eAAe;YAClB,GAAG,aAAa;SACnB,CAAC;QACQ,kBAAa,GAAkB,MAAM,CAAC;IA2BpD,CAAC;IAzBa,KAAK,CAAC,OAAO,CAAC,EACpB,QAAQ,EACR,UAAU,EACV,QAAQ,GACsB;QAC9B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;QAErF,MAAM,OAAO,GAA0C;YACnD;gBACI,IAAI,EAAE,SAAS,SAAS,CAAC,MAAM,iCAAiC,UAAU,IAAI;gBAC9E,IAAI,EAAE,MAAM;aACf;YACD,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;gBACrB,OAAO;oBACH,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC;oBAC1B,IAAI,EAAE,MAAM;iBACmB,CAAC;YACxC,CAAC,CAAC;SACL,CAAC;QAEF,OAAO;YACH,OAAO;SACV,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -2,8 +2,7 @@ import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
export const CountArgs = {
|
|
4
4
|
query: z
|
|
5
|
-
.
|
|
6
|
-
.passthrough()
|
|
5
|
+
.record(z.string(), z.unknown())
|
|
7
6
|
.optional()
|
|
8
7
|
.describe("The query filter to count documents. Matches the syntax of the filter argument of db.collection.count()"),
|
|
9
8
|
};
|
|
@@ -1 +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
|
|
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,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;SAC/B,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"}
|
|
@@ -3,13 +3,11 @@ import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
|
|
|
3
3
|
import { EJSON } from "bson";
|
|
4
4
|
export const FindArgs = {
|
|
5
5
|
filter: z
|
|
6
|
-
.
|
|
7
|
-
.passthrough()
|
|
6
|
+
.record(z.string(), z.unknown())
|
|
8
7
|
.optional()
|
|
9
8
|
.describe("The query filter, matching the syntax of the query argument of db.collection.find()"),
|
|
10
9
|
projection: z
|
|
11
|
-
.
|
|
12
|
-
.passthrough()
|
|
10
|
+
.record(z.string(), z.unknown())
|
|
13
11
|
.optional()
|
|
14
12
|
.describe("The projection, matching the syntax of the projection argument of db.collection.find()"),
|
|
15
13
|
limit: z.number().optional().default(10).describe("The maximum number of documents to return"),
|
|
@@ -1 +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,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7B,MAAM,CAAC,MAAM,QAAQ,GAAG;IACpB,MAAM,EAAE,CAAC;SACJ,MAAM,CAAC,EAAE,CAAC
|
|
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,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7B,MAAM,CAAC,MAAM,QAAQ,GAAG;IACpB,MAAM,EAAE,CAAC;SACJ,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;SAC/B,QAAQ,EAAE;SACV,QAAQ,CAAC,qFAAqF,CAAC;IACpG,UAAU,EAAE,CAAC;SACR,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;SAC/B,QAAQ,E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SACV,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// TODO: https://github.com/mongodb-js/mongodb-mcp-server/issues/141 - reenable when the connect tool is reenabled
|
|
2
|
+
// import { ConnectTool } from "./metadata/connect.js";
|
|
2
3
|
import { ListCollectionsTool } from "./metadata/listCollections.js";
|
|
3
4
|
import { CollectionIndexesTool } from "./read/collectionIndexes.js";
|
|
4
5
|
import { ListDatabasesTool } from "./metadata/listDatabases.js";
|
|
@@ -19,7 +20,8 @@ import { ExplainTool } from "./metadata/explain.js";
|
|
|
19
20
|
import { CreateCollectionTool } from "./create/createCollection.js";
|
|
20
21
|
import { LogsTool } from "./metadata/logs.js";
|
|
21
22
|
export const MongoDbTools = [
|
|
22
|
-
|
|
23
|
+
// TODO: https://github.com/mongodb-js/mongodb-mcp-server/issues/141 - reenable when the connect tool is reenabled
|
|
24
|
+
// ConnectTool,
|
|
23
25
|
ListCollectionsTool,
|
|
24
26
|
ListDatabasesTool,
|
|
25
27
|
CollectionIndexesTool,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/tools/mongodb/tools.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/tools/mongodb/tools.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,uDAAuD;AACvD,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;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB,kHAAkH;IAClH,eAAe;IACf,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;IACpB,QAAQ;CACX,CAAC"}
|
|
@@ -8,13 +8,11 @@ export class UpdateManyTool extends MongoDBToolBase {
|
|
|
8
8
|
this.argsShape = {
|
|
9
9
|
...DbOperationArgs,
|
|
10
10
|
filter: z
|
|
11
|
-
.
|
|
12
|
-
.passthrough()
|
|
11
|
+
.record(z.string(), z.unknown())
|
|
13
12
|
.optional()
|
|
14
13
|
.describe("The selection criteria for the update, matching the syntax of the filter argument of db.collection.updateOne()"),
|
|
15
14
|
update: z
|
|
16
|
-
.
|
|
17
|
-
.passthrough()
|
|
15
|
+
.record(z.string(), z.unknown())
|
|
18
16
|
.describe("An update document describing the modifications to apply using update operator expressions"),
|
|
19
17
|
upsert: z
|
|
20
18
|
.boolean()
|
|
@@ -1 +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,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,OAAO,cAAe,SAAQ,eAAe;IAAnD;;QACc,SAAI,GAAG,aAAa,CAAC;QACrB,gBAAW,GAAG,wEAAwE,CAAC;QACvF,cAAS,GAAG;YAClB,GAAG,eAAe;YAClB,MAAM,EAAE,CAAC;iBACJ,MAAM,CAAC,EAAE,CAAC
|
|
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,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,OAAO,cAAe,SAAQ,eAAe;IAAnD;;QACc,SAAI,GAAG,aAAa,CAAC;QACrB,gBAAW,GAAG,wEAAwE,CAAC;QACvF,cAAS,GAAG;YAClB,GAAG,eAAe;YAClB,MAAM,EAAE,CAAC;iBACJ,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;iBAC/B,QAAQ,EAAE;iBACV,QAAQ,CACL,gHAAgH,CACnH;YACL,MAAM,EAAE,CAAC;iBACJ,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;iBAC/B,QAAQ,CAAC,4FAA4F,CAAC;YAC3G,MA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ongoLogId } from "mongodb-log-writer";
|
|
1
|
+
import logger, { LogId } from "../logger.js";
|
|
3
2
|
export class ToolBase {
|
|
4
3
|
constructor(session, config, telemetry) {
|
|
5
4
|
this.session = session;
|
|
@@ -35,24 +34,49 @@ export class ToolBase {
|
|
|
35
34
|
const callback = async (...args) => {
|
|
36
35
|
const startTime = Date.now();
|
|
37
36
|
try {
|
|
38
|
-
logger.debug(
|
|
37
|
+
logger.debug(LogId.toolExecute, "tool", `Executing ${this.name} with args: ${JSON.stringify(args)}`);
|
|
39
38
|
const result = await this.execute(...args);
|
|
40
39
|
await this.emitToolEvent(startTime, result);
|
|
41
40
|
return result;
|
|
42
41
|
}
|
|
43
42
|
catch (error) {
|
|
44
|
-
logger.error(
|
|
43
|
+
logger.error(LogId.toolExecuteFailure, "tool", `Error executing ${this.name}: ${error}`);
|
|
45
44
|
const toolResult = await this.handleError(error, args[0]);
|
|
46
45
|
await this.emitToolEvent(startTime, toolResult).catch(() => { });
|
|
47
46
|
return toolResult;
|
|
48
47
|
}
|
|
49
48
|
};
|
|
50
49
|
server.tool(this.name, this.description, this.argsShape, callback);
|
|
50
|
+
// This is very similar to RegisteredTool.update, but without the bugs around the name.
|
|
51
|
+
// In the upstream update method, the name is captured in the closure and not updated when
|
|
52
|
+
// the tool name changes. This means that you only get one name update before things end up
|
|
53
|
+
// in a broken state.
|
|
54
|
+
this.update = (updates) => {
|
|
55
|
+
const tools = server["_registeredTools"];
|
|
56
|
+
const existingTool = tools[this.name];
|
|
57
|
+
if (updates.name && updates.name !== this.name) {
|
|
58
|
+
delete tools[this.name];
|
|
59
|
+
this.name = updates.name;
|
|
60
|
+
tools[this.name] = existingTool;
|
|
61
|
+
}
|
|
62
|
+
if (updates.description) {
|
|
63
|
+
existingTool.description = updates.description;
|
|
64
|
+
this.description = updates.description;
|
|
65
|
+
}
|
|
66
|
+
if (updates.inputSchema) {
|
|
67
|
+
existingTool.inputSchema = updates.inputSchema;
|
|
68
|
+
}
|
|
69
|
+
server.sendToolListChanged();
|
|
70
|
+
};
|
|
51
71
|
}
|
|
52
72
|
// Checks if a tool is allowed to run based on the config
|
|
53
73
|
verifyAllowed() {
|
|
54
74
|
let errorClarification;
|
|
55
|
-
|
|
75
|
+
// Check read-only mode first
|
|
76
|
+
if (this.config.readOnly && !["read", "metadata"].includes(this.operationType)) {
|
|
77
|
+
errorClarification = `read-only mode is enabled, its operation type, \`${this.operationType}\`,`;
|
|
78
|
+
}
|
|
79
|
+
else if (this.config.disabledTools.includes(this.category)) {
|
|
56
80
|
errorClarification = `its category, \`${this.category}\`,`;
|
|
57
81
|
}
|
|
58
82
|
else if (this.config.disabledTools.includes(this.operationType)) {
|
|
@@ -62,7 +86,7 @@ export class ToolBase {
|
|
|
62
86
|
errorClarification = `it`;
|
|
63
87
|
}
|
|
64
88
|
if (errorClarification) {
|
|
65
|
-
logger.debug(
|
|
89
|
+
logger.debug(LogId.toolDisabled, "tool", `Prevented registration of ${this.name} because ${errorClarification} is disabled in the config`);
|
|
66
90
|
return false;
|
|
67
91
|
}
|
|
68
92
|
return true;
|
package/dist/tools/tool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/tools/tool.ts"],"names":[],"mappings":"AAIA,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/tools/tool.ts"],"names":[],"mappings":"AAIA,OAAO,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAU7C,MAAM,OAAgB,QAAQ;IAa1B,YACuB,OAAgB,EAChB,MAAkB,EAClB,SAAoB;QAFpB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAY;QAClB,cAAS,GAAT,SAAS,CAAW;IACxC,CAAC;IAEJ;;;;;OAKG;IACK,KAAK,CAAC,aAAa,CAAC,SAAiB,EAAE,MAAsB;QACjE,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,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,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;oBAC7F,OAAO,EAAE,IAAI;iBAChB;aACJ;SACJ,CAAC;IACN,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb-mcp-server",
|
|
3
3
|
"description": "MongoDB Model Context Protocol Server",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "MongoDB <info@mongodb.com>",
|
|
7
7
|
"homepage": "https://github.com/mongodb-js/mongodb-mcp-server",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@eslint/js": "^9.24.0",
|
|
36
36
|
"@jest/globals": "^29.7.0",
|
|
37
|
-
"@modelcontextprotocol/inspector": "^0.
|
|
37
|
+
"@modelcontextprotocol/inspector": "^0.10.2",
|
|
38
38
|
"@redocly/cli": "^1.34.2",
|
|
39
39
|
"@types/jest": "^29.5.14",
|
|
40
40
|
"@types/node": "^22.14.0",
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
"jest-environment-node": "^29.7.0",
|
|
50
50
|
"jest-extended": "^4.0.2",
|
|
51
51
|
"mongodb-runner": "^5.8.2",
|
|
52
|
-
"native-machine-id": "^0.1.0",
|
|
53
52
|
"openapi-types": "^12.1.3",
|
|
54
53
|
"openapi-typescript": "^7.6.1",
|
|
55
54
|
"prettier": "^3.5.3",
|
|
@@ -69,6 +68,7 @@
|
|
|
69
68
|
"mongodb-log-writer": "^2.4.1",
|
|
70
69
|
"mongodb-redact": "^1.1.6",
|
|
71
70
|
"mongodb-schema": "^12.6.2",
|
|
71
|
+
"native-machine-id": "^0.1.0",
|
|
72
72
|
"openapi-fetch": "^0.13.5",
|
|
73
73
|
"simple-oauth2": "^5.1.0",
|
|
74
74
|
"yargs-parser": "^21.1.1",
|
|
@@ -4,8 +4,6 @@ import { AccessToken, ClientCredentials } from "simple-oauth2";
|
|
|
4
4
|
import { ApiClientError } from "./apiClientError.js";
|
|
5
5
|
import { paths, operations } from "./openapi.js";
|
|
6
6
|
import { BaseEvent } from "../../telemetry/types.js";
|
|
7
|
-
import { mongoLogId } from "mongodb-log-writer";
|
|
8
|
-
import logger from "../../logger.js";
|
|
9
7
|
import { packageInfo } from "../../packageInfo.js";
|
|
10
8
|
|
|
11
9
|
const ATLAS_API_VERSION = "2025-03-12";
|
|
@@ -17,7 +15,7 @@ export interface ApiClientCredentials {
|
|
|
17
15
|
|
|
18
16
|
export interface ApiClientOptions {
|
|
19
17
|
credentials?: ApiClientCredentials;
|
|
20
|
-
baseUrl
|
|
18
|
+
baseUrl: string;
|
|
21
19
|
userAgent?: string;
|
|
22
20
|
}
|
|
23
21
|
|
|
@@ -65,12 +63,11 @@ export class ApiClient {
|
|
|
65
63
|
},
|
|
66
64
|
};
|
|
67
65
|
|
|
68
|
-
constructor(options
|
|
66
|
+
constructor(options: ApiClientOptions) {
|
|
69
67
|
this.options = {
|
|
70
68
|
...options,
|
|
71
|
-
baseUrl: options?.baseUrl || "https://cloud.mongodb.com/",
|
|
72
69
|
userAgent:
|
|
73
|
-
options
|
|
70
|
+
options.userAgent ||
|
|
74
71
|
`AtlasMCP/${packageInfo.version} (${process.platform}; ${process.arch}; ${process.env.HOSTNAME || "unknown"})`,
|
|
75
72
|
};
|
|
76
73
|
|
|
@@ -98,11 +95,6 @@ export class ApiClient {
|
|
|
98
95
|
}
|
|
99
96
|
|
|
100
97
|
public hasCredentials(): boolean {
|
|
101
|
-
logger.info(
|
|
102
|
-
mongoLogId(1_000_000),
|
|
103
|
-
"api-client",
|
|
104
|
-
`Checking if API client has credentials: ${!!(this.oauth2Client && this.accessToken)}`
|
|
105
|
-
);
|
|
106
98
|
return !!(this.oauth2Client && this.accessToken);
|
|
107
99
|
}
|
|
108
100
|
|
package/src/config.ts
CHANGED
|
@@ -4,25 +4,29 @@ import argv from "yargs-parser";
|
|
|
4
4
|
|
|
5
5
|
import { ReadConcernLevel, ReadPreferenceMode, W } from "mongodb";
|
|
6
6
|
|
|
7
|
+
export interface ConnectOptions {
|
|
8
|
+
readConcern: ReadConcernLevel;
|
|
9
|
+
readPreference: ReadPreferenceMode;
|
|
10
|
+
writeConcern: W;
|
|
11
|
+
timeoutMS: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
// If we decide to support non-string config options, we'll need to extend the mechanism for parsing
|
|
8
15
|
// env variables.
|
|
9
16
|
export interface UserConfig {
|
|
10
|
-
apiBaseUrl
|
|
17
|
+
apiBaseUrl: string;
|
|
11
18
|
apiClientId?: string;
|
|
12
19
|
apiClientSecret?: string;
|
|
13
20
|
telemetry?: "enabled" | "disabled";
|
|
14
21
|
logPath: string;
|
|
15
22
|
connectionString?: string;
|
|
16
|
-
connectOptions:
|
|
17
|
-
readConcern: ReadConcernLevel;
|
|
18
|
-
readPreference: ReadPreferenceMode;
|
|
19
|
-
writeConcern: W;
|
|
20
|
-
timeoutMS: number;
|
|
21
|
-
};
|
|
23
|
+
connectOptions: ConnectOptions;
|
|
22
24
|
disabledTools: Array<string>;
|
|
25
|
+
readOnly?: boolean;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
const defaults: UserConfig = {
|
|
29
|
+
apiBaseUrl: "https://cloud.mongodb.com/",
|
|
26
30
|
logPath: getLogPath(),
|
|
27
31
|
connectOptions: {
|
|
28
32
|
readConcern: "local",
|
|
@@ -31,7 +35,8 @@ const defaults: UserConfig = {
|
|
|
31
35
|
timeoutMS: 30_000,
|
|
32
36
|
},
|
|
33
37
|
disabledTools: [],
|
|
34
|
-
telemetry: "
|
|
38
|
+
telemetry: "enabled",
|
|
39
|
+
readOnly: false,
|
|
35
40
|
};
|
|
36
41
|
|
|
37
42
|
export const config = {
|