Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-capability-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@modelcontextprotocol/sdk": patch
---

fix: throw SdkError for unsupported capabilities in assertCapability()
2 changes: 1 addition & 1 deletion packages/client/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ export class Client extends Protocol<ClientContext> {

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})`);
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/integration/test/client/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});

/***
Expand Down
Loading