Repository navigation
fix(client): forward listTools/listPrompts/listResources when not connected - #3198
Muzaqil555 wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: 7405500 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
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 |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
|
Thanks for picking this up. Going through The The client package doesn't depend on Two smaller points:
With the tests off the server package and a changeset, the fix itself looks right to me. |
|
Thanks @prkomb for the detailed review! Addressed all three points in commit
Verified locally after final edit: |
|
Checked One wording point in the changeset. When the server closes the connection, |
|
Updated .changeset/list-not-connected-rejects.md\ per your note to clarify the before-\connect()/after-\close()\ vs. server-side-disconnect behavior and drop the overly broad comparison to all other \Client\ request methods. |
Summary
Fixes #3195.
Previously,
Client.listPrompts,Client.listResources,Client.listResourceTemplates, andClient.listToolsinpackages/client/src/client/client.tschecked!this._serverCapabilities?.prompts/.resources/.tools(and checkedthis.responseCacheStore) before verifyingthis.transport. Whenconnect()had not been called or afterclose()clearedthis.transport,_serverCapabilitiesis undefined, causing those methods to resolve to empty lists ({ tools: [] }, etc.) instead of rejecting withError('Not connected').Changes
packages/client/src/client/client.ts: Added an earlyif (!this.transport)check inlistPrompts,listResources,listResourceTemplates, andlistToolsthat delegates tothis.request(...)(which rejects withNot connected) ahead of capability short-circuits and response caching.packages/client/test/client/listNotConnected.test.ts: Added 4 regression tests covering disconnected calls beforeconnect(), afterclose(), connected calls when capabilities omit those features (preserving empty-list behavior), and disconnected calls with a configuredInMemoryResponseCacheStore.test/e2e/requirements.ts: Removed'typescript:protocol:error:not-connected'fromknownFailures.Testing
pnpm --filter @modelcontextprotocol/client run typecheck— passedpnpm --filter @modelcontextprotocol/client run lint— passedpnpm --filter @modelcontextprotocol/client run build— passedpnpm --filter @modelcontextprotocol/client run test— 45 test files passed (45), 1082 tests passed (1082)test/e2e:pnpm exec vitest run scenarios/protocol.test.ts -t "typescript:protocol:error:not-connected"— 12 passed | 396 skipped (408)pnpm exec prettier --checkon all 3 touched files — passed