Skip to content

Commit 1407270

Browse files
committed
add a mechanism to disable tools from the config
1 parent 0becdaa commit 1407270

32 files changed

+134
-72
lines changed

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 = {
@@ -74,6 +76,12 @@ function getEnvConfig(): Partial<UserConfig> {
7476
return;
7577
}
7678

79+
// Try to parse an array of values
80+
if (value.indexOf(",") !== -1) {
81+
obj[currentField] = value.split(",").map((v) => v.trim());
82+
return;
83+
}
84+
7785
obj[currentField] = value;
7886
return;
7987
}
@@ -107,5 +115,7 @@ function SNAKE_CASE_toCamelCase(str: string): string {
107115

108116
// Reads the cli args and parses them into a UserConfig object.
109117
function getCliConfig() {
110-
return argv(process.argv.slice(2)) as unknown as Partial<UserConfig>;
118+
return argv(process.argv.slice(2), {
119+
array: ["disabledTools"],
120+
}) as unknown as Partial<UserConfig>;
111121
}

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 { State } from "../../state.js";
33

44
export abstract class AtlasToolBase extends ToolBase {
55
constructor(state: State) {
66
super(state);
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/collectionIndexes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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 CollectionIndexesTool extends MongoDBToolBase {
66
protected name = "collection-indexes";
77
protected description = "Describe the indexes for a collection";
88
protected argsShape = DbOperationArgs;
9-
protected operationType: DbOperationType = "read";
9+
protected operationType: OperationType = "read";
1010

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

src/tools/mongodb/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,

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/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/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/dbStats.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 DbStatsTool extends MongoDBToolBase {
66
protected name = "db-stats";
@@ -9,7 +9,7 @@ export class DbStatsTool extends MongoDBToolBase {
99
database: DbOperationArgs.database,
1010
};
1111

12-
protected operationType: DbOperationType = "metadata";
12+
protected operationType: OperationType = "metadata";
1313

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

0 commit comments

Comments
 (0)