Address review: justify/refine SDK-gap casts (as unknown as)

Per human review on #1688: for each `as unknown as` in the PR, either refactor
or justify with a comment naming the SDK gap (so it can inform SDK-side type
improvements).

- Sampling/elicit receiver-task returns: route through a typed `CreateTaskResult`
  so the object shape IS checked; the remaining cast to CreateMessageResult /
  ElicitResult is the honest SDK gap (the 2-arg setRequestHandler overload types
  the handler return as the spec result only, not the task-augmented variant).
- `_requestHandlers` / `_progressHandlers` private-field casts: comments now name
  the exact missing public API (opt a handler out of result validation; keep a
  progress subscription alive across a resolved request).
- test-server `_requestHandlers` cast: same SDK gap on the server side, noted.
- serverList object->Record casts (pre-existing): documented as plain structural
  widening (no index signature -> TS requires the `unknown` step), not an SDK
  workaround.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
cliffhall 2026-07-15 14:47:10 -04:00
commit dbb8c40245

View file

@ -1215,6 +1215,12 @@ function wireTaskHandlers(
taskTools: Map<string, TaskToolDefinition>,
): void {
const lowLevel = mcpServer.server;
// SDK gap (server side): `Server` exposes no public API to override an already
// registered handler or to send a `tools/call` response that bypasses its
// result-schema validation, so we reach the private `_requestHandlers` map via
// a narrowed cast (`RawHandlerHost`). Mirrors the client-side bypass in
// `core/mcp/inspectorClient.ts`; both go away when the SDK models task-augmented
// results natively.
const registry = (lowLevel as unknown as RawHandlerHost)._requestHandlers;
const sdkToolsCall = registry.get("tools/call");
// Map each created task back to the tool that owns it, so tasks/get and