From 490293c28c54bca4e3a2a613e6aa49a96497ed62 Mon Sep 17 00:00:00 2001 From: kai-agent-free Date: Fri, 13 Mar 2026 10:31:52 +0000 Subject: [PATCH 1/2] fix: throw SdkError with CapabilityNotSupported code instead of generic 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 #430 --- packages/client/src/client/client.ts | 2 +- test/integration/test/client/client.test.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/client/src/client/client.ts b/packages/client/src/client/client.ts index edb08ee58..df9e703b1 100644 --- a/packages/client/src/client/client.ts +++ b/packages/client/src/client/client.ts @@ -434,7 +434,7 @@ export class Client extends Protocol { protected assertCapability(capability: keyof ServerCapabilities, method: string): void { if (!this._serverCapabilities?.[capability]) { - throw new Error(`Server does not support ${capability} (required for ${method})`); + throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support ${capability} (required for ${method})`); } } diff --git a/test/integration/test/client/client.test.ts b/test/integration/test/client/client.test.ts index 948d16e17..cfc4d180b 100644 --- a/test/integration/test/client/client.test.ts +++ b/test/integration/test/client/client.test.ts @@ -418,6 +418,12 @@ test('should respect server capabilities', async () => { argument: { name: 'test', value: 'test' } }) ).rejects.toThrow('Server does not support completions'); + + // Verify that unsupported capability errors are SdkError with CapabilityNotSupported code + await expect(client.listPrompts()).rejects.toThrow(SdkError); + await expect(client.listPrompts()).rejects.toMatchObject({ + code: SdkErrorCode.CapabilityNotSupported + }); }); /*** From 95e2a9626876428b6b0011a5a907c492f567caff Mon Sep 17 00:00:00 2001 From: kai-agent-free Date: Fri, 13 Mar 2026 16:28:37 +0000 Subject: [PATCH 2/2] Add changeset for capability error fix --- .changeset/fix-capability-error.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fix-capability-error.md diff --git a/.changeset/fix-capability-error.md b/.changeset/fix-capability-error.md new file mode 100644 index 000000000..48db14a66 --- /dev/null +++ b/.changeset/fix-capability-error.md @@ -0,0 +1,5 @@ +--- +"@modelcontextprotocol/sdk": patch +--- + +fix: throw SdkError for unsupported capabilities in assertCapability()