Skip to content

Commit 26044c7

Browse files
committed
feat: hide atlas tools when not configured
1 parent 795858a commit 26044c7

File tree

13 files changed

+27
-34
lines changed

13 files changed

+27
-34
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ You may experiment asking `Can you connect to my mongodb instance?`.
107107
- `atlas-list-db-users` - List MongoDB Atlas database users
108108
- `atlas-create-db-user` - List MongoDB Atlas database users
109109

110+
NOTE: atlas tools are only available when you set credentials and do not set connection string on configuration.
111+
110112
#### MongoDB Database Tools
111113

112114
- `connect` - Connect to a MongoDB instance

src/session.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ import config from "./config.js";
44

55
export class Session {
66
serviceProvider?: NodeDriverServiceProvider;
7-
apiClient?: ApiClient;
7+
apiClient: ApiClient;
88

9-
ensureAuthenticated(): asserts this is { apiClient: ApiClient } {
10-
if (!this.apiClient) {
11-
if (!config.apiClientId || !config.apiClientSecret) {
12-
throw new Error(
13-
"Not authenticated make sure to configure MCP server with MDB_MCP_API_CLIENT_ID and MDB_MCP_API_CLIENT_SECRET environment variables."
14-
);
15-
}
16-
17-
this.apiClient = new ApiClient({
18-
baseUrl: config.apiBaseUrl,
19-
credentials: {
20-
clientId: config.apiClientId,
21-
clientSecret: config.apiClientSecret,
22-
},
23-
});
9+
constructor() {
10+
let credentials: {
11+
clientId: string;
12+
clientSecret: string;
13+
} | undefined = undefined;
14+
if (config.apiClientId && config.apiClientSecret) {
15+
credentials = {
16+
clientId: config.apiClientId,
17+
clientSecret: config.apiClientSecret,
18+
};
2419
}
20+
21+
this.apiClient = new ApiClient({
22+
baseUrl: config.apiBaseUrl,
23+
credentials,
24+
});
2525
}
2626

2727
async close(): Promise<void> {

src/tools/atlas/atlasTool.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import { ToolBase, ToolCategory } from "../tool.js";
22
import { Session } from "../../session.js";
3+
import config from "../../config.js";
34

45
export abstract class AtlasToolBase extends ToolBase {
56
constructor(protected readonly session: Session) {
67
super(session);
78
}
89

910
protected category: ToolCategory = "atlas";
11+
12+
protected verifyAllowed(): boolean {
13+
if (config.connectionString || !config.apiClientId || !config.apiClientSecret) {
14+
return false;
15+
}
16+
return super.verifyAllowed();
17+
}
1018
}

src/tools/atlas/createAccessList.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export class CreateAccessListTool extends AtlasToolBase {
2727
comment,
2828
currentIpAddress,
2929
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
30-
this.session.ensureAuthenticated();
31-
3230
if (!ipAddresses?.length && !cidrBlocks?.length && !currentIpAddress) {
3331
throw new Error("One of ipAddresses, cidrBlocks, currentIpAddress must be provided.");
3432
}

src/tools/atlas/createDBUser.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export class CreateDBUserTool extends AtlasToolBase {
3434
roles,
3535
clusters,
3636
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
37-
this.session.ensureAuthenticated();
38-
3937
const input = {
4038
groupId: projectId,
4139
awsIAMType: "NONE",

src/tools/atlas/createFreeCluster.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export class CreateFreeClusterTool extends AtlasToolBase {
1515
};
1616

1717
protected async execute({ projectId, name, region }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
18-
this.session.ensureAuthenticated();
19-
2018
const input = {
2119
groupId: projectId,
2220
name,

src/tools/atlas/createProject.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export class CreateProjectTool extends AtlasToolBase {
1414
};
1515

1616
protected async execute({ projectName, organizationId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
17-
this.session.ensureAuthenticated();
1817
let assumedOrg = false;
1918

2019
if (!projectName) {

src/tools/atlas/inspectAccessList.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export class InspectAccessListTool extends AtlasToolBase {
1212
};
1313

1414
protected async execute({ projectId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
15-
this.session.ensureAuthenticated();
16-
1715
const accessList = await this.session.apiClient.listProjectIpAccessLists({
1816
params: {
1917
path: {

src/tools/atlas/inspectCluster.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ export class InspectClusterTool extends AtlasToolBase {
1414
};
1515

1616
protected async execute({ projectId, clusterName }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
17-
this.session.ensureAuthenticated();
18-
1917
const cluster = await this.session.apiClient.getCluster({
2018
params: {
2119
path: {

src/tools/atlas/listClusters.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ export class ListClustersTool extends AtlasToolBase {
1313
};
1414

1515
protected async execute({ projectId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
16-
this.session.ensureAuthenticated();
17-
1816
if (!projectId) {
1917
const data = await this.session.apiClient.listClustersForAllProjects();
2018

0 commit comments

Comments
 (0)