Skip to content

Commit 6181ff4

Browse files
authored
add a mechanism to disable tools from the config (#63)
1 parent c692587 commit 6181ff4

35 files changed

+172
-81
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,38 @@ The MongoDB MCP Server can be configured using multiple methods, with the follow
145145
| `apiClientSecret` | Atlas API client secret for authentication |
146146
| `connectionString` | MongoDB connection string for direct database connections (optional users may choose to inform it on every tool call) |
147147
| `logPath` | Folder to store logs |
148+
| `disabledTools` | An array of tool names, operation types, and/or categories of tools that will be disabled. |
148149

149-
**Default Log Path:**
150+
#### `logPath`
151+
152+
Default log location is as follows:
150153

151154
- Windows: `%LOCALAPPDATA%\mongodb\mongodb-mcp\.app-logs`
152155
- macOS/Linux: `~/.mongodb/mongodb-mcp/.app-logs`
153156

157+
#### Disabled Tools
158+
159+
You can disable specific tools or categories of tools by using the `disabledTools` option. This option accepts an array of strings,
160+
where each string can be a tool name, operation type, or category.
161+
162+
The way the array is constructed depends on the type of configuration method you use:
163+
164+
- For **environment variable** configuration, use a comma-separated string: `export MDB_MCP_DISABLED_TOOLS="create,update,delete,atlas,collectionSchema"`.
165+
- For **command-line argument** configuration, use a space-separated string: `--disabledTools create update delete atlas collectionSchema`.
166+
167+
Categories of tools:
168+
169+
- `atlas` - MongoDB Atlas tools, such as list clusters, create cluster, etc.
170+
- `mongodb` - MongoDB database tools, such as find, aggregate, etc.
171+
172+
Operation types:
173+
174+
- `create` - Tools that create resources, such as create cluster, insert document, etc.
175+
- `update` - Tools that update resources, such as update document, rename collection, etc.
176+
- `delete` - Tools that delete resources, such as delete document, drop collection, etc.
177+
- `read` - Tools that read resources, such as find, aggregate, list clusters, etc.
178+
- `metadata` - Tools that read metadata, such as list databases, list collections, collection schema, etc.
179+
154180
### Atlas API Access
155181

156182
To use the Atlas API tools, you'll need to create a service account in MongoDB Atlas:

src/config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface UserConfig {
1919
writeConcern: W;
2020
timeoutMS: number;
2121
};
22+
disabledTools: Array<string>;
2223
}
2324

2425
const defaults: UserConfig = {
@@ -29,6 +30,7 @@ const defaults: UserConfig = {
2930
writeConcern: "majority",
3031
timeoutMS: 30_000,
3132
},
33+
disabledTools: [],
3234
};
3335

