-
Notifications
You must be signed in to change notification settings - Fork 131
fix: handle setLogLevel requests #486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements handling for MCP setLogLevel requests to dynamically control logging output. The changes address issues where the server could not respond to log level changes from MCP clients.
Key changes:
- Added log level filtering in McpLogger based on server's configured minimum level
- Implemented setLogLevel request handler in the Server class
- Restructured logger initialization to create McpLogger after Server instantiation
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/server.ts | Added setLogLevel request handler and mcpLogLevel property management |
src/common/logger.ts | Implemented log level filtering in McpLogger and updated constructor |
src/transports/base.ts | Moved McpLogger creation after Server instantiation to fix dependency |
tests/unit/logger.test.ts | Added test coverage for log level filtering functionality |
package.json | Updated @modelcontextprotocol/inspector dependency version |
.github/workflows/check.yml | Updated inspector version in CI workflow |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
const minimumLevel = McpLogger.LOG_LEVELS.indexOf(this.server.mcpLogLevel); | ||
const currentLevel = McpLogger.LOG_LEVELS.indexOf(level); | ||
if (minimumLevel > currentLevel) { |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comparison logic is inverted. If minimumLevel > currentLevel, it means the current level is actually lower priority than the minimum. The condition should be minimumLevel > currentLevel
to filter out lower priority levels, but the comment says 'Don't log if the requested level is lower than the minimum level' which suggests the opposite logic. Please verify the intended behavior matches the LOG_LEVELS array ordering.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong as the copilot suggestion is wrong or the code itself?
const minimumLevel = McpLogger.LOG_LEVELS.indexOf(this.server.mcpLogLevel); | ||
const currentLevel = McpLogger.LOG_LEVELS.indexOf(level); |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No validation for invalid log levels. If this.server.mcpLogLevel
or level
contains an invalid value not in LOG_LEVELS, indexOf() will return -1, leading to incorrect filtering behavior. Add validation to handle invalid log levels gracefully.
const minimumLevel = McpLogger.LOG_LEVELS.indexOf(this.server.mcpLogLevel); | |
const currentLevel = McpLogger.LOG_LEVELS.indexOf(level); | |
const currentLevel = McpLogger.LOG_LEVELS.indexOf(level); | |
if (minimumLevel === -1) { | |
// Invalid minimum log level configured; skip logging and optionally warn | |
console.warn(`[McpLogger] Invalid minimum log level: ${this.server.mcpLogLevel}`); | |
return; | |
} | |
if (currentLevel === -1) { | |
// Invalid log level requested; skip logging and optionally warn | |
console.warn(`[McpLogger] Invalid log level: ${level}`); | |
return; | |
} |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a valid one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The core logic looks good! The copilot suggestion, might be something to look into.
const minimumLevel = McpLogger.LOG_LEVELS.indexOf(this.server.mcpLogLevel); | ||
const currentLevel = McpLogger.LOG_LEVELS.indexOf(level); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a valid one.
const minimumLevel = McpLogger.LOG_LEVELS.indexOf(this.server.mcpLogLevel); | ||
const currentLevel = McpLogger.LOG_LEVELS.indexOf(level); | ||
if (minimumLevel > currentLevel) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong!
Proposed changes
fixes #485
fixes #454