Skip to content

Commit a9cd645

Browse files
fix(server): normalize per-request clientCapabilities before the elicitation/sampling capability gate
1 parent 44d1f8a commit a9cd645

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

packages/server/src/server/server.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import type {
3636
import {
3737
CallToolRequestSchema,
3838
CallToolResultSchema,
39+
ClientCapabilitiesSchema,
3940
CreateMessageResultSchema,
4041
CreateMessageResultWithToolsSchema,
4142
ElicitResultSchema,
@@ -144,7 +145,13 @@ export class Server extends Protocol<ServerContext> {
144145
const sendOpts = (options?: RequestOptions): RequestOptions => ({ ...options, relatedRequestId: ctx.mcpReq.id });
145146
// SEP-2575: prefer per-request peer scope (lifted from `_meta` by S4) over the
146147
// singleton handshake state. Falls back to the singleton for the connect() path.
147-
const reqCaps = ctx.mcpReq.clientCapabilities ?? this._clientCapabilities;
148+
// Normalize the per-request value: it may arrive raw from a transport adapter
149+
// (e.g. SessionCompat stores `initialize.params.capabilities` off the wire), and
150+
// ElicitationCapabilitySchema's preprocess (e.g. `{}` -> `{form:{}}`) must run
151+
// before the `_elicitInputVia` capability gate reads `caps.elicitation.form`.
152+
const rawReqCaps = ctx.mcpReq.clientCapabilities;
153+
const reqCaps =
154+
rawReqCaps === undefined ? this._clientCapabilities : (ClientCapabilitiesSchema.safeParse(rawReqCaps).data ?? rawReqCaps);
148155
const reqLogLevel = ctx.mcpReq.logLevel;
149156
return {
150157
...ctx,

0 commit comments

Comments
 (0)