diff --git a/schema/draft/schema.json b/schema/draft/schema.json index 05552b38d..76b2bf523 100644 --- a/schema/draft/schema.json +++ b/schema/draft/schema.json @@ -20,6 +20,40 @@ }, "type": "object" }, + "AsyncOperation": { + "description": "Information about an asynchronous operation.", + "properties": { + "errorMessage": { + "description": "Error message if the operation failed.", + "type": "string" + }, + "expiryTime": { + "description": "Time in seconds when the operation will expire.", + "type": "integer" + }, + "requestId": { + "description": "The ID of the request that created this operation.", + "type": [ + "string", + "integer" + ] + }, + "resourceUri": { + "description": "The URI of the resource that will contain the result when ready.", + "type": "string" + }, + "status": { + "$ref": "#/definitions/OperationStatus", + "description": "Current status of the operation." + } + }, + "required": [ + "requestId", + "resourceUri", + "status" + ], + "type": "object" + }, "AudioContent": { "description": "Audio provided to or from an LLM.", "properties": { @@ -92,6 +126,58 @@ ], "type": "object" }, + "CallToolAsyncRequest": { + "description": "Used by the client to invoke a tool asynchronously.", + "properties": { + "method": { + "const": "tools/callAsync", + "type": "string" + }, + "params": { + "$ref": "#/definitions/CallToolAsyncRequestParams" + } + }, + "required": [ + "method", + "params" + ], + "type": "object" + }, + "CallToolAsyncRequestParams": { + "description": "Parameters for calling a tool asynchronously.", + "properties": { + "arguments": { + "additionalProperties": {}, + "description": "Arguments to pass to the tool.", + "type": "object" + }, + "keepAlive": { + "description": "Number of seconds to keep the result available.", + "type": "integer" + }, + "name": { + "description": "Name of the tool to call.", + "type": "string" + } + }, + "required": [ + "name" + ], + "type": "object" + }, + "CallToolAsyncResult": { + "description": "The server's response to an asynchronous tool call request.", + "properties": { + "operation": { + "$ref": "#/definitions/AsyncOperation", + "description": "Information about the asynchronous operation." + } + }, + "required": [ + "operation" + ], + "type": "object" + }, "CallToolRequest": { "description": "Used by the client to invoke a tool provided by the server.", "properties": { @@ -164,6 +250,52 @@ ], "type": "object" }, + "CancelOperationRequest": { + "description": "Used by the client to cancel an operation.", + "properties": { + "method": { + "const": "operations/cancel", + "type": "string" + }, + "params": { + "$ref": "#/definitions/CancelOperationRequestParams" + } + }, + "required": [ + "method", + "params" + ], + "type": "object" + }, + "CancelOperationRequestParams": { + "description": "Parameters for cancelling an operation.", + "properties": { + "requestId": { + "description": "The ID of the request to cancel.", + "type": [ + "string", + "integer" + ] + } + }, + "required": [ + "requestId" + ], + "type": "object" + }, + "CancelOperationResult": { + "description": "The server's response to an operation cancellation request.", + "properties": { + "operation": { + "$ref": "#/definitions/AsyncOperation", + "description": "The updated state of the operation." + } + }, + "required": [ + "operation" + ], + "type": "object" + }, "CancelledNotification": { "description": "This notification can be sent by either side to indicate that it is cancelling a previously-issued request.\n\nThe request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished.\n\nThis notification indicates that the result will be unused, so any associated processing SHOULD cease.\n\nA client MUST NOT attempt to cancel its `initialize` request.", "properties": { @@ -646,6 +778,52 @@ ], "type": "object" }, + "GetOperationRequest": { + "description": "Used by the client to check an operation's status.", + "properties": { + "method": { + "const": "operations/get", + "type": "string" + }, + "params": { + "$ref": "#/definitions/GetOperationRequestParams" + } + }, + "required": [ + "method", + "params" + ], + "type": "object" + }, + "GetOperationRequestParams": { + "description": "Parameters for getting the status of an operation.", + "properties": { + "requestId": { + "description": "The ID of the request to check.", + "type": [ + "string", + "integer" + ] + } + }, + "required": [ + "requestId" + ], + "type": "object" + }, + "GetOperationResult": { + "description": "The server's response to an operation status check.", + "properties": { + "operation": { + "$ref": "#/definitions/AsyncOperation", + "description": "The current state of the operation." + } + }, + "required": [ + "operation" + ], + "type": "object" + }, "GetPromptRequest": { "description": "Used by the client to get a prompt provided by the server.", "properties": { @@ -1217,6 +1395,50 @@ ], "type": "object" }, + "ListToolsAsyncRequest": { + "properties": { + "method": { + "const": "tools/listAsync", + "type": "string" + }, + "params": { + "properties": { + "cursor": { + "description": "An opaque token representing the current pagination position.\nIf provided, the server should return results starting after this cursor.", + "type": "string" + } + }, + "type": "object" + } + }, + "required": [ + "method" + ], + "type": "object" + }, + "ListToolsAsyncResult": { + "properties": { + "_meta": { + "additionalProperties": {}, + "description": "This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.", + "type": "object" + }, + "nextCursor": { + "description": "An opaque token representing the pagination position after the last returned result.\nIf present, there may be more results available.", + "type": "string" + }, + "tools": { + "items": { + "$ref": "#/definitions/Tool" + }, + "type": "array" + } + }, + "required": [ + "tools" + ], + "type": "object" + }, "ListToolsRequest": { "description": "Sent from the client to request a list of tools the server has.", "properties": { @@ -1401,6 +1623,18 @@ ], "type": "object" }, + "OperationStatus": { + "description": "The status of an asynchronous operation.", + "enum": [ + "ACTIVE", + "DELETE_UNSUCCESSFUL", + "DELETING", + "FAILED", + "PENDING", + "UPDATING" + ], + "type": "string" + }, "PaginatedRequest": { "properties": { "method": { @@ -1685,6 +1919,9 @@ }, { "$ref": "#/definitions/BlobResourceContents" + }, + { + "$ref": "#/definitions/ToolResultResourceContents" } ] }, @@ -2243,6 +2480,10 @@ "$ref": "#/definitions/ToolAnnotations", "description": "Optional additional tool information." }, + "async": { + "description": "Whether the tool is asynchronous.\n\nDefault: false", + "type": "boolean" + }, "description": { "description": "A human-readable description of the tool.\n\nThis can be used by clients to improve the LLM's understanding of available tools. It can be thought of like a \"hint\" to the model.", "type": "string" @@ -2362,6 +2603,29 @@ ], "type": "object" }, + "ToolResultResourceContents": { + "description": "Tool result contents of a resource.", + "properties": { + "mimeType": { + "description": "The MIME type of this resource, if known.", + "type": "string" + }, + "toolResult": { + "$ref": "#/definitions/CallToolResult", + "description": "The result of a tool call." + }, + "uri": { + "description": "The URI of this resource.", + "format": "uri", + "type": "string" + } + }, + "required": [ + "toolResult", + "uri" + ], + "type": "object" + }, "UnsubscribeRequest": { "description": "Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.", "properties": { diff --git a/schema/draft/schema.ts b/schema/draft/schema.ts index 0852bad4b..f6936bcfe 100644 --- a/schema/draft/schema.ts +++ b/schema/draft/schema.ts @@ -388,7 +388,7 @@ export interface ReadResourceRequest extends Request { * The server's response to a resources/read request from the client. */ export interface ReadResourceResult extends Result { - contents: (TextResourceContents | BlobResourceContents)[]; + contents: (TextResourceContents | BlobResourceContents | ToolResultResourceContents)[]; } /** @@ -672,6 +672,21 @@ export interface PromptListChangedNotification extends Notification { method: "notifications/prompts/list_changed"; } +/* Async Tools / +/* +Sent from the client to request a list of async tools the server has. + */ +export interface ListToolsAsyncRequest extends PaginatedRequest { + method: "tools/listAsync"; +} + +/* +The server's response to a tools/listAsync request from the client. + */ +export interface ListToolsAsyncResult extends PaginatedResult { + tools: Tool[]; // return Tools which has `async` as True +} + /* Tools */ /** * Sent from the client to request a list of tools the server has. @@ -687,6 +702,145 @@ export interface ListToolsResult extends PaginatedResult { tools: Tool[]; } +/** + * The status of an asynchronous operation. + */ +export type OperationStatus = "PENDING" | "ACTIVE" | "UPDATING" | "FAILED" | "DELETING" | "DELETE_UNSUCCESSFUL"; + +/** + * Information about an asynchronous operation. + */ +export interface AsyncOperation { + /** + * The ID of the request that created this operation. + */ + requestId: string | number; + + /** + * Current status of the operation. + */ + status: OperationStatus; + + /** + * The URI of the resource that will contain the result when ready. + */ + resourceUri: string; + + /** + * Time in seconds when the operation will expire. + */ + expiryTime?: number; + + /** + * Error message if the operation failed. + */ + errorMessage?: string; +} + +/** + * Tool result contents of a resource. + */ +export interface ToolResultResourceContents extends ResourceContents { + /** + * The result of a tool call. + */ + toolResult: CallToolResult; +} + +/** + * Parameters for calling a tool asynchronously. + */ +export interface CallToolAsyncRequestParams { + /** + * Name of the tool to call. + */ + name: string; + + /** + * Arguments to pass to the tool. + */ + arguments?: { [key: string]: unknown }; + + /** + * Number of seconds to keep the result available. + */ + keepAlive?: number; +} + +/** + * Used by the client to invoke a tool asynchronously. + */ +export interface CallToolAsyncRequest { + method: "tools/callAsync"; + params: CallToolAsyncRequestParams; +} + +/** + * The server's response to an asynchronous tool call request. + */ +export interface CallToolAsyncResult { + /** + * Information about the asynchronous operation. + */ + operation: AsyncOperation; +} + +/** + * Parameters for getting the status of an operation. + */ +export interface GetOperationRequestParams { + /** + * The ID of the request to check. + */ + requestId: string | number; +} + +/** + * Used by the client to check an operation's status. + */ +export interface GetOperationRequest { + method: "operations/get"; + params: GetOperationRequestParams; +} + +/** + * The server's response to an operation status check. + */ +export interface GetOperationResult { + /** + * The current state of the operation. + */ + operation: AsyncOperation; +} + +/** + * Parameters for cancelling an operation. + */ +export interface CancelOperationRequestParams { + /** + * The ID of the request to cancel. + */ + requestId: string | number; +} + +/** + * Used by the client to cancel an operation. + */ +export interface CancelOperationRequest { + method: "operations/cancel"; + params: CancelOperationRequestParams; +} + +/** + * The server's response to an operation cancellation request. + */ +export interface CancelOperationResult { + /** + * The updated state of the operation. + */ + operation: AsyncOperation; +} + /** * The server's response to a tool call. */ @@ -829,6 +983,13 @@ export interface Tool { * Optional additional tool information. */ annotations?: ToolAnnotations; + + /** + * Whether the tool is asynchronous. + * + * Default: false + */ + async?: boolean; } /* Logging */