• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / mongodb-mcp-server / 18373530004

09 Oct 2025 10:34AM UTC coverage: 80.622%. First build
18373530004

Pull #629

github

web-flow
Merge fe93f59d5 into 91c11cc59
Pull Request #629: refactor: Replace z.string with CommonArgs.string

991 of 1357 branches covered (73.03%)

Branch coverage included in aggregate %.

37 of 71 new or added lines in 4 files covered. (52.11%)

4892 of 5940 relevant lines covered (82.36%)

46.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.48
/src/tools/args.ts
1
import { z, type ZodString } from "zod";
3✔
2
import { EJSON } from "bson";
3✔
3

4
const NO_UNICODE_REGEX = /^[\x20-\x7E]*$/;
3✔
5
export const NO_UNICODE_ERROR = "String cannot contain special characters or Unicode symbols";
3✔
6

7
const ALLOWED_USERNAME_CHARACTERS_REGEX = /^[a-zA-Z0-9._-]+$/;
3✔
8
export const ALLOWED_USERNAME_CHARACTERS_ERROR =
3✔
9
    "Username can only contain letters, numbers, dots, hyphens, and underscores";
3✔
10

11
const ALLOWED_REGION_CHARACTERS_REGEX = /^[a-zA-Z0-9_-]+$/;
3✔
12
export const ALLOWED_REGION_CHARACTERS_ERROR = "Region can only contain letters, numbers, hyphens, and underscores";
3✔
13

14
const ALLOWED_CLUSTER_NAME_CHARACTERS_REGEX = /^[a-zA-Z0-9_-]+$/;
3✔
15
export const ALLOWED_CLUSTER_NAME_CHARACTERS_ERROR =
3✔
16
    "Cluster names can only contain ASCII letters, numbers, and hyphens.";
3✔
17

18
const ALLOWED_PROJECT_NAME_CHARACTERS_REGEX = /^[a-zA-Z0-9\s()@&+:._',-]+$/;
3✔
19
export const ALLOWED_PROJECT_NAME_CHARACTERS_ERROR =
3✔
20
    "Project names can't be longer than 64 characters and can only contain letters, numbers, spaces, and the following symbols: ( ) @ & + : . _ - ' ,";
3✔
21
export const CommonArgs = {
3✔
22
    string: (): ZodString => z.string().regex(NO_UNICODE_REGEX, NO_UNICODE_ERROR),
3✔
23

24
    objectId: (fieldName: string): z.ZodString =>
3✔
NEW
25
        z
×
NEW
26
            .string()
×
NEW
27
            .min(1, `${fieldName} is required`)
×
NEW
28
            .length(24, `${fieldName} must be exactly 24 characters`)
×
NEW
29
            .regex(/^[0-9a-fA-F]+$/, `${fieldName} must contain only hexadecimal characters`),
×
30
};
3✔
31

32
export const AtlasArgs = {
3✔
33
    projectId: (): z.ZodString => CommonArgs.objectId("projectId"),
3✔
34

35
    organizationId: (): z.ZodString => CommonArgs.objectId("organizationId"),
3✔
36

37
    clusterName: (): z.ZodString =>
3✔
NEW
38
        z
×
NEW
39
            .string()
×
NEW
40
            .min(1, "Cluster name is required")
×
NEW
41
            .max(64, "Cluster name must be 64 characters or less")
×
NEW
42
            .regex(ALLOWED_CLUSTER_NAME_CHARACTERS_REGEX, ALLOWED_CLUSTER_NAME_CHARACTERS_ERROR),
×
43

44
    projectName: (): z.ZodString =>
3✔
NEW
45
        z
×
NEW
46
            .string()
×
NEW
47
            .min(1, "Project name is required")
×
NEW
48
            .max(64, "Project name must be 64 characters or less")
×
NEW
49
            .regex(ALLOWED_PROJECT_NAME_CHARACTERS_REGEX, ALLOWED_PROJECT_NAME_CHARACTERS_ERROR),
×
50

51
    username: (): z.ZodString =>
3✔
NEW
52
        z
×
NEW
53
            .string()
×
NEW
54
            .min(1, "Username is required")
×
NEW
55
            .max(100, "Username must be 100 characters or less")
×
NEW
56
            .regex(ALLOWED_USERNAME_CHARACTERS_REGEX, ALLOWED_USERNAME_CHARACTERS_ERROR),
×
57

58
    ipAddress: (): z.ZodString => z.string().ip({ version: "v4" }),
3✔
59

60
    cidrBlock: (): z.ZodString => z.string().cidr(),
3✔
61

62
    region: (): z.ZodString =>
3✔
NEW
63
        z
×
NEW
64
            .string()
×
NEW
65
            .min(1, "Region is required")
×
NEW
66
            .max(50, "Region must be 50 characters or less")
×
NEW
67
            .regex(ALLOWED_REGION_CHARACTERS_REGEX, ALLOWED_REGION_CHARACTERS_ERROR),
×
68

69
    password: (): z.ZodString =>
3✔
NEW
70
        z.string().min(1, "Password is required").max(100, "Password must be 100 characters or less"),
×
71
};
3✔
72

NEW
73
function toEJSON<T extends object | undefined>(value: T): T {
×
NEW
74
    if (!value) {
×
NEW
75
        return value;
×
NEW
76
    }
×
77

NEW
78
    return EJSON.deserialize(value, { relaxed: false }) as T;
×
NEW
79
}
×
80

81
export function zEJSON(): z.AnyZodObject {
3✔
NEW
82
    return z.object({}).passthrough().transform(toEJSON) as unknown as z.AnyZodObject;
×
NEW
83
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc