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

mongodb-js / mongodb-mcp-server / 17155288437

22 Aug 2025 12:29PM UTC coverage: 82.014% (-0.03%) from 82.04%
17155288437

Pull #468

github

web-flow
Merge 3bb127c20 into ca68195c4
Pull Request #468: chore: update readme with the new tool and resources

855 of 1075 branches covered (79.53%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 2 files covered. (100.0%)

97 existing lines in 8 files now uncovered.

4357 of 5280 relevant lines covered (82.52%)

70.4 hits per line

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

83.33
/src/helpers/connectionOptions.ts
1
import { MongoClientOptions } from "mongodb";
2
import ConnectionString from "mongodb-connection-string-url";
2✔
3

4
export interface AppNameComponents {
5
    appName: string;
6
    deviceId?: Promise<string>;
7
    clientName?: string;
8
}
9

10
/**
11
 * Sets the appName parameter with the extended format: appName--deviceId--clientName
12
 * Only sets the appName if it's not already present in the connection string
13
 * @param connectionString - The connection string to modify
14
 * @param components - The components to build the appName from
15
 * @returns The modified connection string
16
 */
17
export async function setAppNameParamIfMissing({
447✔
18
    connectionString,
447✔
19
    components,
447✔
20
}: {
447✔
21
    connectionString: string;
22
    components: AppNameComponents;
23
}): Promise<string> {
447✔
24
    const connectionStringUrl = new ConnectionString(connectionString);
447✔
25
    const searchParams = connectionStringUrl.typedSearchParams<MongoClientOptions>();
447✔
26

27
    // Only set appName if it's not already present
28
    if (searchParams.has("appName")) {
447✔
29
        return connectionStringUrl.toString();
8✔
30
    }
8✔
31

32
    const appName = components.appName || "unknown";
447!
33
    const deviceId = components.deviceId ? await components.deviceId : "unknown";
447✔
34
    const clientName = components.clientName || "unknown";
447✔
35

36
    // Build the extended appName format: appName--deviceId--clientName
37
    const extendedAppName = `${appName}--${deviceId}--${clientName}`;
447✔
38

39
    searchParams.set("appName", extendedAppName);
447✔
40

41
    return connectionStringUrl.toString();
447✔
42
}
447✔
43

44
/**
45
 * Validates the connection string
46
 * @param connectionString - The connection string to validate
47
 * @param looseValidation - Whether to allow loose validation
48
 * @returns void
49
 * @throws Error if the connection string is invalid
50
 */
51
export function validateConnectionString(connectionString: string, looseValidation: boolean): void {
2✔
52
    try {
2✔
53
        new ConnectionString(connectionString, { looseValidation });
2✔
54
    } catch (error) {
2!
UNCOV
55
        throw new Error(
×
UNCOV
56
            `Invalid connection string with error: ${error instanceof Error ? error.message : String(error)}`
×
UNCOV
57
        );
×
UNCOV
58
    }
×
59
}
2✔
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