Skip to content

add a mechanism to disable tools from the config #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,38 @@ The MongoDB MCP Server can be configured using multiple methods, with the follow
| `apiClientSecret` | Atlas API client secret for authentication |
| `connectionString` | MongoDB connection string for direct database connections (optional users may choose to inform it on every tool call) |
| `logPath` | Folder to store logs |
| `disabledTools` | An array of tool names, operation types, and/or categories of tools that will be disabled. |

**Default Log Path:**
#### `logPath`

Default log location is as follows:

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

#### Disabled Tools

You can disable specific tools or categories of tools by using the `disabledTools` option. This option accepts an array of strings,
where each string can be a tool name, operation type, or category.

The way the array is constructed depends on the type of configuration method you use:

- For **environment variable** configuration, use a comma-separated string: `export MDB_MCP_DISABLED_TOOLS="create,update,delete,atlas,collectionSchema"`.
- For **command-line argument** configuration, use a space-separated string: `--disabledTools create update delete atlas collectionSchema`.

Categories of tools:

- `atlas` - MongoDB Atlas tools, such as list clusters, create cluster, etc.
- `mongodb` - MongoDB database tools, such as find, aggregate, etc.

Operation types:

- `create` - Tools that create resources, such as create cluster, insert document, etc.
- `update` - Tools that update resources, such as update document, rename collection, etc.
- `delete` - Tools that delete resources, such as delete document, drop collection, etc.
- `read` - Tools that read resources, such as find, aggregate, list clusters, etc.
- `metadata` - Tools that read metadata, such as list databases, list collections, collection schema, etc.

### Atlas API Access

To use the Atlas API tools, you'll need to create a service account in MongoDB Atlas:
Expand Down
12 changes: 11 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface UserConfig {
writeConcern: W;
timeoutMS: number;
};
disabledTools: Array<string>;
}

const defaults: UserConfig = {
Expand All @@ -29,6 +30,7 @@ const defaults: UserConfig = {
writeConcern: "majority",
timeoutMS: 30_000,
},
disabledTools: [],
};

const mergedUserConfig = {
Expand Down Expand Up @@ -77,6 +79,12 @@ function getEnvConfig(): Partial<UserConfig> {
return;
}

// Try to parse an array of values
if (value.indexOf(",") !== -1) {
obj[currentField] = value.split(",").map((v) => v.trim());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this supports an array anyways we could just always do the split without the indexOf check

return;
}

obj[currentField] = value;
return;
}
Expand Down Expand Up @@ -110,5 +118,7 @@ function SNAKE_CASE_toCamelCase(str: string): string {

// Reads the cli args and parses them into a UserConfig object.
function getCliConfig() {
return argv(process.argv.slice(2)) as unknown as Partial<UserConfig>;
return argv(process.argv.slice(2), {
array: ["disabledTools"],
}) as unknown as Partial<UserConfig>;
}
4 changes: 3 additions & 1 deletion src/tools/atlas/atlasTool.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ToolBase } from "../tool.js";
import { ToolBase, ToolCategory } from "../tool.js";
import { Session } from "../../session.js";

export abstract class AtlasToolBase extends ToolBase {
constructor(protected readonly session: Session) {
super(session);
}

protected category: ToolCategory = "atlas";
}
3 changes: 2 additions & 1 deletion src/tools/atlas/createAccessList.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { AtlasToolBase } from "./atlasTool.js";
import { ToolArgs } from "../tool.js";
import { ToolArgs, OperationType } from "../tool.js";

const DEFAULT_COMMENT = "Added by Atlas MCP";

export class CreateAccessListTool extends AtlasToolBase {
protected name = "atlas-create-access-list";
protected description = "Allow Ip/CIDR ranges to access your MongoDB Atlas clusters.";
protected operationType: OperationType = "create";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmenezes @blva I've tried to map the atlas tools to operation types, but feel free to suggest more appropriate ones (or we can introduce new types if that'd make sense).

