You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dissolve capabilities.md into server.md and client.md
Sampling and elicitation are now inline sections in `docs/server.md`
under a new "Server-initiated requests" heading, with type-checked code
snippets (`registerTool_sampling`, `registerTool_elicitation` regions in
`serverGuide.examples.ts`). This fixes the asymmetry where logging got
full inline treatment but structurally identical features (sampling,
elicitation) were exiled to table rows pointing at a separate file.
Tasks get subsections in both guides that name the entry-point APIs
(`registerToolTask`, `callToolStream`, `getTask`, `getTaskResult`) and
link to runnable examples, with progressive disclosure through JSDoc.
JSDoc enhancements for task APIs:
- `ToolTaskHandler`: three-phase description moved to field-level docs,
`@see` linking to `registerToolTask`
- `ResponseMessage`, `TaskStatusMessage`, `TaskCreatedMessage`,
`ResultMessage`, `ErrorMessage`: lifecycle semantics and terminal
behaviour documented; `{@linkcode}` cross-references to streaming APIs
- `takeResult`, `toArrayAsync`: added JSDoc
- `InMemoryTaskStore`: `{@inheritdoc TaskStore.*}` on all public methods
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/client.md
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Client
3
3
---
4
4
5
-
##Client overview
5
+
# Client overview
6
6
7
7
This guide covers SDK usage for building MCP clients in TypeScript. For protocol-level details and message formats, see the [MCP specification](https://modelcontextprotocol.io/specification/latest/).
> For a full form‑based elicitation handler with AJV validation, see [`simpleStreamableHttp.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/simpleStreamableHttp.ts). For URL elicitation mode, see [`elicitationUrlExample.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/elicitationUrlExample.ts) and the [Capabilities guide](capabilities.md#elicitation).
321
+
> For a full form‑based elicitation handler with AJV validation, see [`simpleStreamableHttp.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/simpleStreamableHttp.ts). For URL elicitation mode (`mode: 'url'`), see [`elicitationUrlExample.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/elicitationUrlExample.ts).
322
322
>
323
323
> For protocol details, see [Elicitation](https://modelcontextprotocol.io/specification/latest/client/elicitation) in the MCP specification.
324
324
@@ -367,6 +367,19 @@ console.log(result);
367
367
> [!NOTE]
368
368
> For an end‑to‑end example of server‑initiated SSE disconnection and automatic client reconnection with event replay, see [`ssePollingClient.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/ssePollingClient.ts).
369
369
370
+
## Tasks (experimental)
371
+
372
+
Task-based execution enables "call-now, fetch-later" patterns for long-running operations. Instead of returning a result immediately, a tool creates a task that can be polled or resumed later. To use tasks:
373
+
374
+
- Call {@linkcode@modelcontextprotocol/client!experimental/tasks/client.ExperimentalClientTasks#callToolStream | client.experimental.tasks.callToolStream(...)} to start a tool call that may create a task and emit status updates over time.
375
+
- Call {@linkcode@modelcontextprotocol/client!experimental/tasks/client.ExperimentalClientTasks#getTask | client.experimental.tasks.getTask(...)} and {@linkcode@modelcontextprotocol/client!experimental/tasks/client.ExperimentalClientTasks#getTaskResult | getTaskResult(...)} to check status and fetch results after reconnecting.
376
+
377
+
> [!NOTE]
378
+
> For a full runnable example, see [`simpleTaskInteractiveClient.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/simpleTaskInteractiveClient.ts).
379
+
380
+
> [!WARNING]
381
+
> The tasks API is experimental and may change without notice.
382
+
370
383
## More client features
371
384
372
385
The sections above cover the essentials. The table below links to additional capabilities.
@@ -377,4 +390,3 @@ The sections above cover the essentials. The table below links to additional cap
377
390
| SSE disconnect / reconnection | Server‑initiated SSE disconnect with automatic reconnection and event replay |[`ssePollingClient.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/ssePollingClient.ts)|
378
391
| Multiple clients | Independent client lifecycles to the same server |[`multipleClientsParallel.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/multipleClientsParallel.ts)|
379
392
| URL elicitation | Handle sensitive data collection via browser |[`elicitationUrlExample.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/elicitationUrlExample.ts)|
380
-
| Tasks (experimental) | Long‑running tool calls with status streaming |[`simpleTaskInteractiveClient.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/simpleTaskInteractiveClient.ts), [Capabilities guide](capabilities.md#task-based-execution-experimental)|
Copy file name to clipboardExpand all lines: docs/server.md
+116-5Lines changed: 116 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Server
3
3
---
4
4
5
-
##Server overview
5
+
# Server overview
6
6
7
7
This guide covers SDK usage for building MCP servers in TypeScript. For protocol-level details and message formats, see the [MCP specification](https://modelcontextprotocol.io/specification/latest/).
8
8
@@ -339,9 +339,123 @@ server.registerPrompt(
339
339
340
340
For client-side completion usage, see the [Client guide](client.md).
341
341
342
+
## Server‑initiated requests
343
+
344
+
MCP is bidirectional — servers can also send requests *to* the client during tool execution, as long as the client declares matching capabilities.
345
+
346
+
### Sampling
347
+
348
+
Use `ctx.mcpReq.requestSampling(params)` (from {@linkcode@modelcontextprotocol/server!index.ServerContext | ServerContext}) inside a tool handler to request an LLM completion from the connected client:
> For a full runnable example, see [`toolWithSampleServer.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/server/src/toolWithSampleServer.ts).
384
+
>
385
+
> For protocol details, see [Sampling](https://modelcontextprotocol.io/specification/latest/client/sampling) in the MCP specification.
386
+
387
+
### Elicitation
388
+
389
+
Use `ctx.mcpReq.elicitInput(params)` (from {@linkcode@modelcontextprotocol/server!index.ServerContext | ServerContext}) inside a tool handler to request user input. Elicitation supports two modes:
390
+
391
+
-**Form** (`mode: 'form'`) — collects **non‑sensitive** data via a schema‑driven form.
392
+
-**URL** (`mode: 'url'`) — for sensitive data or secure web‑based flows (API keys, payments, OAuth). The client opens a URL in the browser.
393
+
394
+
> [!IMPORTANT]
395
+
> Sensitive information **must not** be collected via form elicitation; always use URL elicitation or out‑of‑band flows for secrets.
> For runnable examples, see [`elicitationFormExample.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/server/src/elicitationFormExample.ts) (form mode) and [`elicitationUrlExample.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/server/src/elicitationUrlExample.ts) (URL mode).
439
+
>
440
+
> For protocol details, see [Elicitation](https://modelcontextprotocol.io/specification/latest/client/elicitation) in the MCP specification.
441
+
442
+
## Tasks (experimental)
443
+
444
+
Task-based execution enables "call-now, fetch-later" patterns for long-running operations. Instead of returning a result immediately, a tool creates a task that can be polled or resumed later. To use tasks:
445
+
446
+
- Provide a {@linkcode@modelcontextprotocol/server!index.TaskStore | TaskStore} implementation that persists task metadata and results (see {@linkcode@modelcontextprotocol/server!index.InMemoryTaskStore | InMemoryTaskStore} for reference).
447
+
- Enable the `tasks` capability when constructing the server.
448
+
- Register tools with {@linkcode@modelcontextprotocol/server!experimental/tasks/mcpServer.ExperimentalMcpServerTasks#registerToolTask | server.experimental.tasks.registerToolTask(...)}.
449
+
450
+
> [!NOTE]
451
+
> For a full runnable example, see [`simpleTaskInteractive.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/server/src/simpleTaskInteractive.ts).
452
+
453
+
> [!WARNING]
454
+
> The tasks API is experimental and may change without notice.
455
+
342
456
## More server features
343
457
344
-
The sections above cover the essentials. The SDK supports several additional capabilities — each is demonstrated in the runnable examples and covered in more detail in the linked references.
458
+
The sections above cover the essentials. The table below links to additional capabilities demonstrated in the runnable examples.
345
459
346
460
| Feature | Description | Reference |
347
461
|---------|-------------|-----------|
@@ -350,7 +464,4 @@ The sections above cover the essentials. The SDK supports several additional cap
350
464
| Resumability | Replay missed SSE events via an event store |[`inMemoryEventStore.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/server/src/inMemoryEventStore.ts)|
351
465
| CORS | Expose MCP headers (`mcp-session-id`, etc.) for browser clients |[`simpleStreamableHttp.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/server/src/simpleStreamableHttp.ts)|
352
466
| Tool annotations | Hint whether tools are read-only, destructive, etc. |[`simpleStreamableHttp.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/server/src/simpleStreamableHttp.ts)|
353
-
| Elicitation | Request user input (forms or URLs) during tool execution |[Capabilities guide](capabilities.md#elicitation), [`elicitationFormExample.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/server/src/elicitationFormExample.ts)|
354
-
| Sampling | Request LLM completions from the connected client |[Capabilities guide](capabilities.md#sampling), [`toolWithSampleServer.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/server/src/toolWithSampleServer.ts)|
355
-
| Tasks (experimental) | Long-running operations with polling and resumption |[Capabilities guide](capabilities.md#task-based-execution-experimental), [`simpleStreamableHttp.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/server/src/simpleStreamableHttp.ts)|
0 commit comments