Skip to content

Commit 84e706e

Browse files
committed
chore: improve connect tool guidance when using Atlas
1 parent f7dc230 commit 84e706e

39 files changed

+164
-87
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ The MongoDB MCP Server can be configured using multiple methods, with the follow
268268
| `connectionString` | MongoDB connection string for direct database connections. Optional, if not set, you'll need to call the `connect` tool before interacting with MongoDB data. |
269269
| `logPath` | Folder to store logs. |
270270
| `disabledTools` | An array of tool names, operation types, and/or categories of tools that will be disabled. |
271-
| `readOnly` | When set to true, only allows read and metadata operation types, disabling create/update/delete operations. |
271+
| `readOnly` | When set to true, only allows read, connect, and metadata operation types, disabling create/update/delete operations. |
272272
| `indexCheck` | When set to true, enforces that query operations must use an index, rejecting queries that perform a collection scan. |
273273
| `telemetry` | When set to disabled, disables telemetry collection. |
274274

@@ -301,10 +301,11 @@ Operation types:
301301
- `delete` - Tools that delete resources, such as delete document, drop collection, etc.
302302
- `read` - Tools that read resources, such as find, aggregate, list clusters, etc.
303303
- `metadata` - Tools that read metadata, such as list databases, list collections, collection schema, etc.
304+
- `connect` - Tools that allow you to connect or switch the connection to a MongoDB instance. If this is disabled, you will need to provide a connection string through the config when starting the server.
304305

305306
#### Read-Only Mode
306307

307-
The `readOnly` configuration option allows you to restrict the MCP server to only use tools with "read" and "metadata" operation types. When enabled, all tools that have "create", "update" or "delete" operation types will not be registered with the server.
308+
The `readOnly` configuration option allows you to restrict the MCP server to only use tools with "read", "connect", and "metadata" operation types. When enabled, all tools that have "create", "update" or "delete" operation types will not be registered with the server.
308309

309310
This is useful for scenarios where you want to provide access to MongoDB data for analysis without allowing any modifications to the data or infrastructure.
310311

src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface ServerOptions {
2323

2424
export class Server {
2525
public readonly session: Session;
26-
private readonly mcpServer: McpServer;
26+
public readonly mcpServer: McpServer;
2727
private readonly telemetry: Telemetry;
2828
public readonly userConfig: UserConfig;
2929
public readonly tools: ToolBase[] = [];
@@ -145,7 +145,7 @@ export class Server {
145145
private registerTools() {
146146
for (const toolConstructor of [...AtlasTools, ...MongoDbTools]) {
147147
const tool = new toolConstructor(this.session, this.userConfig, this.telemetry);
148-
if (tool.register(this.mcpServer)) {
148+
if (tool.register(this)) {
149149
this.tools.push(tool);
150150
}
151151
}

src/tools/atlas/atlasTool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { z } from "zod";
66
import { ApiClientError } from "../../common/atlas/apiClientError.js";
77

88
export abstract class AtlasToolBase extends ToolBase {
9-
protected category: ToolCategory = "atlas";
9+
public category: ToolCategory = "atlas";
1010

1111
protected verifyAllowed(): boolean {
1212
if (!this.config.apiClientId || !this.config.apiClientSecret) {
@@ -29,7 +29,7 @@ export abstract class AtlasToolBase extends ToolBase {
2929
type: "text",
3030
text: `Unable to authenticate with MongoDB Atlas, API error: ${error.message}
3131
32-
Hint: Your API credentials may be invalid, expired or lack permissions.
32+
Hint: Your API credentials may be invalid, expired or lack permissions.
3333
Please check your Atlas API credentials and ensure they have the appropriate permissions.
3434
For more information on setting up API keys, visit: https://www.mongodb.com/docs/atlas/configure-api-access/`,
3535
},
@@ -44,7 +44,7 @@ For more information on setting up API keys, visit: https://www.mongodb.com/docs
4444
{
4545
type: "text",
4646
text: `Received a Forbidden API Error: ${error.message}
47-
47+
4848
You don't have sufficient permissions to perform this action in MongoDB Atlas
4949
Please ensure your API key has the necessary roles assigned.
5050
For more information on Atlas API access roles, visit: https://www.mongodb.com/docs/atlas/api/service-accounts-overview/`,

src/tools/atlas/connect/connectCluster.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ const EXPIRY_MS = 1000 * 60 * 60 * 12; // 12 hours
1111
function sleep(ms: number): Promise<void> {
1212
return new Promise((resolve) => setTimeout(resolve, ms));
1313
}
14+
15+
export const name = "atlas-connect-cluster";
16+
1417
export class ConnectClusterTool extends AtlasToolBase {
15-
protected name = "atlas-connect-cluster";
18+
public name = name;
1619
protected description = "Connect to MongoDB Atlas cluster";
17-
protected operationType: OperationType = "metadata";
20+
public operationType: OperationType = "connect";
1821
protected argsShape = {
1922
projectId: z.string().describe("Atlas project ID"),
2023
clusterName: z.string().describe("Atlas cluster name"),

src/tools/atlas/create/createAccessList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { ToolArgs, OperationType } from "../../tool.js";
66
const DEFAULT_COMMENT = "Added by Atlas MCP";
77

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

src/tools/atlas/create/createDBUser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { CloudDatabaseUser, DatabaseUserRole } from "../../../common/atlas/opena
66
import { generateSecurePassword } from "../../../common/atlas/generatePassword.js";
77

88
export class CreateDBUserTool extends AtlasToolBase {
9-
protected name = "atlas-create-db-user";
9+
public name = "atlas-create-db-user";
1010
protected description = "Create an MongoDB Atlas database user";
11-
protected operationType: OperationType = "create";
11+
public operationType: OperationType = "create";
1212
protected argsShape = {
1313
projectId: z.string().describe("Atlas project ID"),
1414
username: z.string().describe("Username for the new user"),

src/tools/atlas/create/createFreeCluster.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { ToolArgs, OperationType } from "../../tool.js";
55
import { ClusterDescription20240805 } from "../../../common/atlas/openapi.js";
66

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

src/tools/atlas/create/createProject.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { ToolArgs, OperationType } from "../../tool.js";
55
import { Group } from "../../../common/atlas/openapi.js";
66

77
export class CreateProjectTool extends AtlasToolBase {
8-
protected name = "atlas-create-project";
8+
public name = "atlas-create-project";
99
protected description = "Create a MongoDB Atlas project";
10-
protected operationType: OperationType = "create";
10+
public operationType: OperationType = "create";
1111
protected argsShape = {
1212
projectName: z.string().optional().describe("Name for the new project"),
1313
organizationId: z.string().optional().describe("Organization ID for the new project"),

src/tools/atlas/read/inspectAccessList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { AtlasToolBase } from "../atlasTool.js";
44
import { ToolArgs, OperationType } from "../../tool.js";
55

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

src/tools/atlas/read/inspectCluster.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { ToolArgs, OperationType } from "../../tool.js";
55
import { Cluster, inspectCluster } from "../../../common/atlas/cluster.js";
66

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

0 commit comments

Comments
 (0)