Skip to content

Commit 347e890

Browse files
committed
Add types for cancellation notifications
1 parent d0c83e9 commit 347e890

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/types.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,33 @@ export const JSONRPCMessageSchema = z.union([
151151
*/
152152
export const EmptyResultSchema = ResultSchema.strict();
153153

154+
/* Cancellation */
155+
/**
156+
* This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
157+
*
158+
* The 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.
159+
*
160+
* This notification indicates that the result will be unused, so any associated processing SHOULD cease.
161+
*
162+
* A client MUST NOT attempt to cancel its `initialize` request.
163+
*/
164+
export const CancelledNotificationSchema = NotificationSchema.extend({
165+
method: z.literal("cancelled"),
166+
params: BaseNotificationParamsSchema.extend({
167+
/**
168+
* The ID of the request to cancel.
169+
*
170+
* This MUST correspond to the ID of a request previously issued in the same direction.
171+
*/
172+
requestId: RequestIdSchema,
173+
174+
/**
175+
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
176+
*/
177+
reason: z.string().optional(),
178+
}),
179+
});
180+
154181
/* Initialization */
155182
/**
156183
* Describes the name and version of an MCP implementation.
@@ -1030,6 +1057,7 @@ export const ClientRequestSchema = z.union([
10301057
]);
10311058

10321059
export const ClientNotificationSchema = z.union([
1060+
CancelledNotificationSchema,
10331061
ProgressNotificationSchema,
10341062
InitializedNotificationSchema,
10351063
RootsListChangedNotificationSchema,
@@ -1049,6 +1077,7 @@ export const ServerRequestSchema = z.union([
10491077
]);
10501078

10511079
export const ServerNotificationSchema = z.union([
1080+
CancelledNotificationSchema,
10521081
ProgressNotificationSchema,
10531082
LoggingMessageNotificationSchema,
10541083
ResourceUpdatedNotificationSchema,
@@ -1096,6 +1125,9 @@ export type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
10961125
/* Empty result */
10971126
export type EmptyResult = z.infer<typeof EmptyResultSchema>;
10981127

1128+
/* Cancellation */
1129+
export type CancelledNotification = z.infer<typeof CancelledNotificationSchema>;
1130+
10991131
/* Initialization */
11001132
export type Implementation = z.infer<typeof ImplementationSchema>;
11011133
export type ClientCapabilities = z.infer<typeof ClientCapabilitiesSchema>;

0 commit comments

Comments
 (0)