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

mongodb-js / mongodb-mcp-server / 19701495156

26 Nov 2025 11:03AM UTC coverage: 79.824% (-0.1%) from 79.969%
19701495156

Pull #760

github

web-flow
Merge 7806a08a9 into cfb965b7a
Pull Request #760: chore: rename vectorSearch feature flag to search

1339 of 1770 branches covered (75.65%)

Branch coverage included in aggregate %.

13 of 14 new or added lines in 10 files covered. (92.86%)

16 existing lines in 1 file now uncovered.

6368 of 7885 relevant lines covered (80.76%)

68.18 hits per line

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

70.21
/src/common/config/configUtils.ts
1
import path from "path";
3✔
2
import os from "os";
3✔
3
import { ALL_CONFIG_KEYS } from "./argsParserOptions.js";
3✔
4
import * as levenshteinModule from "ts-levenshtein";
3✔
5
const levenshtein = levenshteinModule.default;
3✔
6

7
/**
8
 * Metadata for config schema fields.
9
 */
10
export type ConfigFieldMeta = {
11
    /**
12
     * Custom description for the default value, used when generating documentation.
13
     */
14
    defaultValueDescription?: string;
15
    /**
16
     * Marks the field as containing sensitive/secret information, used for MCP Registry.
17
     * Secret fields will be marked as secret in environment variable definitions.
18
     */
19
    isSecret?: boolean;
20

21
    [key: string]: unknown;
22
};
23

24
export function matchingConfigKey(key: string): string | undefined {
3✔
25
    let minLev = Number.MAX_VALUE;
3✔
26
    let suggestion = undefined;
3✔
27
    for (const validKey of ALL_CONFIG_KEYS) {
3✔
28
        const lev = levenshtein.get(key, validKey);
231✔
29
        // Accepting upto 2 typos and should be better than whatever previous
30
        // suggestion was.
31
        if (lev <= 2 && lev < minLev) {
231✔
32
            minLev = lev;
2✔
33
            suggestion = validKey;
2✔
34
        }
2✔
35
    }
231✔
36

37
    return suggestion;
3✔
38
}
3✔
39

40
export function isConnectionSpecifier(arg: string | undefined): boolean {
3✔
41
    return (
13✔
42
        arg !== undefined &&
13✔
43
        (arg.startsWith("mongodb://") ||
13✔
44
            arg.startsWith("mongodb+srv://") ||
9✔
45
            // Strings starting with double hyphens `--` are generally a sign of
46
            // CLI flag so we exclude them from the possibility of being a
47
            // connection specifier.
48
            !(arg.endsWith(".js") || arg.endsWith(".mongodb") || arg.startsWith("--")))
9✔
49
    );
50
}
13✔
51

52
export function getLocalDataPath(): string {
3✔
53
    return process.platform === "win32"
106!
54
        ? path.join(process.env.LOCALAPPDATA || process.env.APPDATA || os.homedir(), "mongodb")
×
55
        : path.join(os.homedir(), ".mongodb");
106✔
56
}
106✔
57

58
export function getLogPath(): string {
3✔
59
    const logPath = path.join(getLocalDataPath(), "mongodb-mcp", ".app-logs");
53✔
60
    return logPath;
53✔
61
}
53✔
62

63
export function getExportsPath(): string {
3✔
64
    return path.join(getLocalDataPath(), "mongodb-mcp", "exports");
53✔
65
}
53✔
66

67
export function commaSeparatedToArray<T extends string[]>(str: string | string[] | undefined): T | undefined {
3✔
68
    if (str === undefined) {
11!
69
        return undefined;
×
70
    }
×
71

72
    if (typeof str === "string") {
11!
73
        return str
×
74
            .split(",")
×
UNCOV
75
            .map((e) => e.trim())
×
UNCOV
76
            .filter((e) => e.length > 0) as T;
×
UNCOV
77
    }
×
78

79
    if (str.length === 1) {
11✔
80
        return str[0]
11✔
81
            ?.split(",")
11✔
82
            .map((e) => e.trim())
11✔
83
            .filter((e) => e.length > 0) as T;
11✔
84
    }
11!
85

UNCOV
86
    return str as T;
×
UNCOV
87
}
×
88

89
/**
90
 * Preprocessor for boolean values that handles string "false"/"0" correctly.
91
 * Zod's coerce.boolean() treats any non-empty string as true, which is not what we want.
92
 */
93
export function parseBoolean(val: unknown): unknown {
3✔
94
    if (typeof val === "string") {
22!
UNCOV
95
        const lower = val.toLowerCase().trim();
×
UNCOV
96
        if (lower === "false") {
×
UNCOV
97
            return false;
×
UNCOV
98
        }
×
UNCOV
99
        return true;
×
UNCOV
100
    }
×
101
    if (typeof val === "boolean") {
22✔
102
        return val;
22✔
103
    }
22!
UNCOV
104
    if (typeof val === "number") {
×
UNCOV
105
        return val !== 0;
×
UNCOV
106
    }
×
UNCOV
107
    return !!val;
×
UNCOV
108
}
×
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

© 2025 Coveralls, Inc