protected argsShape = {
projectId: z.string().describe("Atlas project ID"),
ipAddresses: z
Expand Down
3 changes: 2 additions & 1 deletion src/tools/atlas/createDBUser.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { AtlasToolBase } from "./atlasTool.js";
import { ToolArgs } from "../tool.js";
import { ToolArgs, OperationType } from "../tool.js";
import { CloudDatabaseUser, DatabaseUserRole } from "../../common/atlas/openapi.js";

export class CreateDBUserTool extends AtlasToolBase {
protected name = "atlas-create-db-user";
protected description = "Create an MongoDB Atlas database user";
protected operationType: OperationType = "create";
protected argsShape = {
projectId: z.string().describe("Atlas project ID"),
username: z.string().describe("Username for the new user"),
Expand Down
3 changes: 2 additions & 1 deletion src/tools/atlas/createFreeCluster.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { AtlasToolBase } from "./atlasTool.js";
import { ToolArgs } from "../tool.js";
import { ToolArgs, OperationType } from "../tool.js";
import { ClusterDescription20240805 } from "../../common/atlas/openapi.js";

export class CreateFreeClusterTool extends AtlasToolBase {
protected name = "atlas-create-free-cluster";
protected description = "Create a free MongoDB Atlas cluster";
protected operationType: OperationType = "create";
protected argsShape = {
projectId: z.string().describe("Atlas project ID to create the cluster in"),
name: z.string().describe("Name of the cluster"),
Expand Down
3 changes: 2 additions & 1 deletion src/tools/atlas/inspectAccessList.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { AtlasToolBase } from "./atlasTool.js";
import { ToolArgs } from "../tool.js";
import { ToolArgs, OperationType } from "../tool.js";

export class InspectAccessListTool extends AtlasToolBase {
protected name = "atlas-inspect-access-list";
protected description = "Inspect Ip/CIDR ranges with access to your MongoDB Atlas clusters.";
protected operationType: OperationType = "read";
protected argsShape = {
projectId: z.string().describe("Atlas project ID"),
};
Expand Down
3 changes: 2 additions & 1 deletion src/tools/atlas/inspectCluster.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { AtlasToolBase } from "./atlasTool.js";
import { ToolArgs } from "../tool.js";
import { ToolArgs, OperationType } from "../tool.js";
import { ClusterDescription20240805 } from "../../common/atlas/openapi.js";

export class InspectClusterTool extends AtlasToolBase {
protected name = "atlas-inspect-cluster";
protected description = "Inspect MongoDB Atlas cluster";
protected operationType: OperationType = "read";
protected argsShape = {
projectId: z.string().describe("Atlas project ID"),
clusterName: z.string().describe("Atlas cluster name"),
Expand Down
3 changes: 2 additions & 1 deletion src/tools/atlas/listClusters.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { AtlasToolBase } from "./atlasTool.js";
import { ToolArgs } from "../tool.js";
import { ToolArgs, OperationType } from "../tool.js";
import { PaginatedClusterDescription20240805, PaginatedOrgGroupView, Group } from "../../common/atlas/openapi.js";

export class ListClustersTool extends AtlasToolBase {
protected name = "atlas-list-clusters";
protected description = "List MongoDB Atlas clusters";
protected operationType: OperationType = "read";
protected argsShape = {
projectId: z.string().describe("Atlas project ID to filter clusters").optional(),
};
Expand Down
3 changes: 2 additions & 1 deletion src/tools/atlas/listDBUsers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { AtlasToolBase } from "./atlasTool.js";
import { ToolArgs } from "../tool.js";
import { ToolArgs, OperationType } from "../tool.js";
import { DatabaseUserRole, UserScope } from "../../common/atlas/openapi.js";

export class ListDBUsersTool extends AtlasToolBase {
protected name = "atlas-list-db-users";
protected description = "List MongoDB Atlas database users";
protected operationType: OperationType = "read";
protected argsShape = {
projectId: z.string().describe("Atlas project ID to filter DB users"),
};
Expand Down
2 changes: 2 additions & 0 deletions src/tools/atlas/listProjects.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { AtlasToolBase } from "./atlasTool.js";
import { OperationType } from "../tool.js";

export class ListProjectsTool extends AtlasToolBase {
protected name = "atlas-list-projects";
protected description = "List MongoDB Atlas projects";
protected operationType: OperationType = "read";
protected argsShape = {};

protected async execute(): Promise<CallToolResult> {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/mongodb/create/createIndex.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs } from "../../tool.js";
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs, OperationType } from "../../tool.js";
import { IndexDirection } from "mongodb";

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

protected operationType: DbOperationType = "create";
protected operationType: OperationType = "create";

protected async execute({ database, collection, keys }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
const provider = await this.ensureConnected();
Expand Down
6 changes: 3 additions & 3 deletions src/tools/mongodb/create/insertMany.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs } from "../../tool.js";
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs, OperationType } from "../../tool.js";

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

protected async execute({
database,
Expand Down
6 changes: 3 additions & 3 deletions src/tools/mongodb/create/insertOne.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs } from "../../tool.js";
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs, OperationType } from "../../tool.js";

export class InsertOneTool extends MongoDBToolBase {
protected name = "insert-one";
Expand All @@ -16,7 +16,7 @@ export class InsertOneTool extends MongoDBToolBase {
),
};

protected operationType: DbOperationType = "create";
protected operationType: OperationType = "create";

protected async execute({
database,
Expand Down
6 changes: 3 additions & 3 deletions src/tools/mongodb/delete/deleteMany.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs } from "../../tool.js";
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs, OperationType } from "../../tool.js";

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

protected async execute({
database,
Expand Down
6 changes: 3 additions & 3 deletions src/tools/mongodb/delete/deleteOne.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs } from "../../tool.js";
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs, OperationType } from "../../tool.js";

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

protected async execute({
database,
Expand Down
6 changes: 3 additions & 3 deletions src/tools/mongodb/delete/dropCollection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs } from "../../tool.js";
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs, OperationType } from "../../tool.js";

export class DropCollectionTool extends MongoDBToolBase {
protected name = "drop-collection";
Expand All @@ -9,7 +9,7 @@ export class DropCollectionTool extends MongoDBToolBase {
protected argsShape = {
...DbOperationArgs,
};
protected operationType: DbOperationType = "delete";
protected operationType: OperationType = "delete";

protected async execute({ database, collection }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
const provider = await this.ensureConnected();
Expand Down
6 changes: 3 additions & 3 deletions src/tools/mongodb/delete/dropDatabase.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs } from "../../tool.js";
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs, OperationType } from "../../tool.js";

export class DropDatabaseTool extends MongoDBToolBase {
protected name = "drop-database";
protected description = "Removes the specified database, deleting the associated data files";
protected argsShape = {
database: DbOperationArgs.database,
};
protected operationType: DbOperationType = "delete";
protected operationType: OperationType = "delete";

protected async execute({ database }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
const provider = await this.ensureConnected();
Expand Down
6 changes: 3 additions & 3 deletions src/tools/mongodb/metadata/collectionSchema.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs } from "../../tool.js";
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs, OperationType } from "../../tool.js";
import { parseSchema, SchemaField } from "mongodb-schema";

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

protected operationType: DbOperationType = "metadata";
protected operationType: OperationType = "metadata";

protected async execute({ database, collection }: ToolArgs<typeof DbOperationArgs>): Promise<CallToolResult> {
const provider = await this.ensureConnected();
Expand Down
6 changes: 3 additions & 3 deletions src/tools/mongodb/metadata/collectionStorageSize.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { DbOperationArgs, DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs } from "../../tool.js";
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs, OperationType } from "../../tool.js";

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

protected operationType: DbOperationType = "metadata";
protected operationType: OperationType = "metadata";

protected async execute({ database, collection }: ToolArgs<typeof DbOperationArgs>): Promise<CallToolResult> {
const provider = await this.ensureConnected();
Expand Down
6 changes: 3 additions & 3 deletions src/tools/mongodb/metadata/connect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { DbOperationType, MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs } from "../../tool.js";
import { MongoDBToolBase } from "../mongodbTool.js";
import { ToolArgs, OperationType } from "../../tool.js";
import { ErrorCodes, MongoDBError } from "../../../errors.js";
import config from "../../../config.js";

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

protected operationType: DbOperationType = "metadata";
protected operationType: OperationType = "metadata";

protected async execute({
connectionStringOrClusterName,
Expand Down
Loading
Loading