Fix automatic log level handling for sessionless connections (#917)
This commit is contained in:
parent
5dd7a2b700
commit
ebf39330f3
1 changed files with 158 additions and 6 deletions
|
|
@ -117,7 +117,7 @@ export class Server<
|
|||
const transportSessionId: string | undefined = extra.sessionId || extra.requestInfo?.headers['mcp-session-id'] as string || undefined;
|
||||
const { level } = request.params;
|
||||
const parseResult = LoggingLevelSchema.safeParse(level);
|
||||
if (transportSessionId && parseResult.success) {
|
||||
if (parseResult.success) {
|
||||
this._loggingLevels.set(transportSessionId, parseResult.data);
|
||||
}
|
||||
return {};
|
||||
|
|
@ -126,7 +126,7 @@ export class Server<
|
|||
}
|
||||
|
||||
// Map log levels by session id
|
||||
private _loggingLevels = new Map<string, LoggingLevel>();
|
||||
private _loggingLevels = new Map<string | undefined, LoggingLevel>();
|
||||
|
||||
// Map LogLevelSchema to severity index
|
||||
private readonly LOG_LEVEL_SEVERITY = new Map(
|
||||
|
|
@ -134,7 +134,7 @@ export class Server<
|
|||
);
|
||||
|
||||
// Is a message with the given level ignored in the log level set for the given session id?
|
||||
private isMessageIgnored = (level: LoggingLevel, sessionId: string): boolean => {
|
||||
private isMessageIgnored = (level: LoggingLevel, sessionId?: string): boolean => {
|
||||
const currentLevel = this._loggingLevels.get(sessionId);
|
||||
return (currentLevel)
|
||||
? this.LOG_LEVEL_SEVERITY.get(level)! < this.LOG_LEVEL_SEVERITY.get(currentLevel)!
|
||||
|
|
@ -398,7 +398,7 @@ export class Server<
|
|||
*/
|
||||
async sendLoggingMessage(params: LoggingMessageNotification["params"], sessionId?: string) {
|
||||
if (this._capabilities.logging) {
|
||||
if (!sessionId || !this.isMessageIgnored(params.level, sessionId)) {
|
||||
if (!this.isMessageIgnored(params.level, sessionId)) {
|
||||
return this.notification({method: "notifications/message", params})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue