Skip to content

Commit 7848be5

Browse files
committed
wip
1 parent e5b2307 commit 7848be5

File tree

8 files changed

+19
-31
lines changed

8 files changed

+19
-31
lines changed

src/tools/args.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const CommonArgs = {
2929
};
3030

3131
export const AtlasArgs = {
32-
projectId: (): z.ZodString => CommonArgs.objectId("projectId"),
32+
projectId: (): z.ZodString => CommonArgs.objectId("projectId").describe("Atlas project ID"),
3333

3434
organizationId: (): z.ZodString => CommonArgs.objectId("organizationId"),
3535

@@ -68,3 +68,12 @@ export const AtlasArgs = {
6868
password: (): z.ZodString =>
6969
z.string().min(1, "Password is required").max(100, "Password must be 100 characters or less"),
7070
};
71+
72+
export const ProjectAndClusterArgs = {
73+
projectId: AtlasArgs.projectId(),
74+
clusterName: AtlasArgs.clusterName().describe("Atlas cluster name"),
75+
};
76+
77+
export const ProjectArgs = {
78+
projectId: AtlasArgs.projectId(),
79+
};

src/tools/atlas/connect/connectCluster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function sleep(ms: number): Promise<void> {
2020
}
2121

2222
export const ConnectClusterArgs = {
23-
projectId: AtlasArgs.projectId().describe("Atlas project ID"),
23+
projectId: AtlasArgs.projectId(),
2424
clusterName: AtlasArgs.clusterName().describe("Atlas cluster name"),
2525
};
2626

src/tools/atlas/create/createAccessList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { type OperationType, type ToolArgs } from "../../tool.js";
33
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
44
import { AtlasToolBase } from "../atlasTool.js";
55
import { makeCurrentIpAccessListEntry, DEFAULT_ACCESS_LIST_COMMENT } from "../../../common/atlas/accessListUtils.js";
6-
import { AtlasArgs, CommonArgs } from "../../args.js";
6+
import { AtlasArgs, CommonArgs, ProjectArgs } from "../../args.js";
77

88
export const CreateAccessListArgs = {
9-
projectId: AtlasArgs.projectId().describe("Atlas project ID"),
9+
...ProjectArgs,
1010
ipAddresses: z.array(AtlasArgs.ipAddress()).describe("IP addresses to allow access from").optional(),
1111
cidrBlocks: z.array(AtlasArgs.cidrBlock()).describe("CIDR blocks to allow access from").optional(),
1212
currentIpAddress: z.boolean().describe("Add the current IP address").default(false),

src/tools/atlas/create/createDBUser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ensureCurrentIpInAccessList } from "../../../common/atlas/accessListUti
88
import { AtlasArgs, CommonArgs } from "../../args.js";
99

1010
export const CreateDBUserArgs = {
11-
projectId: AtlasArgs.projectId().describe("Atlas project ID"),
11+
projectId: AtlasArgs.projectId(),
1212
username: AtlasArgs.username().describe("Username for the new user"),
1313
// Models will generate overly simplistic passwords like SecurePassword123 or
1414
// AtlasPassword123, which are easily guessable and exploitable. We're instructing
@@ -26,7 +26,7 @@ export const CreateDBUserArgs = {
2626
collectionName: CommonArgs.string().describe("Collection name").optional(),
2727
})
2828
)
29-
.describe("Roles for the new user"),
29+
.describe("Roles for the new database user"),
3030
clusters: z
3131
.array(AtlasArgs.clusterName())
3232
.describe("Clusters to assign the user to, leave empty for access to all clusters")
@@ -35,7 +35,7 @@ export const CreateDBUserArgs = {
3535

3636
export class CreateDBUserTool extends AtlasToolBase {
3737
public name = "atlas-create-db-user";
38-
protected description = "Create an MongoDB Atlas database user";
38+
protected description = "Create a MongoDB Atlas database user";
3939
public operationType: OperationType = "create";
4040
protected argsShape = {
4141
...CreateDBUserArgs,

src/tools/atlas/read/inspectAccessList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AtlasToolBase } from "../atlasTool.js";
44
import { AtlasArgs } from "../../args.js";
55

66
export const InspectAccessListArgs = {
7-
projectId: AtlasArgs.projectId().describe("Atlas project ID"),
7+
projectId: AtlasArgs.projectId(),
88
};
99

1010
export class InspectAccessListTool extends AtlasToolBase {

src/tools/atlas/read/inspectCluster.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@ import { type OperationType, type ToolArgs, formatUntrustedData } from "../../to
33
import { AtlasToolBase } from "../atlasTool.js";
44
import type { Cluster } from "../../../common/atlas/cluster.js";
55
import { inspectCluster } from "../../../common/atlas/cluster.js";
6-
import { AtlasArgs } from "../../args.js";
7-
8-
export const InspectClusterArgs = {
9-
projectId: AtlasArgs.projectId().describe("Atlas project ID"),
10-
clusterName: AtlasArgs.clusterName().describe("Atlas cluster name"),
11-
};
6+
import { ProjectAndClusterArgs } from "../../args.js";
127

138
export class InspectClusterTool extends AtlasToolBase {
149
public name = "atlas-inspect-cluster";
1510
protected description = "Inspect MongoDB Atlas cluster";
1611
public operationType: OperationType = "read";
1712
protected argsShape = {
18-
...InspectClusterArgs,
13+
...ProjectAndClusterArgs,
1914
};
2015

2116
protected async execute({ projectId, clusterName }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {

tests/integration/helpers.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,6 @@ export const createClusterParameters: ParameterInfo[] = [
247247
{ name: "region", type: "string", description: "Region of the cluster", required: false },
248248
];
249249

250-
export const createDbUserParameters: ParameterInfo[] = [
251-
{
252-
name: "projectId",
253-
type: "string",
254-
description: "Atlas project ID to create the database user in",
255-
required: true,
256-
},
257-
{ name: "username", type: "string", description: "Username of the database user", required: true },
258-
{ name: "password", type: "string", description: "Password of the database user", required: false },
259-
{ name: "roles", type: "array", description: "Roles of the database user", required: true },
260-
{ name: "scopes", type: "array", description: "Scopes of the database user", required: false },
261-
];
262-
263250
export const databaseCollectionInvalidArgs = [
264251
{},
265252
{ database: "test" },

tests/integration/tools/atlas/dbUsers.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ import {
44
getResponseElements,
55
projectIdInvalidArgs,
66
validateThrowsForInvalidArguments,
7-
validateToolMetadata,
8-
createDbUserParameters,
97
} from "../../helpers.js";
108
import { ApiClientError } from "../../../../src/common/atlas/apiClientError.js";
119
import { afterEach, beforeEach, describe, expect, it } from "vitest";
1210
import { Keychain } from "../../../../src/common/keychain.js";
1311

1412
describeWithAtlas("db users", (integration) => {
1513
describe("should have correct metadata and validate invalid arguments", () => {
16-
validateToolMetadata(integration, "atlas-create-db-user", "Create a database user", createDbUserParameters);
1714
validateThrowsForInvalidArguments(integration, "atlas-create-db-user", projectIdInvalidArgs);
1815
});
1916

0 commit comments

Comments
 (0)