Skip to content

Commit 3a5d4c1

Browse files
committed
reformat
1 parent 1850676 commit 3a5d4c1

File tree

7 files changed

+41
-52
lines changed

7 files changed

+41
-52
lines changed

src/common/atlas/apiClient.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ export class ApiClient {
9696
}
9797

9898
public hasCredentials(): boolean {
99-
logger.info(mongoLogId(1_000_000), "api-client", `Checking if API client has credentials: ${!!(this.oauth2Client && this.accessToken)}`);
99+
logger.info(
100+
mongoLogId(1_000_000),
101+
"api-client",
102+
`Checking if API client has credentials: ${!!(this.oauth2Client && this.accessToken)}`
103+
);
100104
return !!(this.oauth2Client && this.accessToken);
101105
}
102106

src/config.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface UserConfig {
1111
apiBaseUrl?: string;
1212
apiClientId?: string;
1313
apiClientSecret?: string;
14-
telemetry?: 'enabled' | 'disabled';
14+
telemetry?: "enabled" | "disabled";
1515
logPath: string;
1616
connectionString?: string;
1717
connectOptions: {
@@ -40,21 +40,20 @@ const mergedUserConfig = {
4040
...getCliConfig(),
4141
};
4242

43-
4443
const machineMetadata = {
4544
device_id: "id", // TODO: use @mongodb-js/machine-id
4645
platform: process.platform,
4746
arch: process.arch,
4847
os_type: process.platform,
4948
os_version: process.version,
50-
}
49+
};
5150

5251
const config = {
5352
...mergedUserConfig,
5453
...machineMetadata,
5554
version: packageJson.version,
5655
mcpServerName: "MdbMcpServer",
57-
isTelemetryEnabled: true
56+
isTelemetryEnabled: true,
5857
};
5958

6059
export default config;

src/index.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import config from "./config.js";
88
import { Session } from "./session.js";
99
import { Server } from "./server.js";
1010

11-
1211
async function main() {
1312
const session = new Session();
1413
const mcpServer = new McpServer({
@@ -30,10 +29,6 @@ async function main() {
3029
try {
3130
await main();
3231
} catch (error: unknown) {
33-
logger.emergency(
34-
mongoLogId(1_000_004),
35-
"server",
36-
`Fatal error running server: ${error as string}`
37-
);
32+
logger.emergency(mongoLogId(1_000_004), "server", `Fatal error running server: ${error as string}`);
3833
process.exit(1);
3934
}

src/server.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { MongoDbTools } from "./tools/mongodb/tools.js";
66
import logger, { initializeLogger } from "./logger.js";
77
import { mongoLogId } from "mongodb-log-writer";
88

9-
109
export class Server {
1110
public readonly session: Session;
1211
private readonly mcpServer: McpServer;
@@ -24,7 +23,7 @@ export class Server {
2423

2524
await this.mcpServer.connect(transport);
2625

27-
this.mcpServer.server.oninitialized = () => {
26+
this.mcpServer.server.oninitialized = () => {
2827
this.session.setAgentClientData(this.mcpServer.server.getClientVersion());
2928
logger.info(mongoLogId(1_000_004), "server", `Server started with transport ${transport.constructor.name}`);
3029
};

src/session.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class Session {
88
serviceProvider?: NodeDriverServiceProvider;
99
apiClient: ApiClient;
1010
agentClientName?: string;
11-
agentClientVersion?: string;
11+
agentClientVersion?: string;
1212

1313
constructor() {
1414
// Initialize API client with credentials if available
@@ -26,14 +26,14 @@ export class Session {
2626
// Initialize API client without credentials
2727
this.apiClient = new ApiClient({ baseUrl: config.apiBaseUrl });
2828
}
29-
29+
3030
setAgentClientData(agentClient: Implementation | undefined) {
3131
this.agentClientName = agentClient?.name;
3232
this.agentClientVersion = agentClient?.version;
3333
}
3434

3535
ensureAuthenticated(): asserts this is { apiClient: ApiClient } {
36-
if (!this.apiClient || !(this.apiClient.hasCredentials())) {
36+
if (!this.apiClient || !this.apiClient.hasCredentials()) {
3737
if (!config.apiClientId || !config.apiClientSecret) {
3838
throw new Error(
3939
"Not authenticated make sure to configure MCP server with MDB_MCP_API_CLIENT_ID and MDB_MCP_API_CLIENT_SECRET environment variables."

src/telemetry/telemetry.ts

+24-32
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { Session } from '../session.js';
2-
import { BaseEvent, type ToolEvent } from './types.js';
3-
import pkg from '../../package.json' with { type: 'json' };
4-
import config from '../config.js';
5-
import logger from '../logger.js';
6-
import { mongoLogId } from 'mongodb-log-writer';
7-
import { ApiClient } from '../common/atlas/apiClient.js';
8-
import fs from 'fs/promises';
9-
import path from 'path';
10-
11-
const TELEMETRY_ENABLED = config.telemetry !== 'disabled';
12-
const CACHE_FILE = path.join(process.cwd(), '.telemetry-cache.json');
1+
import { Session } from "../session.js";
2+
import { BaseEvent, type ToolEvent } from "./types.js";
3+
import pkg from "../../package.json" with { type: "json" };
4+
import config from "../config.js";
5+
import logger from "../logger.js";
6+
import { mongoLogId } from "mongodb-log-writer";
7+
import { ApiClient } from "../common/atlas/apiClient.js";
8+
import fs from "fs/promises";
9+
import path from "path";
10+
11+
const TELEMETRY_ENABLED = config.telemetry !== "disabled";
12+
const CACHE_FILE = path.join(process.cwd(), ".telemetry-cache.json");
1313

1414
interface TelemetryError extends Error {
1515
code?: string;
@@ -63,7 +63,7 @@ export class Telemetry {
6363
command: string,
6464
category: string,
6565
startTime: number,
66-
result: 'success' | 'failure',
66+
result: "success" | "failure",
6767
error?: Error
6868
): Promise<void> {
6969
if (!TELEMETRY_ENABLED) {
@@ -82,14 +82,14 @@ export class Telemetry {
8282
command: string,
8383
category: string,
8484
startTime: number,
85-
result: 'success' | 'failure',
85+
result: "success" | "failure",
8686
error?: Error
8787
): ToolEvent {
8888
const duration = Date.now() - startTime;
8989

9090
const event: ToolEvent = {
9191
timestamp: new Date().toISOString(),
92-
source: 'mdbmcp',
92+
source: "mdbmcp",
9393
properties: {
9494
...this.commonProperties,
9595
command,
@@ -99,9 +99,9 @@ export class Telemetry {
9999
result,
100100
...(error && {
101101
error_type: error.name,
102-
error_code: error.message
103-
})
104-
}
102+
error_code: error.message,
103+
}),
104+
},
105105
};
106106

107107
return event;
@@ -127,11 +127,7 @@ export class Telemetry {
127127
return;
128128
}
129129

130-
logger.warning(
131-
mongoLogId(1_000_000),
132-
"telemetry",
133-
`Error sending event to client: ${result.error}`
134-
);
130+
logger.warning(mongoLogId(1_000_000), "telemetry", `Error sending event to client: ${result.error}`);
135131
await this.cacheEvents(allEvents);
136132
}
137133

@@ -145,7 +141,7 @@ export class Telemetry {
145141
} catch (error) {
146142
return {
147143
success: false,
148-
error: error instanceof Error ? error : new Error(String(error))
144+
error: error instanceof Error ? error : new Error(String(error)),
149145
};
150146
}
151147
}
@@ -156,11 +152,11 @@ export class Telemetry {
156152
*/
157153
private async readCache(): Promise<BaseEvent[]> {
158154
try {
159-
const data = await fs.readFile(CACHE_FILE, 'utf-8');
155+
const data = await fs.readFile(CACHE_FILE, "utf-8");
160156
return JSON.parse(data) as BaseEvent[];
161157
} catch (error) {
162158
const typedError = error as TelemetryError;
163-
if (typedError.code !== 'ENOENT') {
159+
if (typedError.code !== "ENOENT") {
164160
logger.warning(
165161
mongoLogId(1_000_000),
166162
"telemetry",
@@ -177,11 +173,7 @@ export class Telemetry {
177173
private async cacheEvents(events: BaseEvent[]): Promise<void> {
178174
try {
179175
await fs.writeFile(CACHE_FILE, JSON.stringify(events, null, 2));
180-
logger.debug(
181-
mongoLogId(1_000_000),
182-
"telemetry",
183-
`Cached ${events.length} events for later sending`
184-
);
176+
logger.debug(mongoLogId(1_000_000), "telemetry", `Cached ${events.length} events for later sending`);
185177
} catch (error) {
186178
logger.warning(
187179
mongoLogId(1_000_000),
@@ -199,7 +191,7 @@ export class Telemetry {
199191
await fs.unlink(CACHE_FILE);
200192
} catch (error) {
201193
const typedError = error as TelemetryError;
202-
if (typedError.code !== 'ENOENT') {
194+
if (typedError.code !== "ENOENT") {
203195
logger.warning(
204196
mongoLogId(1_000_000),
205197
"telemetry",

src/telemetry/types.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
export interface Event {
55
timestamp: string;
6-
source: 'mdbmcp';
6+
source: "mdbmcp";
77
properties: Record<string, unknown>;
88
}
99

@@ -19,7 +19,7 @@ export interface BaseEvent extends Event {
1919
os_type: string;
2020
os_version?: string;
2121
session_id?: string;
22-
} & Event['properties'];
22+
} & Event["properties"];
2323
}
2424

2525
/**
@@ -30,12 +30,12 @@ export interface ToolEvent extends BaseEvent {
3030
command: string;
3131
category: string;
3232
duration_ms: number;
33-
result: 'success' | 'failure';
33+
result: "success" | "failure";
3434
error_code?: string;
3535
error_type?: string;
3636
project_id?: string;
3737
org_id?: string;
3838
cluster_name?: string;
3939
is_atlas?: boolean;
40-
} & BaseEvent['properties'];
40+
} & BaseEvent["properties"];
4141
}

0 commit comments

Comments
 (0)