Skip to content

fix: registerCapabilities registers logging/setLevel handler#1605

Open
giulio-leone wants to merge 2 commits intomodelcontextprotocol:mainfrom
giulio-leone:fix/register-capabilities-logging-handler
Open

fix: registerCapabilities registers logging/setLevel handler#1605
giulio-leone wants to merge 2 commits intomodelcontextprotocol:mainfrom
giulio-leone:fix/register-capabilities-logging-handler

Conversation

@giulio-leone
Copy link

Problem

When logging capability is added via registerCapabilities() instead of the constructor options, the logging/setLevel request handler is not registered. This causes clients to receive a 'Method not found' error when calling setLoggingLevel().

// This works ✅
let a = new Server({}, { capabilities: { logging: {} } });

// This doesn't ✅ → ❌
let b = new Server();
b.registerCapabilities({ logging: {} });
// b has no logging/setLevel handler

Root Cause

The logging/setLevel handler is only registered in the constructor when this._capabilities.logging is truthy. When registerCapabilities() is called later to add logging, it only merges capabilities but doesn't register the handler.

Fix

Extract the logging handler setup into a private _registerLoggingHandler() method and call it from both:

  1. The constructor (when logging is in initial capabilities)
  2. registerCapabilities() (when logging capability is added after construction, and wasn't there before)

Tests

Two new integration tests:

  • registerCapabilities should register logging/setLevel handler: Creates a Server without logging, adds it via registerCapabilities, then verifies the client can successfully call setLoggingLevel
  • logging in constructor capabilities should register logging/setLevel handler: Verifies the existing constructor path still works

All 86 server integration tests pass (2 consecutive clean runs).

Fixes #1464

@giulio-leone giulio-leone requested a review from a team as a code owner February 28, 2026 07:21
@changeset-bot
Copy link

changeset-bot bot commented Feb 28, 2026

⚠️ No Changeset found

Latest commit: 5a16f75

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 28, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1605

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1605

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1605

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1605

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1605

commit: 2de4c27

When logging capability is added via registerCapabilities() instead of
the constructor options, the logging/setLevel request handler was not
being registered. This caused clients to receive 'Method not found'
errors when calling setLoggingLevel.

Extract the logging handler setup into a private _registerLoggingHandler
method and call it from both the constructor (when logging is in initial
capabilities) and registerCapabilities (when logging is added later).

Fixes modelcontextprotocol#1464
@giulio-leone giulio-leone force-pushed the fix/register-capabilities-logging-handler branch from 2f06c63 to a809754 Compare February 28, 2026 14:41
@giulio-leone
Copy link
Author

Friendly ping — CI is green and this is ready for review. Happy to address any feedback. Thanks!

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.

The registerCapabilities has no effect on logging/setLevel

1 participant