Skip to content

Conversation

cliffhall
Copy link
Member

@cliffhall cliffhall commented Sep 3, 2025

Description

  • In src/server/index.ts

    • in Server class
      • in automatic request handler for SetLevelRequestSchema set in constructor, use "NO_SESSION" as the transportSessionId / map key for _loggingLevels and set the level.
      • This allows an STDIO server to have automatic log filtering if sendLoggingMessage is used.
      • in isMessageIgnored method
        • default value of sessionId is "NO_SESSION" if not supplied
      • in sendLoggingMessage method, - remove sessionId check from condition, since an undefined sessionId will be converted to "NO_SESSION" in the call to isMessageIgnored - this allows STDIO servers to have automatic log filtering
  • In src/server/index.test.ts

    • added tests
      • "should respect log level for transport without sessionId"
      • "should respect log level for transport with sessionId"
  • In .gitignore

    • add .idea/ for JetBrains IDEs

Motivation and Context

While refactoring the Everything server to demonstrate how servers can avail themselves of the SDK's recent addition of Automatic handling of logging level, I discovered a wrinkle that needs ironing out.

STDIO server connections (which do not have a sessionId) would no longer throw a "Method not found" error if they advertised logging but did not set a listener for SetLevelRequestSchema messages, which is good. However, they would not respect the level that was set in subsequent calls to sendLoggingMessage. This is because the log levels are tracked by sessionId, to allow for multiple clients connecting to a server and each setting their own level.

This PR fixes that and tests the entire process, both with and without a sessionId.

How Has This Been Tested?

New unit tests for both cases.

Breaking Changes

Nope.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

  - add .idea/ for JetBrains IDEs
* In src/server/index.ts
  - in Server class
    - in automatic request handler for SetLevelRequestSchema set in constructor, use "NO_SESSION" as the transportSessionId / map key for _loggingLevels and set the level.
    - This allows an STDIO server to have automatic log filtering if sendLoggingMessage is used.
    - in isMessageIgnored method
      - default value of sessionId is "NO_SESSION" if not supplied
    - in sendLoggingMessage method,
      - remove sessionId check from condition, since an undefined sessionId will be converted to "NO_SESSION" in the call to isMessageIgnored
      - this allows STDIO servers to have automatic log filtering

* In src/server/index.test.ts
  - added tests
    - "should respect log level for transport without sessionId"
    - "should respect log level for transport with sessionId"
@cliffhall cliffhall requested a review from a team as a code owner September 3, 2025 22:10
  - adjust imports to minimize diff impact
  - remove unused import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant