File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -250,7 +250,7 @@ export class DiskLogger extends LoggerBase<{ initialized: [] }> {
250
250
}
251
251
252
252
export class McpLogger extends LoggerBase {
253
- private static readonly LOG_LEVELS : LogLevel [ ] = [
253
+ public static readonly LOG_LEVELS : LogLevel [ ] = [
254
254
"debug" ,
255
255
"info" ,
256
256
"notice" ,
@@ -259,7 +259,7 @@ export class McpLogger extends LoggerBase {
259
259
"critical" ,
260
260
"alert" ,
261
261
"emergency" ,
262
- ] ;
262
+ ] as const ;
263
263
264
264
public constructor ( private readonly server : Server ) {
265
265
super ( ) ;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { AtlasTools } from "./tools/atlas/tools.js";
5
5
import { MongoDbTools } from "./tools/mongodb/tools.js" ;
6
6
import { Resources } from "./resources/resources.js" ;
7
7
import type { LogLevel } from "./common/logger.js" ;
8
- import { LogId } from "./common/logger.js" ;
8
+ import { LogId , McpLogger } from "./common/logger.js" ;
9
9
import type { Telemetry } from "./telemetry/telemetry.js" ;
10
10
import type { UserConfig } from "./common/config.js" ;
11
11
import { type ServerEvent } from "./telemetry/types.js" ;
@@ -107,6 +107,10 @@ export class Server {
107
107
} ) ;
108
108
109
109
this . mcpServer . server . setRequestHandler ( SetLevelRequestSchema , ( { params } ) => {
110
+ if ( ! McpLogger . LOG_LEVELS . includes ( params . level ) ) {
111
+ throw new Error ( `Invalid log level: ${ params . level } ` ) ;
112
+ }
113
+
110
114
this . _mcpLogLevel = params . level ;
111
115
return { } ;
112
116
} ) ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import * as path from "path";
7
7
import * as fs from "fs/promises" ;
8
8
import { once } from "events" ;
9
9
import type { Server } from "../../src/server.js" ;
10
+ import { LoggingMessageNotificationSchema } from "@modelcontextprotocol/sdk/types.js" ;
10
11
11
12
describe ( "Logger" , ( ) => {
12
13
let consoleErrorSpy : MockInstance < typeof console . error > ;
@@ -332,5 +333,9 @@ describe("Logger", () => {
332
333
expect ( mcpLoggerSpy ) . toHaveBeenCalledTimes ( 2 ) ;
333
334
expect ( getLastMcpLogMessage ( ) ) . toContain ( "Alert message" ) ;
334
335
} ) ;
336
+
337
+ it ( "MCPLogger.LOG_LEVELS contains all possible levels" , ( ) => {
338
+ expect ( McpLogger . LOG_LEVELS ) . toEqual ( LoggingMessageNotificationSchema . shape . params . shape . level . options ) ;
339
+ } ) ;
335
340
} ) ;
336
341
} ) ;
You can’t perform that action at this time.
0 commit comments