Skip to content

Commit 97fcd60

Browse files
committed
Add optional status notifications for tasks
1 parent e57ea31 commit 97fcd60

File tree

4 files changed

+134
-4
lines changed

4 files changed

+134
-4
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,35 @@ This notification resolves the race condition where a requestor might attempt to
220220

221221
Receivers that do not support tasks (and thus ignore task metadata in requests) will not send this notification, allowing requestors to fall back to waiting for the original request response.
222222

223+
### Task Status Notification
224+
225+
When a task's status changes, receivers **MAY** send a `notifications/tasks/status` notification to inform the requestor of the change.
226+
227+
**Notification:**
228+
229+
```json
230+
{
231+
"jsonrpc": "2.0",
232+
"method": "notifications/tasks/status",
233+
"params": {
234+
"status": "completed",
235+
"_meta": {
236+
"modelcontextprotocol.io/related-task": {
237+
"taskId": "786512e2-9e0d-44bd-8f29-789f320fe840"
238+
}
239+
}
240+
}
241+
}
242+
```
243+
244+
The notification includes:
245+
- `status`: The new task status
246+
- `error` (optional): Error message if the status is `failed`
247+
248+
The task ID is conveyed through the `modelcontextprotocol.io/related-task` metadata key.
249+
250+
Requestors **MUST NOT** rely on receiving these notifications, as they are optional. Receivers are not required to send status notifications and may choose to only send them for certain status transitions. Requestors **SHOULD** continue to poll via `tasks/get` to ensure they receive status updates.
251+
223252
### Listing Tasks
224253

225254
To retrieve a list of tasks, requestors send a `tasks/list` request. This operation supports pagination.

docs/specification/draft/schema.mdx

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema/draft/schema.json

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema/draft/schema.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export interface NotificationParams {
5757
_meta?: { [key: string]: unknown };
5858
}
5959

60-
6160
/** @internal */
6261
export interface Notification {
6362
method: string;
@@ -546,7 +545,7 @@ export interface Implementation extends BaseMetadata, Icons {
546545
*/
547546
export interface PingRequest extends JSONRPCRequest {
548547
method: "ping";
549-
params?: RequestParams
548+
params?: RequestParams;
550549
}
551550

552551
/* Progress notifications */
@@ -1423,6 +1422,41 @@ export interface TaskCreatedNotification extends JSONRPCNotification {
14231422
};
14241423
}
14251424

1425+
/**
1426+
* Parameters for a `notifications/tasks/status` notification.
1427+
*
1428+
* @category notifications/tasks/status
1429+
*/
1430+
export interface TaskStatusNotificationParams extends NotificationParams {
1431+
/**
1432+
* The new task status.
1433+
*/
1434+
status: TaskStatus;
1435+
1436+
/**
1437+
* Error message if status is "failed".
1438+
*/
1439+
error?: string;
1440+
1441+
/**
1442+
* The _meta field MUST include modelcontextprotocol.io/related-task with the taskId.
1443+
*/
1444+
_meta?: {
1445+
"modelcontextprotocol.io/related-task"?: RelatedTaskMetadata;
1446+
[key: string]: unknown;
1447+
};
1448+
}
1449+
1450+
/**
1451+
* An optional notification from the receiver to the requestor, informing them that a task's status has changed. Receivers are not required to send these notifications.
1452+
*
1453+
* @category notifications/tasks/status
1454+
*/
1455+
export interface TaskStatusNotification extends JSONRPCNotification {
1456+
method: "notifications/tasks/status";
1457+
params: TaskStatusNotificationParams;
1458+
}
1459+
14261460
/* Logging */
14271461

14281462
/**
@@ -2042,7 +2076,8 @@ export type ClientNotification =
20422076
| ProgressNotification
20432077
| InitializedNotification
20442078
| RootsListChangedNotification
2045-
| TaskCreatedNotification;
2079+
| TaskCreatedNotification
2080+
| TaskStatusNotification;
20462081

20472082
/** @internal */
20482083
export type ClientResult =
@@ -2076,7 +2111,8 @@ export type ServerNotification =
20762111
| ResourceListChangedNotification
20772112
| ToolListChangedNotification
20782113
| PromptListChangedNotification
2079-
| TaskCreatedNotification;
2114+
| TaskCreatedNotification
2115+
| TaskStatusNotification;
20802116

20812117
/** @internal */
20822118
export type ServerResult =

0 commit comments

Comments
 (0)