Skip to content

Commit 3028c92

Browse files
committed
Merge branch 'main' into elicitation/expect-server-flag
2 parents 3b9aa40 + 2951c23 commit 3028c92

File tree

7 files changed

+171
-122
lines changed

7 files changed

+171
-122
lines changed

docs/docs/develop/build-client.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,10 @@ async function main() {
738738
try {
739739
await mcpClient.connectToServer(process.argv[2]);
740740
await mcpClient.chatLoop();
741+
} catch (e) {
742+
console.error("Error:", e);
743+
await mcpClient.cleanup();
744+
process.exit(1);
741745
} finally {
742746
await mcpClient.cleanup();
743747
process.exit(0);
@@ -842,6 +846,7 @@ If you see:
842846
- `Tool execution failed`: Verify the tool's required environment variables are set
843847
- `ANTHROPIC_API_KEY is not set`: Check your .env file and environment variables
844848
- `TypeError`: Ensure you're using the correct types for tool arguments
849+
- `BadRequestError`: Ensure you have enough credits to access the Anthropic API
845850

846851
</Tab>
847852

docs/specification/draft/basic/transports.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ MCP endpoint.
111111
at any time in order to avoid holding a long-lived connection. The client
112112
**SHOULD** then "poll" the SSE stream by attempting to reconnect.
113113
- If the server does close the _connection_ prior to terminating the _SSE stream_,
114-
it **SHOULD** send an SSE event with a standard [`retry`](https://html.spec.whatwg.org/multipage/server-sent-events.html#the-retry-value) field before
114+
it **SHOULD** send an SSE event with a standard [`retry`](https://html.spec.whatwg.org/multipage/server-sent-events.html#:~:text=field%20name%20is%20%22retry%22) field before
115115
closing the connection. The client **MUST** respect the `retry` field,
116116
waiting the given number of milliseconds before attempting to reconnect.
117117
- The SSE stream **SHOULD** eventually include a JSON-RPC _response_ for the

docs/specification/draft/basic/utilities/tasks.mdx

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ The set of capabilities in `capabilities.tasks.requests` is exhaustive. If a req
108108

109109
### Tool-Level Negotiation
110110

111-
Tool calls are given special consideration for the purpose of task augmentation. In the result of `tools/list`, tools declare support for tasks via `annotations.taskHint`, which if present can have a value of `"always"`, `"optional"`, or `"never"`.
111+
Tool calls are given special consideration for the purpose of task augmentation. In the result of `tools/list`, tools declare support for tasks via `execution.task`, which if present can have a value of `"always"`, `"optional"`, or `"never"`.
112112

113113
This is to be interpreted as a fine-grained layer in addition to capabilities, following these rules:
114114

115-
1. If a server's capabilities include `tasks.requests.tools.call: false`, then clients **MUST NOT** attempt to use task augmentation on that server's tools, regardless of the `taskHint` value.
116-
1. If a server's capabilities include `tasks.requests.tools.call: true`, then clients consider the value of `taskHint`, and handle it accordingly:
117-
1. If `taskHint` is not present or `"never"`, clients **MUST NOT** attempt to invoke the tool as a task. Servers **SHOULD** return a `-32601` (Method not found) error if a client attempts to do so. This is the default behavior.
118-
1. If `taskHint` is `"optional"`, clients **MAY** invoke the tool as a task or as a normal request.
119-
1. If `taskHint` is `"always"`, clients **SHOULD** invoke the tool as a task. Servers **MAY** return a `-32601` (Method not found) error if a client does not attempt to do so.
115+
1. If a server's capabilities do not include `tasks.requests.tools.call`, then clients **MUST NOT** attempt to use task augmentation on that server's tools, regardless of the `execution.task` value.
116+
1. If a server's capabilities include `tasks.requests.tools.call`, then clients consider the value of `execution.task`, and handle it accordingly:
117+
1. If `execution.task` is not present or `"never"`, clients **MUST NOT** attempt to invoke the tool as a task. Servers **SHOULD** return a `-32601` (Method not found) error if a client attempts to do so. This is the default behavior.
118+
1. If `execution.task` is `"optional"`, clients **MAY** invoke the tool as a task or as a normal request.
119+
1. If `execution.task` is `"always"`, clients **MUST** invoke the tool as a task. Servers **MUST** return a `-32601` (Method not found) error if a client does not attempt to do so.
120120

121121
## Protocol Messages
122122

@@ -182,10 +182,18 @@ This guidance is non-binding and is provisional logic intended to account for th
182182

183183
### Getting Tasks
184184

185+
<Note>
186+
187+
In the Streamable HTTP (SSE) transport, clients **MAY** disconnect from an SSE stream opened by the server in response to a `tasks/get` request at any time.
188+
189+
While this note is not prescriptive regarding the specific usage of SSE streams, all implementations **MUST** continue to comply with the existing [Streamable HTTP transport specification](../transports#sending-messages-to-the-server).
190+
191+
</Note>
192+
185193
Requestors poll for task completion by sending [`tasks/get`](/specification/draft/schema#tasks%2Fget) requests.
186194
Requestors **SHOULD** respect the `pollInterval` provided in responses when determining polling frequency.
187195

188-
Requestors **SHOULD** continue polling until the task reaches a terminal status (`completed`, `failed`, or `cancelled`), or until encountering the [`input_required`](#input-required-status) status.
196+
Requestors **SHOULD** continue polling until the task reaches a terminal status (`completed`, `failed`, or `cancelled`), or until encountering the [`input_required`](#input-required-status) status. Note that invoking `tasks/result` does not imply that the requestor needs to stop polling - requestors **SHOULD** continue polling the task status via `tasks/get` if they are not actively waiting for `tasks/result` to complete.
189197

190198
**Request:**
191199

@@ -219,10 +227,20 @@ Requestors **SHOULD** continue polling until the task reaches a terminal status
219227

220228
### Retrieving Task Results
221229

230+
<Note>
231+
232+
In the Streamable HTTP (SSE) transport, clients **MAY** disconnect from an SSE stream opened by the server in response to a `tasks/result` request at any time.
233+
234+
While this note is not prescriptive regarding the specific usage of SSE streams, all implementations **MUST** continue to comply with the existing [Streamable HTTP transport specification](../transports#sending-messages-to-the-server).
235+
236+
</Note>
237+
222238
After a task completes the operation result is retrieved via [`tasks/result`](/specification/draft/schema#tasks%2Fresult). This is distinct from the initial `CreateTaskResult` response, which contains only task data. The result structure matches the original request type (e.g., `CallToolResult` for `tools/call`).
223239

224240
To retrieve the result of a completed task, requestors can send a `tasks/result` request:
225241

242+
While `tasks/result` blocks until the task reaches a terminal status, requestors can continue polling via `tasks/get` in parallel if they are not actively blocked waiting for the result, such as if their previous `tasks/result` request failed or was cancelled. This allows requestors to monitor status changes or display progress updates while the task executes, even after invoking `tasks/result`.
243+
226244
**Request:**
227245

228246
```json
@@ -412,7 +430,9 @@ stateDiagram-v2
412430

413431
With the Streamable HTTP (SSE) transport, servers often close SSE streams after delivering a response message, which can lead to ambiguity regarding the stream used for subsequent task messages.
414432

415-
Implementations have flexibility in how they manage SSE streams during task polling and result retrieval.
433+
Servers can handle this by enqueueing messages to the client to side-channel task-related messages alongside other responses.
434+
435+
Servers have flexibility in how they manage SSE streams during task polling and result retrieval, and clients **SHOULD** expect messages to be delivered on any SSE stream, including the HTTP GET stream.
416436
One possible approach is maintaining an SSE stream on `tasks/result` (see notes on the `input_required` status).
417437
Where possible, servers **SHOULD NOT** upgrade to an SSE stream in response to a `tasks/get` request, as the client has indicated it wishes to poll for a result.
418438

@@ -482,19 +502,29 @@ sequenceDiagram
482502
participant S as Server (Receiver)
483503
Note over C,S: 1. Task Creation
484504
C->>S: Request with task field (ttl)
505+
activate S
485506
S->>C: CreateTaskResult (taskId, status: working, ttl, pollInterval)
507+
deactivate S
486508
Note over C,S: 2. Task Polling
487509
C->>S: tasks/get (taskId)
510+
activate S
488511
S->>C: working
512+
deactivate S
489513
Note over S: Task processing continues...
490514
C->>S: tasks/get (taskId)
515+
activate S
491516
S->>C: working
517+
deactivate S
492518
Note over S: Task completes
493519
C->>S: tasks/get (taskId)
520+
activate S
494521
S->>C: completed
522+
deactivate S
495523
Note over C,S: 3. Result Retrieval
496524
C->>S: tasks/result (taskId)
525+
activate S
497526
S->>C: Result content
527+
deactivate S
498528
Note over C,S: 4. Cleanup
499529
Note over S: After ttl period from creation, task is cleaned up
500530
```
@@ -513,44 +543,61 @@ sequenceDiagram
513543
514544
Note over C,S: Client augments with task
515545
C->>S: tools/call (ttl: 3600000)
546+
activate S
516547
S->>C: CreateTaskResult (task-123, status: working)
548+
deactivate S
517549
518550
Note over LLM,C: Client continues processing other requests<br/>while task executes in background
519551
LLM->>C: Request other operation
520552
C->>LLM: Other operation result
521553
522554
Note over C,S: Client polls for status
523555
C->>S: tasks/get (task-123)
556+
activate S
524557
S->>C: working
558+
deactivate S
525559
526560
Note over S: Server needs information from client<br/>Task moves to input_required
527561
528562
Note over C,S: Client polls and discovers input_required
529563
C->>S: tasks/get (task-123)
564+
activate S
530565
S->>C: input_required
566+
deactivate S
531567
532-
Note over C,S: Client receives input requests
568+
Note over C,S: Client opens result stream
533569
C->>S: tasks/result (task-123)
534-
S->>C: elicitation/create (task-123)
570+
activate S
571+
S->>C: elicitation/create (related-task: task-123)
572+
activate C
535573
C->>U: Prompt user for input
536574
U->>C: Provide information
537-
C->>S: elicitation response (task-123)
575+
C->>S: elicitation response (related-task: task-123)
576+
deactivate C
577+
deactivate S
578+
579+
Note over C,S: Client closes result stream and resumes polling
538580
539581
Note over S: Task continues processing...<br/>Task moves back to working
540582
541-
Note over C,S: Client polls again
542583
C->>S: tasks/get (task-123)
584+
activate S
543585
S->>C: working
586+
deactivate S
544587
545588
Note over S: Task completes
546589
547590
Note over C,S: Client polls and discovers completion
548591
C->>S: tasks/get (task-123)
592+
activate S
549593
S->>C: completed
594+
deactivate S
550595
551596
Note over C,S: Client retrieves final results
552597
C->>S: tasks/result (task-123)
598+
activate S
553599
S->>C: Result content
600+
deactivate S
554601
C->>LLM: Process result
555602
556603
Note over S: Results retained for ttl period from creation
@@ -569,13 +616,17 @@ sequenceDiagram
569616
570617
Note over S,C: Server requests client operation (task-augmented)
571618
S->>C: sampling/createMessage (ttl: 3600000)
619+
activate C
572620
C->>S: CreateTaskResult (request-789, status: working)
621+
deactivate C
573622
574623
Note over S: Server continues processing<br/>while waiting for result
575624
576625
Note over S,C: Server polls for result
577626
S->>C: tasks/get (request-789)
627+
activate C
578628
C->>S: working
629+
deactivate C
579630
580631
Note over C,U: Client may present request to user
581632
C->>U: Review request
@@ -591,11 +642,15 @@ sequenceDiagram
591642
592643
Note over S,C: Server polls and discovers completion
593644
S->>C: tasks/get (request-789)
645+
activate C
594646
C->>S: completed
647+
deactivate C
595648
596649
Note over S,C: Server retrieves result
597650
S->>C: tasks/result (request-789)
651+
activate C
598652
C->>S: Result content
653+
deactivate C
599654
600655
Note over S: Server continues processing
601656
@@ -611,20 +666,26 @@ sequenceDiagram
611666
612667
Note over C,S: 1. Task Creation
613668
C->>S: tools/call (request ID: 42, ttl: 60000)
669+
activate S
614670
S->>C: CreateTaskResult (task-123, status: working)
671+
deactivate S
615672
616673
Note over C,S: 2. Task Processing
617674
C->>S: tasks/get (task-123)
675+
activate S
618676
S->>C: working
677+
deactivate S
619678
620679
Note over C,S: 3. Client Cancellation
621680
Note over C: User requests cancellation
622681
C->>S: tasks/cancel (taskId: task-123)
682+
activate S
623683
624684
Note over S: Server stops execution (best effort)
625685
Note over S: Task moves to cancelled status
626686
627687
S->>C: Task (status: cancelled)
688+
deactivate S
628689
629690
Note over C: Client receives confirmation
630691

0 commit comments

Comments
 (0)