-
Notifications
You must be signed in to change notification settings - Fork 96
fix: remove global logger MCP-103 #425
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.
[nit] Not blocking at all, but maybe it would be worth to have the logger at the session level because we have access to the session from almost everywhere?
8f8defd
to
cb0d498
Compare
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 refactors the logging system to eliminate the global logger pattern in favor of session-scoped loggers. The changes create a composite logger system where each session has its own logger instance that includes transport-specific and MCP-specific loggers as needed.
Key changes:
- Replaced global logger singleton with session-scoped loggers that are passed down to all components
- Added session ID attributes to loggers for better traceability
- Enhanced logger system with attributes support and buffering for disk logger initialization
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/common/logger.ts | Enhanced logger classes with attributes support, added DiskLogger buffering, and NullLogger for testing |
src/transports/base.ts | Added logger creation logic to transport runners and session setup |
src/transports/streamableHttp.ts | Updated to use instance logger instead of global logger |
src/transports/stdio.ts | Updated to use instance logger instead of global logger |
src/common/session.ts | Modified to accept and use a logger instance |
src/common/sessionStore.ts | Updated to store logger per session instead of creating MCP loggers |
src/server.ts | Removed global logger setup, now uses session logger |
src/index.ts | Updated to use transport runner logger with fallback console logger |
tests/unit/telemetry.test.ts | Updated tests to use session logger and NullLogger |
tests/unit/logger.test.ts | Added comprehensive tests for new logger functionality |
tests/integration/helpers.ts | Added logger to session setup in tests |
tests/unit/accessListUtils.test.ts | Added logger to mock API client |
Pull Request Test Coverage Report for Build 16790782045Details
💛 - Coveralls |
Co-authored-by: Copilot <[email protected]>
Proposed changes
This refactoring removes the global logger and instead creates a session-scoped logger for each session, which is then used by the whole server machinery. Additionally, we add a session id attribute once the session is bound to ensure that is included in the log messages.
The way this works is we create a composite logger that includes all configured loggers for the transport manager. Then as we create sessions, for each session we create a new composite logger that includes the transport logger and the MCP logger (if configured). Then all tools and api clients will use the session logger.
Checklist