Skip to content

Commit c6ba47b

Browse files
nirinchevCopilot
andauthored
chore: better connect tool guidance with Atlas MCP-48 (#349)
Co-authored-by: Copilot <[email protected]>
1 parent c40eeab commit c6ba47b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+182
-94
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ The MongoDB MCP Server can be configured using multiple methods, with the follow
285285
| `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. |
286286
| `logPath` | Folder to store logs. |
287287
| `disabledTools` | An array of tool names, operation types, and/or categories of tools that will be disabled. |
288-
| `readOnly` | When set to true, only allows read and metadata operation types, disabling create/update/delete operations. |
288+
| `readOnly` | When set to true, only allows read, connect, and metadata operation types, disabling create/update/delete operations. |
289289
| `indexCheck` | When set to true, enforces that query operations must use an index, rejecting queries that perform a collection scan. |
290290
| `telemetry` | When set to disabled, disables telemetry collection. |
291291

@@ -318,10 +318,11 @@ Operation types:
318318
- `delete` - Tools that delete resources, such as delete document, drop collection, etc.
319319
- `read` - Tools that read resources, such as find, aggregate, list clusters, etc.
320320
- `metadata` - Tools that read metadata, such as list databases, list collections, collection schema, etc.
321+
- `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.
321322

322323
#### Read-Only Mode
323324

324-
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.
325+
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.
325326

326327
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.
327328

src/server.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { type ServerCommand } from "./telemetry/types.js";
1212
import { CallToolRequestSchema, CallToolResult } from "@modelcontextprotocol/sdk/types.js";
1313
import assert from "assert";
1414
import { detectContainerEnv } from "./common/container.js";
15+
import { ToolBase } from "./tools/tool.js";
1516

1617
export interface ServerOptions {
1718
session: Session;
@@ -22,9 +23,10 @@ export interface ServerOptions {
2223

2324
export class Server {
2425
public readonly session: Session;
25-
private readonly mcpServer: McpServer;
26+
public readonly mcpServer: McpServer;
2627
private readonly telemetry: Telemetry;
2728
public readonly userConfig: UserConfig;
29+
public readonly tools: ToolBase[] = [];
2830
private readonly startTime: number;
2931

3032
constructor({ session, mcpServer, userConfig, telemetry }: ServerOptions) {
@@ -141,8 +143,11 @@ export class Server {
141143
}
142144

143145
private registerTools() {
144-
for (const tool of [...AtlasTools, ...MongoDbTools]) {
145-
new tool(this.session, this.userConfig, this.telemetry).register(this.mcpServer);
146+
for (const toolConstructor of [...AtlasTools, ...MongoDbTools]) {
147+
const tool = new toolConstructor(this.session, this.userConfig, this.telemetry);
148+
if (tool.register(this)) {
149+
this.tools.push(tool);
150+
}
146151
}
147152
}
148153

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/metadata/connectCluster.ts renamed to src/tools/atlas/connect/connectCluster.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ function sleep(ms: number): Promise<void> {
1313
}
1414

1515
export class ConnectClusterTool extends AtlasToolBase {
16-
protected name = "atlas-connect-cluster";
16+
public name = "atlas-connect-cluster";
1717
protected description = "Connect to MongoDB Atlas cluster";
18-
protected operationType: OperationType = "metadata";
18+
public operationType: OperationType = "connect";
1919
protected argsShape = {
2020
projectId: z.string().describe("Atlas project ID"),
2121
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)