Skip to content

Commit 7682f5c

Browse files
committed
update read tools
1 parent b89637f commit 7682f5c

File tree

7 files changed

+33
-23
lines changed

7 files changed

+33
-23
lines changed

src/tools/atlas/read/inspectAccessList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { z } from "zod";
21
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
32
import { AtlasToolBase } from "../atlasTool.js";
43
import type { ToolArgs, OperationType } from "../../tool.js";
54
import { formatUntrustedData } from "../../tool.js";
5+
import { AtlasArgs } from "../validators.js";
66

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

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

src/tools/atlas/read/inspectCluster.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import type { ToolArgs, OperationType } from "../../tool.js";
55
import { formatUntrustedData } from "../../tool.js";
66
import type { Cluster } from "../../../common/atlas/cluster.js";
77
import { inspectCluster } from "../../../common/atlas/cluster.js";
8+
import { AtlasArgs } from "../validators.js";
89

910
export class InspectClusterTool extends AtlasToolBase {
1011
public name = "atlas-inspect-cluster";
1112
protected description = "Inspect MongoDB Atlas cluster";
1213
public operationType: OperationType = "read";
1314
protected argsShape = {
14-
projectId: z.string().describe("Atlas project ID"),
15+
projectId: AtlasArgs.projectId().describe("Atlas project ID"),
1516
clusterName: z.string().describe("Atlas cluster name"),
1617
};
1718

src/tools/atlas/read/listAlerts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { z } from "zod";
21
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
32
import { AtlasToolBase } from "../atlasTool.js";
43
import type { ToolArgs, OperationType } from "../../tool.js";
54
import { formatUntrustedData } from "../../tool.js";
5+
import { AtlasArgs } from "../validators.js";
66

77
export class ListAlertsTool extends AtlasToolBase {
88
public name = "atlas-list-alerts";
99
protected description = "List MongoDB Atlas alerts";
1010
public operationType: OperationType = "read";
1111
protected argsShape = {
12-
projectId: z.string().describe("Atlas project ID to list alerts for"),
12+
projectId: AtlasArgs.projectId().describe("Atlas project ID to list alerts for"),
1313
};
1414

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

src/tools/atlas/read/listClusters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { z } from "zod";
21
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
32
import { AtlasToolBase } from "../atlasTool.js";
43
import type { ToolArgs, OperationType } from "../../tool.js";
@@ -10,13 +9,14 @@ import type {
109
PaginatedFlexClusters20241113,
1110
} from "../../../common/atlas/openapi.js";
1211
import { formatCluster, formatFlexCluster } from "../../../common/atlas/cluster.js";
12+
import { AtlasArgs } from "../validators.js";
1313

1414
export class ListClustersTool extends AtlasToolBase {
1515
public name = "atlas-list-clusters";
1616
protected description = "List MongoDB Atlas clusters";
1717
public operationType: OperationType = "read";
1818
protected argsShape = {
19-
projectId: z.string().describe("Atlas project ID to filter clusters").optional(),
19+
projectId: AtlasArgs.projectId().describe("Atlas project ID to filter clusters").optional(),
2020
};
2121

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

src/tools/atlas/read/listDBUsers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { z } from "zod";
21
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
32
import { AtlasToolBase } from "../atlasTool.js";
43
import type { ToolArgs, OperationType } from "../../tool.js";
54
import { formatUntrustedData } from "../../tool.js";
65
import type { DatabaseUserRole, UserScope } from "../../../common/atlas/openapi.js";
6+
import { AtlasArgs } from "../validators.js";
77

88
export class ListDBUsersTool extends AtlasToolBase {
99
public name = "atlas-list-db-users";
1010
protected description = "List MongoDB Atlas database users";
1111
public operationType: OperationType = "read";
1212
protected argsShape = {
13-
projectId: z.string().describe("Atlas project ID to filter DB users"),
13+
projectId: AtlasArgs.projectId().describe("Atlas project ID to filter DB users"),
1414
};
1515

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

src/tools/atlas/read/listProjects.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
22
import { AtlasToolBase } from "../atlasTool.js";
33
import type { OperationType } from "../../tool.js";
44
import { formatUntrustedData } from "../../tool.js";
5-
import { z } from "zod";
65
import type { ToolArgs } from "../../tool.js";
6+
import { AtlasArgs } from "../validators.js";
77

88
export class ListProjectsTool extends AtlasToolBase {
99
public name = "atlas-list-projects";
1010
protected description = "List MongoDB Atlas projects";
1111
public operationType: OperationType = "read";
1212
protected argsShape = {
13-
orgId: z.string().describe("Atlas organization ID to filter projects").optional(),
13+
orgId: AtlasArgs.organizationId().describe("Atlas organization ID to filter projects").optional(),
1414
};
1515

1616
protected async execute({ orgId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {

src/tools/atlas/validators.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
1-
import { z } from "zod";
1+
import { z, type ZodString } from "zod";
2+
3+
export const ToolArgs = {
4+
string: (): ZodString =>
5+
z.string().regex(/^[\x20-\x7E]*$/, "String cannot contain special characters or Unicode symbols"),
6+
};
7+
28
/**
39
* Common Zod validators for Atlas tools
410
* These can be reused across different Atlas tools for consistent validation
511
*/
612
export const AtlasArgs = {
713
objectId: (fieldName: string): z.ZodString =>
8-
z
9-
.string()
14+
ToolArgs.string()
1015
.min(1, `${fieldName} is required`)
1116
.regex(/^[0-9a-fA-F]{24}$/, `${fieldName} must be a valid 24-character hexadecimal string`),
1217

13-
projectId: (): z.ZodString => AtlasArgs.objectId("Project ID"),
18+
projectId: (): z.ZodString => AtlasArgs.objectId("projectId"),
1419

15-
organizationId: (): z.ZodString => AtlasArgs.objectId("Organization ID"),
20+
organizationId: (): z.ZodString => AtlasArgs.objectId("organizationId"),
1621

1722
clusterName: (): z.ZodString =>
18-
z
19-
.string()
23+
ToolArgs.string()
2024
.min(1, "Cluster name is required")
2125
.max(64, "Cluster name must be 64 characters or less")
2226
.regex(/^[a-zA-Z0-9_-]+$/, "Cluster name can only contain letters, numbers, hyphens, and underscores"),
2327

2428
username: (): z.ZodString =>
25-
z
26-
.string()
29+
ToolArgs.string()
2730
.min(1, "Username is required")
2831
.max(100, "Username must be 100 characters or less")
2932
.regex(/^[a-zA-Z0-9._-]+$/, "Username can only contain letters, numbers, dots, hyphens, and underscores"),
3033

31-
ipAddress: (): z.ZodString => z.string().ip({ version: "v4" }),
34+
ipAddress: (): z.ZodString => ToolArgs.string().ip({ version: "v4" }),
3235

3336
cidrBlock: (): z.ZodString =>
34-
z.string().regex(/^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/, "Must be a valid CIDR block (e.g., 192.168.1.0/24)"),
37+
ToolArgs.string().regex(
38+
/^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/,
39+
"Must be a valid CIDR block (e.g., 192.168.1.0/24)"
40+
),
3541

3642
region: (): z.ZodString =>
37-
z.string().regex(/^[a-zA-Z0-9_-]+$/, "Region can only contain letters, numbers, hyphens, and underscores"),
43+
ToolArgs.string().regex(
44+
/^[a-zA-Z0-9_-]+$/,
45+
"Region can only contain letters, numbers, hyphens, and underscores"
46+
),
3847
};

0 commit comments

Comments
 (0)