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: [] }> {
250250}
251251
252252export class McpLogger extends LoggerBase {
253- private static readonly LOG_LEVELS : LogLevel [ ] = [
253+ public static readonly LOG_LEVELS : LogLevel [ ] = [
254254 "debug" ,
255255 "info" ,
256256 "notice" ,
@@ -259,7 +259,7 @@ export class McpLogger extends LoggerBase {
259259 "critical" ,
260260 "alert" ,
261261 "emergency" ,
262- ] ;
262+ ] as const ;
263263
264264 public constructor ( private readonly server : Server ) {
265265 super ( ) ;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { AtlasTools } from "./tools/atlas/tools.js";
55import { MongoDbTools } from "./tools/mongodb/tools.js" ;
66import { Resources } from "./resources/resources.js" ;
77import type { LogLevel } from "./common/logger.js" ;
8- import { LogId } from "./common/logger.js" ;
8+ import { LogId , McpLogger } from "./common/logger.js" ;
99import type { Telemetry } from "./telemetry/telemetry.js" ;
1010import type { UserConfig } from "./common/config.js" ;
1111import { type ServerEvent } from "./telemetry/types.js" ;
@@ -107,6 +107,10 @@ export class Server {
107107 } ) ;
108108
109109 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+
110114 this . _mcpLogLevel = params . level ;
111115 return { } ;
112116 } ) ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import * as path from "path";
77import * as fs from "fs/promises" ;
88import { once } from "events" ;
99import type { Server } from "../../src/server.js" ;
10+ import { LoggingMessageNotificationSchema } from "@modelcontextprotocol/sdk/types.js" ;
1011
1112describe ( "Logger" , ( ) => {
1213 let consoleErrorSpy : MockInstance < typeof console . error > ;
@@ -332,5 +333,9 @@ describe("Logger", () => {
332333 expect ( mcpLoggerSpy ) . toHaveBeenCalledTimes ( 2 ) ;
333334 expect ( getLastMcpLogMessage ( ) ) . toContain ( "Alert message" ) ;
334335 } ) ;
336+
337+ it ( "MCPLogger.LOG_LEVELS contains all possible levels" , ( ) => {
338+ expect ( McpLogger . LOG_LEVELS ) . toEqual ( LoggingMessageNotificationSchema . shape . params . shape . level . options ) ;
339+ } ) ;
335340 } ) ;
336341} ) ;
You can’t perform that action at this time.
0 commit comments