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> {

0 commit comments

Comments
 (0)