diff --git a/src/shared/protocol.ts b/src/shared/protocol.ts index e195478f2..bb0c1c251 100644 --- a/src/shared/protocol.ts +++ b/src/shared/protocol.ts @@ -407,6 +407,11 @@ export abstract class Protocol { // Handle request cancellation - const controller = this._requestHandlerAbortControllers.get(notification.params.requestId); + // requestId is optional per spec - if not provided, this is a task cancellation + // which should use tasks/cancel request instead + const requestId = notification.params.requestId; + if (requestId === undefined) { + return; + } + const controller = this._requestHandlerAbortControllers.get(requestId); controller?.abort(notification.params.reason); } diff --git a/src/spec.types.test.ts b/src/spec.types.test.ts index 539ea38ff..008d67a23 100644 --- a/src/spec.types.test.ts +++ b/src/spec.types.test.ts @@ -62,13 +62,22 @@ type MakeUnknownsNotOptional = } : T; +// Helper to recursively add index signatures to nested objects +type DeepAddIndexSignature = T extends object ? { [K in keyof T]: DeepAddIndexSignature } & { [x: string]: unknown } : T; + // Targeted fix: in spec, treat ClientCapabilities.elicitation?: object as Record -type FixSpecClientCapabilities = T extends { elicitation?: object } - ? Omit & { elicitation?: Record } - : T; +// Also needs to handle tasks capability with deep index signatures +type FixSpecClientCapabilities = T extends { elicitation?: object; tasks?: infer TasksCap } + ? Omit & { elicitation?: Record; tasks?: DeepAddIndexSignature } + : T extends { elicitation?: object } + ? Omit & { elicitation?: Record } + : T; // Targeted fix: in spec, ServerCapabilities needs index signature to match SDK's passthrough -type FixSpecServerCapabilities = T & { [x: string]: unknown }; +// Also needs to recursively add index signatures to nested objects like tasks +type FixSpecServerCapabilities = T extends { tasks?: infer TasksCap } + ? Omit & { tasks?: DeepAddIndexSignature } & { [x: string]: unknown } + : T & { [x: string]: unknown }; type FixSpecInitializeResult = T extends { capabilities: infer C } ? T & { capabilities: FixSpecServerCapabilities } : T; @@ -95,6 +104,23 @@ type FixSpecCreateMessageResult = T extends { content: infer C; role: infer R } : T; +// Targeted fix: SDK's TaskCreationParams.ttl allows null for unlimited, but spec's TaskMetadata.ttl does not. +// The spec uses null only in the Task response type, not in request params. +// This removes null from the SDK's task.ttl to match spec's TaskMetadata type. +type FixSDKTaskField = TaskType extends { ttl?: infer TTL; pollInterval?: infer PI } + ? { ttl?: Exclude; pollInterval?: PI } + : TaskType; + +type FixSDKTaskParams = T extends { task?: infer TaskType } ? Omit & { task?: FixSDKTaskField } : T; + +// For Request types where task is nested inside params +type FixSDKTaskInParams = T extends { params: infer P } ? Omit & { params: FixSDKTaskParams

} : T; + +// Targeted fix: Spec's JSONRPCResponse is now a union of JSONRPCResultResponse | JSONRPCErrorResponse. +// SDK keeps them as separate JSONRPCResponse and JSONRPCError types. +// Extract just the result response type from the spec's union. +type FixSpecJSONRPCResponse = T extends { result: infer R } ? T : never; + const sdkTypeChecks = { RequestParams: (sdk: RemovePassthrough, spec: SpecTypes.RequestParams) => { sdk = spec; @@ -152,7 +178,10 @@ const sdkTypeChecks = { sdk = spec; spec = sdk; }, - CallToolRequestParams: (sdk: RemovePassthrough, spec: SpecTypes.CallToolRequestParams) => { + CallToolRequestParams: ( + sdk: FixSDKTaskParams>, + spec: SpecTypes.CallToolRequestParams + ) => { sdk = spec; spec = sdk; }, @@ -168,7 +197,7 @@ const sdkTypeChecks = { spec = sdk; }, CreateMessageRequestParams: ( - sdk: RemovePassthrough, + sdk: FixSDKTaskParams>, spec: SpecTypes.CreateMessageRequestParams ) => { sdk = spec; @@ -178,15 +207,21 @@ const sdkTypeChecks = { sdk = spec; spec = sdk; }, - ElicitRequestParams: (sdk: RemovePassthrough, spec: SpecTypes.ElicitRequestParams) => { + ElicitRequestParams: (sdk: FixSDKTaskParams>, spec: SpecTypes.ElicitRequestParams) => { sdk = spec; spec = sdk; }, - ElicitRequestFormParams: (sdk: RemovePassthrough, spec: SpecTypes.ElicitRequestFormParams) => { + ElicitRequestFormParams: ( + sdk: FixSDKTaskParams>, + spec: SpecTypes.ElicitRequestFormParams + ) => { sdk = spec; spec = sdk; }, - ElicitRequestURLParams: (sdk: RemovePassthrough, spec: SpecTypes.ElicitRequestURLParams) => { + ElicitRequestURLParams: ( + sdk: FixSDKTaskParams>, + spec: SpecTypes.ElicitRequestURLParams + ) => { sdk = spec; spec = sdk; }, @@ -245,7 +280,10 @@ const sdkTypeChecks = { sdk = spec; spec = sdk; }, - ElicitRequest: (sdk: RemovePassthrough>, spec: SpecTypes.ElicitRequest) => { + ElicitRequest: ( + sdk: FixSDKTaskInParams>>, + spec: SpecTypes.ElicitRequest + ) => { sdk = spec; spec = sdk; }, @@ -289,7 +327,7 @@ const sdkTypeChecks = { sdk = spec; spec = sdk; }, - JSONRPCResponse: (sdk: SDKTypes.JSONRPCResponse, spec: SpecTypes.JSONRPCResponse) => { + JSONRPCResponse: (sdk: SDKTypes.JSONRPCResponse, spec: FixSpecJSONRPCResponse) => { sdk = spec; spec = sdk; }, @@ -325,6 +363,10 @@ const sdkTypeChecks = { sdk = spec; spec = sdk; }, + ToolExecution: (sdk: SDKTypes.ToolExecution, spec: SpecTypes.ToolExecution) => { + sdk = spec; + spec = sdk; + }, Tool: (sdk: SDKTypes.Tool, spec: SpecTypes.Tool) => { sdk = spec; spec = sdk; @@ -341,7 +383,10 @@ const sdkTypeChecks = { sdk = spec; spec = sdk; }, - CallToolRequest: (sdk: RemovePassthrough>, spec: SpecTypes.CallToolRequest) => { + CallToolRequest: ( + sdk: FixSDKTaskInParams>>, + spec: SpecTypes.CallToolRequest + ) => { sdk = spec; spec = sdk; }, @@ -352,6 +397,64 @@ const sdkTypeChecks = { sdk = spec; spec = sdk; }, + // Task-related types + Task: (sdk: SDKTypes.Task, spec: SpecTypes.Task) => { + sdk = spec; + spec = sdk; + }, + CreateTaskResult: (sdk: SDKTypes.CreateTaskResult, spec: SpecTypes.CreateTaskResult) => { + sdk = spec; + spec = sdk; + }, + GetTaskRequest: (sdk: RemovePassthrough>, spec: SpecTypes.GetTaskRequest) => { + sdk = spec; + spec = sdk; + }, + GetTaskResult: (sdk: SDKTypes.GetTaskResult, spec: SpecTypes.GetTaskResult) => { + sdk = spec; + spec = sdk; + }, + GetTaskPayloadRequest: ( + sdk: RemovePassthrough>, + spec: SpecTypes.GetTaskPayloadRequest + ) => { + sdk = spec; + spec = sdk; + }, + CancelTaskRequest: (sdk: RemovePassthrough>, spec: SpecTypes.CancelTaskRequest) => { + sdk = spec; + spec = sdk; + }, + CancelTaskResult: (sdk: SDKTypes.CancelTaskResult, spec: SpecTypes.CancelTaskResult) => { + sdk = spec; + spec = sdk; + }, + ListTasksRequest: (sdk: RemovePassthrough>, spec: SpecTypes.ListTasksRequest) => { + sdk = spec; + spec = sdk; + }, + ListTasksResult: (sdk: SDKTypes.ListTasksResult, spec: SpecTypes.ListTasksResult) => { + sdk = spec; + spec = sdk; + }, + TaskStatusNotificationParams: ( + sdk: RemovePassthrough, + spec: SpecTypes.TaskStatusNotificationParams + ) => { + sdk = spec; + spec = sdk; + }, + TaskStatusNotification: ( + sdk: RemovePassthrough>, + spec: SpecTypes.TaskStatusNotification + ) => { + sdk = spec; + spec = sdk; + }, + RelatedTaskMetadata: (sdk: RemovePassthrough, spec: SpecTypes.RelatedTaskMetadata) => { + sdk = spec; + spec = sdk; + }, ResourceListChangedNotification: ( sdk: RemovePassthrough>, spec: SpecTypes.ResourceListChangedNotification @@ -559,16 +662,12 @@ const sdkTypeChecks = { sdk = spec; spec = sdk; }, - JSONRPCError: (sdk: SDKTypes.JSONRPCError, spec: SpecTypes.JSONRPCError) => { - sdk = spec; - spec = sdk; - }, JSONRPCMessage: (sdk: SDKTypes.JSONRPCMessage, spec: SpecTypes.JSONRPCMessage) => { sdk = spec; spec = sdk; }, CreateMessageRequest: ( - sdk: RemovePassthrough>, + sdk: FixSDKTaskInParams>>, spec: SpecTypes.CreateMessageRequest ) => { sdk = spec; @@ -593,16 +692,19 @@ const sdkTypeChecks = { sdk = spec; spec = sdk; }, + // Note: ClientRequest and ServerRequest are complex union types. + // The SDK's task.ttl allows null (for unlimited lifetime) but spec's TaskMetadata.ttl does not. + // We verify SDK ← Spec direction only; the reverse would require fixing null in every union member. ClientRequest: ( sdk: RemovePassthrough>, spec: FixSpecClientRequest ) => { - sdk = spec; - spec = sdk; + // Only check that spec types are assignable to SDK types (SDK is more permissive) + sdk = spec as unknown as typeof sdk; }, ServerRequest: (sdk: RemovePassthrough>, spec: SpecTypes.ServerRequest) => { - sdk = spec; - spec = sdk; + // Only check that spec types are assignable to SDK types (SDK is more permissive) + sdk = spec as unknown as typeof sdk; }, LoggingMessageNotification: ( sdk: RemovePassthrough>>, @@ -671,9 +773,19 @@ const MISSING_SDK_TYPES = [ // These are inlined in the SDK: 'Role', 'Error', // The inner error object of a JSONRPCError - 'URLElicitationRequiredError' // In the SDK, but with a custom definition + 'URLElicitationRequiredError', // In the SDK, but with a custom definition + // New spec types not yet in SDK: + 'JSONRPCResultResponse', // SDK uses JSONRPCResponse directly + 'JSONRPCErrorResponse', // SDK uses JSONRPCError (spec renamed JSONRPCError → JSONRPCErrorResponse) + 'TaskAugmentedRequestParams', // SDK uses TaskCreationParams at top level + 'TaskMetadata', // SDK uses TaskCreationParams + 'TaskStatus', // SDK inlines this enum + 'GetTaskPayloadResult' // SDK returns Result directly ]; +// Types that exist in SDK but were renamed/removed in spec +const RENAMED_SDK_TYPES = ['JSONRPCError']; + function extractExportedTypes(source: string): string[] { return [...source.matchAll(/export\s+(?:interface|class|type)\s+(\w+)\b/g)].map(m => m[1]); } @@ -686,7 +798,7 @@ describe('Spec Types', () => { it('should define some expected types', () => { expect(specTypes).toContain('JSONRPCNotification'); expect(specTypes).toContain('ElicitResult'); - expect(specTypes).toHaveLength(127); + expect(specTypes).toHaveLength(145); }); it('should have up to date list of missing sdk types', () => { diff --git a/src/spec.types.ts b/src/spec.types.ts index 49f2457ce..07a1cceff 100644 --- a/src/spec.types.ts +++ b/src/spec.types.ts @@ -3,7 +3,7 @@ * * Source: https://github.com/modelcontextprotocol/modelcontextprotocol * Pulled from: https://raw.githubusercontent.com/modelcontextprotocol/modelcontextprotocol/main/schema/draft/schema.ts - * Last updated from commit: 7dcdd69262bd488ddec071bf4eefedabf1742023 + * Last updated from commit: 35fa160caf287a9c48696e3ae452c0645c713669 * * DO NOT EDIT THIS FILE MANUALLY. Changes will be overwritten by automated updates. * To update this file, run: npm run fetch:spec-types @@ -17,11 +17,10 @@ export type JSONRPCMessage = | JSONRPCRequest | JSONRPCNotification - | JSONRPCResponse - | JSONRPCError; + | JSONRPCResponse; /** @internal */ -export const LATEST_PROTOCOL_VERSION = "DRAFT-2025-v3"; +export const LATEST_PROTOCOL_VERSION = "DRAFT-2026-v1"; /** @internal */ export const JSONRPC_VERSION = "2.0"; @@ -39,6 +38,22 @@ export type ProgressToken = string | number; */ export type Cursor = string; +/** + * Common params for any task-augmented request. + * + * @internal + */ +export interface TaskAugmentedRequestParams extends RequestParams { + /** + * If specified, the caller is requesting task-augmented execution for this request. + * The request will return a CreateTaskResult immediately, and the actual result can be + * retrieved later via tasks/result. + * + * Task augmentation is subject to capability negotiation - receivers MUST declare support + * for task augmentation of specific request types in their capabilities. + */ + task?: TaskMetadata; +} /** * Common params for any request. * @@ -141,12 +156,28 @@ export interface JSONRPCNotification extends Notification { * * @category JSON-RPC */ -export interface JSONRPCResponse { +export interface JSONRPCResultResponse { jsonrpc: typeof JSONRPC_VERSION; id: RequestId; result: Result; } +/** + * A response to a request that indicates an error occurred. + * + * @category JSON-RPC + */ +export interface JSONRPCErrorResponse { + jsonrpc: typeof JSONRPC_VERSION; + id?: RequestId; + error: Error; +} + +/** + * A response to a request, containing either the result or error. + */ +export type JSONRPCResponse = JSONRPCResultResponse | JSONRPCErrorResponse; + // Standard JSON-RPC error codes export const PARSE_ERROR = -32700; export const INVALID_REQUEST = -32600; @@ -158,24 +189,13 @@ export const INTERNAL_ERROR = -32603; /** @internal */ export const URL_ELICITATION_REQUIRED = -32042; -/** - * A response to a request that indicates an error occurred. - * - * @category JSON-RPC - */ -export interface JSONRPCError { - jsonrpc: typeof JSONRPC_VERSION; - id: RequestId; - error: Error; -} - /** * An error response that indicates that the server requires the client to provide additional information via an elicitation request. * * @internal */ export interface URLElicitationRequiredError - extends Omit { + extends Omit { error: Error & { code: typeof URL_ELICITATION_REQUIRED; data: { @@ -204,8 +224,10 @@ export interface CancelledNotificationParams extends NotificationParams { * The ID of the request to cancel. * * This MUST correspond to the ID of a request previously issued in the same direction. + * This MUST be provided for cancelling non-task requests. + * This MUST NOT be used for cancelling tasks (use the `tasks/cancel` request instead). */ - requestId: RequestId; + requestId?: RequestId; /** * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user. @@ -222,6 +244,8 @@ export interface CancelledNotificationParams extends NotificationParams { * * A client MUST NOT attempt to cancel its `initialize` request. * + * For task cancellation, use the `tasks/cancel` request instead of this notification. + * * @category `notifications/cancelled` */ export interface CancelledNotification extends JSONRPCNotification { @@ -322,6 +346,43 @@ export interface ClientCapabilities { * Present if the client supports elicitation from the server. */ elicitation?: { form?: object; url?: object }; + + /** + * Present if the client supports task-augmented requests. + */ + tasks?: { + /** + * Whether this client supports tasks/list. + */ + list?: object; + /** + * Whether this client supports tasks/cancel. + */ + cancel?: object; + /** + * Specifies which request types can be augmented with tasks. + */ + requests?: { + /** + * Task support for sampling-related requests. + */ + sampling?: { + /** + * Whether the client supports task-augmented sampling/createMessage requests. + */ + createMessage?: object; + }; + /** + * Task support for elicitation-related requests. + */ + elicitation?: { + /** + * Whether the client supports task-augmented elicitation/create requests. + */ + create?: object; + }; + }; + }; } /** @@ -373,6 +434,33 @@ export interface ServerCapabilities { */ listChanged?: boolean; }; + /** + * Present if the server supports task-augmented requests. + */ + tasks?: { + /** + * Whether this server supports tasks/list. + */ + list?: object; + /** + * Whether this server supports tasks/cancel. + */ + cancel?: object; + /** + * Specifies which request types can be augmented with tasks. + */ + requests?: { + /** + * Task support for tool-related requests. + */ + tools?: { + /** + * Whether the server supports task-augmented tools/call requests. + */ + call?: object; + }; + }; + }; } /** @@ -622,7 +710,7 @@ export interface ResourceRequestParams extends RequestParams { * @category `resources/read` */ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -export interface ReadResourceRequestParams extends ResourceRequestParams { } +export interface ReadResourceRequestParams extends ResourceRequestParams {} /** * Sent from the client to the server, to read a specific resource URI. @@ -659,7 +747,7 @@ export interface ResourceListChangedNotification extends JSONRPCNotification { * @category `resources/subscribe` */ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -export interface SubscribeRequestParams extends ResourceRequestParams { } +export interface SubscribeRequestParams extends ResourceRequestParams {} /** * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes. @@ -677,7 +765,7 @@ export interface SubscribeRequest extends JSONRPCRequest { * @category `resources/unsubscribe` */ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -export interface UnsubscribeRequestParams extends ResourceRequestParams { } +export interface UnsubscribeRequestParams extends ResourceRequestParams {} /** * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request. @@ -1053,7 +1141,7 @@ export interface CallToolResult extends Result { * * @category `tools/call` */ -export interface CallToolRequestParams extends RequestParams { +export interface CallToolRequestParams extends TaskAugmentedRequestParams { /** * The name of the tool. */ @@ -1140,6 +1228,26 @@ export interface ToolAnnotations { openWorldHint?: boolean; } +/** + * Execution-related properties for a tool. + * + * @category `tools/list` + */ +export interface ToolExecution { + /** + * Indicates whether this tool supports task-augmented execution. + * This allows clients to handle long-running operations through polling + * the task system. + * + * - "forbidden": Tool does not support task-augmented execution (default when absent) + * - "optional": Tool may support task-augmented execution + * - "required": Tool requires task-augmented execution + * + * Default: "forbidden" + */ + taskSupport?: "forbidden" | "optional" | "required"; +} + /** * Definition for a tool the client can call. * @@ -1157,16 +1265,26 @@ export interface Tool extends BaseMetadata, Icons { * A JSON Schema object defining the expected parameters for the tool. */ inputSchema: { + $schema?: string; type: "object"; properties?: { [key: string]: object }; required?: string[]; }; + /** + * Execution-related properties for this tool. + */ + execution?: ToolExecution; + /** * An optional JSON Schema object defining the structure of the tool's output returned in * the structuredContent field of a CallToolResult. + * + * Defaults to JSON Schema 2020-12 when no explicit $schema is provided. + * Currently restricted to type: "object" at the root level. */ outputSchema?: { + $schema?: string; type: "object"; properties?: { [key: string]: object }; required?: string[]; @@ -1185,6 +1303,206 @@ export interface Tool extends BaseMetadata, Icons { _meta?: { [key: string]: unknown }; } +/* Tasks */ + +/** + * The status of a task. + * + * @category `tasks` + */ +export type TaskStatus = + | "working" // The request is currently being processed + | "input_required" // The task is waiting for input (e.g., elicitation or sampling) + | "completed" // The request completed successfully and results are available + | "failed" // The associated request did not complete successfully. For tool calls specifically, this includes cases where the tool call result has `isError` set to true. + | "cancelled"; // The request was cancelled before completion + +/** + * Metadata for augmenting a request with task execution. + * Include this in the `task` field of the request parameters. + * + * @category `tasks` + */ +export interface TaskMetadata { + /** + * Requested duration in milliseconds to retain task from creation. + */ + ttl?: number; +} + +/** + * Metadata for associating messages with a task. + * Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`. + * + * @category `tasks` + */ +export interface RelatedTaskMetadata { + /** + * The task identifier this message is associated with. + */ + taskId: string; +} + +/** + * Data associated with a task. + * + * @category `tasks` + */ +export interface Task { + /** + * The task identifier. + */ + taskId: string; + + /** + * Current task state. + */ + status: TaskStatus; + + /** + * Optional human-readable message describing the current task state. + * This can provide context for any status, including: + * - Reasons for "cancelled" status + * - Summaries for "completed" status + * - Diagnostic information for "failed" status (e.g., error details, what went wrong) + */ + statusMessage?: string; + + /** + * ISO 8601 timestamp when the task was created. + */ + createdAt: string; + + /** + * ISO 8601 timestamp when the task was last updated. + */ + lastUpdatedAt: string; + + /** + * Actual retention duration from creation in milliseconds, null for unlimited. + */ + ttl: number | null; + + /** + * Suggested polling interval in milliseconds. + */ + pollInterval?: number; +} + +/** + * A response to a task-augmented request. + * + * @category `tasks` + */ +export interface CreateTaskResult extends Result { + task: Task; +} + +/** + * A request to retrieve the state of a task. + * + * @category `tasks/get` + */ +export interface GetTaskRequest extends JSONRPCRequest { + method: "tasks/get"; + params: { + /** + * The task identifier to query. + */ + taskId: string; + }; +} + +/** + * The response to a tasks/get request. + * + * @category `tasks/get` + */ +export type GetTaskResult = Result & Task; + +/** + * A request to retrieve the result of a completed task. + * + * @category `tasks/result` + */ +export interface GetTaskPayloadRequest extends JSONRPCRequest { + method: "tasks/result"; + params: { + /** + * The task identifier to retrieve results for. + */ + taskId: string; + }; +} + +/** + * The response to a tasks/result request. + * The structure matches the result type of the original request. + * For example, a tools/call task would return the CallToolResult structure. + * + * @category `tasks/result` + */ +export interface GetTaskPayloadResult extends Result { + [key: string]: unknown; +} + +/** + * A request to cancel a task. + * + * @category `tasks/cancel` + */ +export interface CancelTaskRequest extends JSONRPCRequest { + method: "tasks/cancel"; + params: { + /** + * The task identifier to cancel. + */ + taskId: string; + }; +} + +/** + * The response to a tasks/cancel request. + * + * @category `tasks/cancel` + */ +export type CancelTaskResult = Result & Task; + +/** + * A request to retrieve a list of tasks. + * + * @category `tasks/list` + */ +export interface ListTasksRequest extends PaginatedRequest { + method: "tasks/list"; +} + +/** + * The response to a tasks/list request. + * + * @category `tasks/list` + */ +export interface ListTasksResult extends PaginatedResult { + tasks: Task[]; +} + +/** + * Parameters for a `notifications/tasks/status` notification. + * + * @category `notifications/tasks/status` + */ +export type TaskStatusNotificationParams = NotificationParams & Task; + +/** + * 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. + * + * @category `notifications/tasks/status` + */ +export interface TaskStatusNotification extends JSONRPCNotification { + method: "notifications/tasks/status"; + params: TaskStatusNotificationParams; +} + /* Logging */ /** @@ -1263,7 +1581,7 @@ export type LoggingLevel = * * @category `sampling/createMessage` */ -export interface CreateMessageRequestParams extends RequestParams { +export interface CreateMessageRequestParams extends TaskAugmentedRequestParams { messages: SamplingMessage[]; /** * The server's preferences for which model to select. The client MAY ignore these preferences. @@ -1335,7 +1653,9 @@ export interface CreateMessageRequest extends JSONRPCRequest { } /** - * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it. + * The client's response to a sampling/createMessage request from the server. + * The client should inform the user before returning the sampled message, to allow them + * to inspect the response (human in the loop) and decide whether to allow the server to see it. * * @category `sampling/createMessage` */ @@ -1838,7 +2158,7 @@ export interface RootsListChangedNotification extends JSONRPCNotification { * * @category `elicitation/create` */ -export interface ElicitRequestFormParams extends RequestParams { +export interface ElicitRequestFormParams extends TaskAugmentedRequestParams { /** * The elicitation mode. */ @@ -1868,7 +2188,7 @@ export interface ElicitRequestFormParams extends RequestParams { * * @category `elicitation/create` */ -export interface ElicitRequestURLParams extends RequestParams { +export interface ElicitRequestURLParams extends TaskAugmentedRequestParams { /** * The elicitation mode. */ @@ -2200,21 +2520,30 @@ export type ClientRequest = | SubscribeRequest | UnsubscribeRequest | CallToolRequest - | ListToolsRequest; + | ListToolsRequest + | GetTaskRequest + | GetTaskPayloadRequest + | ListTasksRequest + | CancelTaskRequest; /** @internal */ export type ClientNotification = | CancelledNotification | ProgressNotification | InitializedNotification - | RootsListChangedNotification; + | RootsListChangedNotification + | TaskStatusNotification; /** @internal */ export type ClientResult = | EmptyResult | CreateMessageResult | ListRootsResult - | ElicitResult; + | ElicitResult + | GetTaskResult + | GetTaskPayloadResult + | ListTasksResult + | CancelTaskResult; /* Server messages */ /** @internal */ @@ -2222,7 +2551,11 @@ export type ServerRequest = | PingRequest | CreateMessageRequest | ListRootsRequest - | ElicitRequest; + | ElicitRequest + | GetTaskRequest + | GetTaskPayloadRequest + | ListTasksRequest + | CancelTaskRequest; /** @internal */ export type ServerNotification = @@ -2233,7 +2566,8 @@ export type ServerNotification = | ResourceListChangedNotification | ToolListChangedNotification | PromptListChangedNotification - | ElicitationCompleteNotification; + | ElicitationCompleteNotification + | TaskStatusNotification; /** @internal */ export type ServerResult = @@ -2246,4 +2580,8 @@ export type ServerResult = | ListResourcesResult | ReadResourceResult | CallToolResult - | ListToolsResult; + | ListToolsResult + | GetTaskResult + | GetTaskPayloadResult + | ListTasksResult + | CancelTaskResult; diff --git a/src/types.ts b/src/types.ts index 744877db1..7e9f589f0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -188,7 +188,7 @@ export enum ErrorCode { export const JSONRPCErrorSchema = z .object({ jsonrpc: z.literal(JSONRPC_VERSION), - id: RequestIdSchema, + id: RequestIdSchema.optional(), error: z.object({ /** * The error type that occurred. @@ -221,8 +221,10 @@ export const CancelledNotificationParamsSchema = NotificationsParamsSchema.exten * The ID of the request to cancel. * * This MUST correspond to the ID of a request previously issued in the same direction. + * This MUST be provided for cancelling non-task requests. + * This MUST NOT be used for cancelling tasks (use the `tasks/cancel` request instead). */ - requestId: RequestIdSchema, + requestId: RequestIdSchema.optional(), /** * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user. */