Skip to content

Commit 2d00859

Browse files
committed
reuse args
1 parent b12b4b1 commit 2d00859

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

src/tools/args.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const ALLOWED_CLUSTER_NAME_CHARACTERS_ERROR =
1818
const ALLOWED_PROJECT_NAME_CHARACTERS_REGEX = /^[a-zA-Z0-9\s()@&+:._',-]+$/;
1919
export const ALLOWED_PROJECT_NAME_CHARACTERS_ERROR =
2020
"Project names can't be longer than 64 characters and can only contain letters, numbers, spaces, and the following symbols: ( ) @ & + : . _ - ' ,";
21+
2122
export const CommonArgs = {
2223
string: (): ZodString => z.string().regex(NO_UNICODE_REGEX, NO_UNICODE_ERROR),
2324

@@ -70,14 +71,15 @@ export const AtlasArgs = {
7071
z.string().min(1, "Password is required").max(100, "Password must be 100 characters or less"),
7172
};
7273

73-
export const ProjectAndClusterArgs = {
74+
export const ProjectArgs = {
7475
projectId: AtlasArgs.projectId(),
75-
clusterName: AtlasArgs.clusterName().describe("Atlas cluster name"),
7676
};
7777

78-
export const ProjectArgs = {
79-
projectId: AtlasArgs.projectId(),
78+
export const ProjectAndClusterArgs = {
79+
...ProjectArgs,
80+
clusterName: AtlasArgs.clusterName().describe("Atlas cluster name"),
8081
};
82+
8183
function toEJSON<T extends object | undefined>(value: T): T {
8284
if (!value) {
8385
return value;
@@ -89,11 +91,3 @@ function toEJSON<T extends object | undefined>(value: T): T {
8991
export function zEJSON(): z.AnyZodObject {
9092
return z.object({}).passthrough().transform(toEJSON) as unknown as z.AnyZodObject;
9193
}
92-
export const ProjectAndClusterArgs = {
93-
projectId: AtlasArgs.projectId(),
94-
clusterName: AtlasArgs.clusterName().describe("Atlas cluster name"),
95-
};
96-
97-
export const ProjectArgs = {
98-
projectId: AtlasArgs.projectId(),
99-
};

src/tools/atlas/connect/connectCluster.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { inspectCluster } from "../../../common/atlas/cluster.js";
77
import { ensureCurrentIpInAccessList } from "../../../common/atlas/accessListUtils.js";
88
import type { AtlasClusterConnectionInfo } from "../../../common/connectionManager.js";
99
import { getDefaultRoleFromConfig } from "../../../common/atlas/roles.js";
10-
import { AtlasArgs } from "../../args.js";
10+
import { ProjectAndClusterArgs } from "../../args.js";
1111

1212
const addedIpAccessListMessage =
1313
"Note: Your current IP address has been added to the Atlas project's IP access list to enable secure connection.";
@@ -20,8 +20,7 @@ function sleep(ms: number): Promise<void> {
2020
}
2121

2222
export const ConnectClusterArgs = {
23-
projectId: AtlasArgs.projectId(),
24-
clusterName: AtlasArgs.clusterName().describe("Atlas cluster name"),
23+
...ProjectAndClusterArgs,
2524
};
2625

2726
export class ConnectClusterTool extends AtlasToolBase {

src/tools/atlas/create/createFreeCluster.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@ import { type ToolArgs, type OperationType } from "../../tool.js";
33
import { AtlasToolBase } from "../atlasTool.js";
44
import type { ClusterDescription20240805 } from "../../../common/atlas/openapi.js";
55
import { ensureCurrentIpInAccessList } from "../../../common/atlas/accessListUtils.js";
6-
import { AtlasArgs } from "../../args.js";
6+
import { ProjectAndClusterArgs, AtlasArgs } from "../../args.js";
77

88
export class CreateFreeClusterTool extends AtlasToolBase {
99
public name = "atlas-create-free-cluster";
1010
protected description = "Create a free MongoDB Atlas cluster";
1111
public operationType: OperationType = "create";
1212
protected argsShape = {
13-
projectId: AtlasArgs.projectId().describe("Atlas project ID to create the cluster in"),
14-
name: AtlasArgs.clusterName().describe("Name of the cluster"),
13+
...ProjectAndClusterArgs,
1514
region: AtlasArgs.region().describe("Region of the cluster").default("US_EAST_1"),
1615
};
1716

18-
protected async execute({ projectId, name, region }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
17+
protected async execute({
18+
projectId,
19+
clusterName,
20+
region,
21+
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
1922
const input = {
2023
groupId: projectId,
21-
name,
24+
clusterName,
2225
clusterType: "REPLICASET",
2326
replicationSpecs: [
2427
{
@@ -50,7 +53,7 @@ export class CreateFreeClusterTool extends AtlasToolBase {
5053

5154
return {
5255
content: [
53-
{ type: "text", text: `Cluster "${name}" has been created in region "${region}".` },
56+
{ type: "text", text: `Cluster "${clusterName}" has been created in region "${region}".` },
5457
{ type: "text", text: `Double check your access lists to enable your current IP.` },
5558
],
5659
};

0 commit comments

Comments
 (0)