3436
const mergedUserConfig = {
@@ -77,6 +79,12 @@ function getEnvConfig(): Partial<UserConfig> {
7779
return;
7880
}
7981

82+
// Try to parse an array of values
83+
if (value.indexOf(",") !== -1) {
84+
obj[currentField] = value.split(",").map((v) => v.trim());
85+
return;
86+
}
87+
8088
obj[currentField] = value;
8189
return;
8290
}
@@ -110,5 +118,7 @@ function SNAKE_CASE_toCamelCase(str: string): string {
110118

111119
// Reads the cli args and parses them into a UserConfig object.
112120
function getCliConfig() {
113-
return argv(process.argv.slice(2)) as unknown as Partial<UserConfig>;
121+
return argv(process.argv.slice(2), {
122+
array: ["disabledTools"],
123+
}) as unknown as Partial<UserConfig>;
114124
}

src/tools/atlas/atlasTool.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { ToolBase } from "../tool.js";
1+
import { ToolBase, ToolCategory } from "../tool.js";
22
import { Session } from "../../session.js";
33

44
export abstract class AtlasToolBase extends ToolBase {
55
constructor(protected readonly session: Session) {
66
super(session);
77
}
8+
9+
protected category: ToolCategory = "atlas";
810
}

src/tools/atlas/createAccessList.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
33
import { AtlasToolBase } from "./atlasTool.js";
4-
import { ToolArgs } from "../tool.js";
4+
import { ToolArgs, OperationType } from "../tool.js";
55

66
const DEFAULT_COMMENT = "Added by Atlas MCP";
77

88
export class CreateAccessListTool extends AtlasToolBase {
99
protected name = "atlas-create-access-list";
1010
protected description = "Allow Ip/CIDR ranges to access your MongoDB Atlas clusters.";
11+
protected operationType: OperationType = "create";
1112
protected argsShape = {
1213
projectId: z.string().describe("Atlas project ID"),
1314
ipAddresses: z

src/tools/atlas/createDBUser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
33
import { AtlasToolBase } from "./atlasTool.js";
4-
import { ToolArgs } from "../tool.js";
4+
import { ToolArgs, OperationType } from "../tool.js";
55
import { CloudDatabaseUser, DatabaseUserRole } from "../../common/atlas/openapi.js";
66

77
export class CreateDBUserTool extends AtlasToolBase {
88
protected name = "atlas-create-db-user";
99
protected description = "Create an MongoDB Atlas database user";
10+
protected operationType: OperationType = "create";
1011
protected argsShape = {
1112
projectId: z.string().describe("Atlas project ID"),
1213
username: z.string().describe("Username for the new user"),

src/tools/atlas/createFreeCluster.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
33
import { AtlasToolBase } from "./atlasTool.js";
4-
import { ToolArgs } from "../tool.js";
4+
import { ToolArgs, OperationType } from "../tool.js";
55
import { ClusterDescription20240805 } from "../../common/atlas/openapi.js";
66

77
export class CreateFreeClusterTool extends AtlasToolBase {
88
protected name = "atlas-create-free-cluster";
99
protected description = "Create a free MongoDB Atlas cluster";
10+
protected operationType: OperationType = "create";
1011
protected argsShape = {
1112
projectId: z.string().describe("Atlas project ID to create the cluster in"),
1213
name: z.string().describe("Name of the cluster"),

src/tools/atlas/inspectAccessList.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
33
import { AtlasToolBase } from "./atlasTool.js";
4-
import { ToolArgs } from "../tool.js";
4+
import { ToolArgs, OperationType } from "../tool.js";
55

66
export class InspectAccessListTool extends AtlasToolBase {
77
protected name = "atlas-inspect-access-list";
88
protected description = "Inspect Ip/CIDR ranges with access to your MongoDB Atlas clusters.";
9+
protected operationType: OperationType = "read";
910
protected argsShape = {
1011
projectId: z.string().describe("Atlas project ID"),
1112
};

src/tools/atlas/inspectCluster.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
33
import { AtlasToolBase } from "./atlasTool.js";
4-
import { ToolArgs } from "../tool.js";
4+
import { ToolArgs, OperationType } from "../tool.js";
55
import { ClusterDescription20240805 } from "../../common/atlas/openapi.js";
66

77
export class InspectClusterTool extends AtlasToolBase {
88
protected name = "atlas-inspect-cluster";
99
protected description = "Inspect MongoDB Atlas cluster";
10+
protected operationType: OperationType = "read";
1011
protected argsShape = {
1112
projectId: z.string().describe("Atlas project ID"),
1213
clusterName: z.string().describe("Atlas cluster name"),

src/tools/atlas/listClusters.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
33
import { AtlasToolBase } from "./atlasTool.js";
4-
import { ToolArgs } from "../tool.js";
4+
import { ToolArgs, OperationType } from "../tool.js";
55
import { PaginatedClusterDescription20240805, PaginatedOrgGroupView, Group } from "../../common/atlas/openapi.js";
66

77
export class ListClustersTool extends AtlasToolBase {
88
protected name = "atlas-list-clusters";
99
protected description = "List MongoDB Atlas clusters";
10+
protected operationType: OperationType = "read";
1011
protected argsShape = {
1112
projectId: z.string().describe("Atlas project ID to filter clusters").optional(),
1213
};

src/tools/atlas/listDBUsers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
33
import { AtlasToolBase } from "./atlasTool.js";
4-
import { ToolArgs } from "../tool.js";
4+
import { ToolArgs, OperationType } from "../tool.js";
55
import { DatabaseUserRole, UserScope } from "../../common/atlas/openapi.js";
66

77
export class ListDBUsersTool extends AtlasToolBase {
88
protected name = "atlas-list-db-users";
99
protected description = "List MongoDB Atlas database users";
10+
protected operationType: OperationType = "read";
1011
protected argsShape = {
1112
projectId: z.string().describe("Atlas project ID to filter DB users"),
1213
};

src/tools/atlas/listProjects.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
22
import { AtlasToolBase } from "./atlasTool.js";
3+
import { OperationType } from "../tool.js";
34

45
export class ListProjectsTool extends AtlasToolBase {
56
protected name = "atlas-list-projects";
67
protected description = "List MongoDB Atlas projects";
8+
protected operationType: OperationType = "read";
79
protected argsShape = {};
810

911
protected async execute(): Promise<CallToolResult> {

src/tools/mongodb/create/createIndex.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3-
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
4-
import { ToolArgs } from "../../tool.js";
3+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
4+
import { ToolArgs, OperationType } from "../../tool.js";
55
import { IndexDirection } from "mongodb";
66

77
export class CreateIndexTool extends MongoDBToolBase {
@@ -12,7 +12,7 @@ export class CreateIndexTool extends MongoDBToolBase {
1212
keys: z.record(z.string(), z.custom<IndexDirection>()).describe("The index definition"),
1313
};
1414

15-
protected operationType: DbOperationType = "create";
15+
protected operationType: OperationType = "create";
1616

1717
protected async execute({ database, collection, keys }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
1818
const provider = await this.ensureConnected();

src/tools/mongodb/create/insertMany.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3-
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
4-
import { ToolArgs } from "../../tool.js";
3+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
4+
import { ToolArgs, OperationType } from "../../tool.js";
55

66
export class InsertManyTool extends MongoDBToolBase {
77
protected name = "insert-many";
@@ -14,7 +14,7 @@ export class InsertManyTool extends MongoDBToolBase {
1414
"The array of documents to insert, matching the syntax of the document argument of db.collection.insertMany()"
1515
),
1616
};
17-
protected operationType: DbOperationType = "create";
17+
protected operationType: OperationType = "create";
1818

1919
protected async execute({
2020
database,

src/tools/mongodb/create/insertOne.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3-
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
4-
import { ToolArgs } from "../../tool.js";
3+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
4+
import { ToolArgs, OperationType } from "../../tool.js";
55

66
export class InsertOneTool extends MongoDBToolBase {
77
protected name = "insert-one";
@@ -16,7 +16,7 @@ export class InsertOneTool extends MongoDBToolBase {
1616
),
1717
};
1818

19-
protected operationType: DbOperationType = "create";
19+
protected operationType: OperationType = "create";
2020

2121
protected async execute({
2222
database,

src/tools/mongodb/delete/deleteMany.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3-
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
4-
import { ToolArgs } from "../../tool.js";
3+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
4+
import { ToolArgs, OperationType } from "../../tool.js";
55

66
export class DeleteManyTool extends MongoDBToolBase {
77
protected name = "delete-many";
@@ -16,7 +16,7 @@ export class DeleteManyTool extends MongoDBToolBase {
1616
"The query filter, specifying the deletion criteria. Matches the syntax of the filter argument of db.collection.deleteMany()"
1717
),
1818
};
19-
protected operationType: DbOperationType = "delete";
19+
protected operationType: OperationType = "delete";
2020

2121
protected async execute({
2222
database,

src/tools/mongodb/delete/deleteOne.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3-
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
4-
import { ToolArgs } from "../../tool.js";
3+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
4+
import { ToolArgs, OperationType } from "../../tool.js";
55

66
export class DeleteOneTool extends MongoDBToolBase {
77
protected name = "delete-one";
@@ -16,7 +16,7 @@ export class DeleteOneTool extends MongoDBToolBase {
1616
"The query filter, specifying the deletion criteria. Matches the syntax of the filter argument of db.collection.deleteMany()"
1717
),
1818
};
19-
protected operationType: DbOperationType = "delete";
19+
protected operationType: OperationType = "delete";
2020

2121
protected async execute({
2222
database,

src/tools/mongodb/delete/dropCollection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2-
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
3-
import { ToolArgs } from "../../tool.js";
2+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
3+
import { ToolArgs, OperationType } from "../../tool.js";
44

55
export class DropCollectionTool extends MongoDBToolBase {
66
protected name = "drop-collection";
@@ -9,7 +9,7 @@ export class DropCollectionTool extends MongoDBToolBase {
99
protected argsShape = {
1010
...DbOperationArgs,
1111
};
12-
protected operationType: DbOperationType = "delete";
12+
protected operationType: OperationType = "delete";
1313

1414
protected async execute({ database, collection }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
1515
const provider = await this.ensureConnected();

src/tools/mongodb/delete/dropDatabase.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2-
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
3-
import { ToolArgs } from "../../tool.js";
2+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
3+
import { ToolArgs, OperationType } from "../../tool.js";
44

55
export class DropDatabaseTool extends MongoDBToolBase {
66
protected name = "drop-database";
77
protected description = "Removes the specified database, deleting the associated data files";
88
protected argsShape = {
99
database: DbOperationArgs.database,
1010
};
11-
protected operationType: DbOperationType = "delete";
11+
protected operationType: OperationType = "delete";
1212

1313
protected async execute({ database }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
1414
const provider = await this.ensureConnected();

src/tools/mongodb/metadata/collectionSchema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2-
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
3-
import { ToolArgs } from "../../tool.js";
2+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
3+
import { ToolArgs, OperationType } from "../../tool.js";
44
import { parseSchema, SchemaField } from "mongodb-schema";
55

66
export class CollectionSchemaTool extends MongoDBToolBase {
77
protected name = "collection-schema";
88
protected description = "Describe the schema for a collection";
99
protected argsShape = DbOperationArgs;
1010

11-
protected operationType: DbOperationType = "metadata";
11+
protected operationType: OperationType = "metadata";
1212

1313
protected async execute({ database, collection }: ToolArgs<typeof DbOperationArgs>): Promise<CallToolResult> {
1414
const provider = await this.ensureConnected();

src/tools/mongodb/metadata/collectionStorageSize.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2-
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
3-
import { ToolArgs } from "../../tool.js";
2+
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
3+
import { ToolArgs, OperationType } from "../../tool.js";
44

55
export class CollectionStorageSizeTool extends MongoDBToolBase {
66
protected name = "collection-storage-size";
77
protected description = "Gets the size of the collection in MB";
88
protected argsShape = DbOperationArgs;
99

10-
protected operationType: DbOperationType = "metadata";
10+
protected operationType: OperationType = "metadata";
1111

1212
protected async execute({ database, collection }: ToolArgs<typeof DbOperationArgs>): Promise<CallToolResult> {
1313
const provider = await this.ensureConnected();

src/tools/mongodb/metadata/connect.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from "zod";
22
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3-
import { DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
4-
import { ToolArgs } from "../../tool.js";
3+
import { MongoDBToolBase } from "../mongodbTool.js";
4+
import { ToolArgs, OperationType } from "../../tool.js";
55
import { ErrorCodes, MongoDBError } from "../../../errors.js";
66
import config from "../../../config.js";
77

@@ -15,7 +15,7 @@ export class ConnectTool extends MongoDBToolBase {
1515
.describe("MongoDB connection string (in the mongodb:// or mongodb+srv:// format) or cluster name"),
1616
};
1717

18-
protected operationType: DbOperationType = "metadata";
18+
protected operationType: OperationType = "metadata";
1919

2020
protected async execute({
2121
connectionStringOrClusterName,

0 commit comments

Comments
 (0)