Skip to content

fix: throw SdkError for unsupported capabilities in assertCapability()#1676

Open
kai-agent-free wants to merge 2 commits intomodelcontextprotocol:mainfrom
kai-agent-free:fix/capability-unsupported-error
Open

fix: throw SdkError for unsupported capabilities in assertCapability()#1676
kai-agent-free wants to merge 2 commits intomodelcontextprotocol:mainfrom
kai-agent-free:fix/capability-unsupported-error

Conversation

@kai-agent-free
Copy link

Summary

Fixes #430

The assertCapability() method in Client was throwing a generic Error when a server doesn't support a required capability. This made it impossible for callers to programmatically distinguish unsupported-capability errors from other failures without fragile message-string matching.

Changes

  • packages/client/src/client/client.ts: Replace throw new Error(...) with throw new SdkError(SdkErrorCode.CapabilityNotSupported, ...) in assertCapability(). This is consistent with assertCapabilityForMethod() which already uses SdkError with the same error code.

  • test/integration/test/client/client.test.ts: Add assertions verifying that the thrown error is an instance of SdkError with code: SdkErrorCode.CapabilityNotSupported.

Usage

Callers can now catch unsupported capability errors programmatically:

try {
  await client.listPrompts();
} catch (error) {
  if (error instanceof SdkError && error.code === SdkErrorCode.CapabilityNotSupported) {
    // Handle unsupported capability gracefully
  }
}

All 386 tests pass.

…ic Error

Replace the generic `throw new Error()` in `assertCapability()` with
`throw new SdkError(SdkErrorCode.CapabilityNotSupported, ...)` so that
callers can programmatically distinguish unsupported-capability errors
from other failures without fragile message-string matching.

Fixes modelcontextprotocol#430
@kai-agent-free kai-agent-free requested a review from a team as a code owner March 13, 2026 10:32
@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2026

🦋 Changeset detected

Latest commit: 95e2a96

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 13, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: a4c8eb7

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.

Client class should throw a custom exception if the capability is unsupported

1 participant