Skip to content

Commit f152a4d

Browse files
committed
Pass request _meta to request handlers extra param
1 parent 56b0427 commit f152a4d

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/shared/protocol.ts

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
RequestId,
2222
Result,
2323
ServerCapabilities,
24+
RequestMeta,
2425
} from "../types.js";
2526
import { Transport } from "./transport.js";
2627

@@ -114,6 +115,11 @@ export type RequestHandlerExtra<SendRequestT extends Request,
114115
*/
115116
sessionId?: string;
116117

118+
/**
119+
* Metadata from the original request.
120+
*/
121+
_meta?: RequestMeta;
122+
117123
/**
118124
* Sends a notification that relates to the current request being handled.
119125
*
@@ -355,6 +361,7 @@ export abstract class Protocol<
355361
const extra: RequestHandlerExtra<SendRequestT, SendNotificationT> = {
356362
signal: abortController.signal,
357363
sessionId: this._transport?.sessionId,
364+
_meta: request.params?._meta,
358365
sendNotification:
359366
(notification) =>
360367
this.notification(notification, { relatedRequestId: request.id }),

src/types.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ export const ProgressTokenSchema = z.union([z.string(), z.number().int()]);
1919
*/
2020
export const CursorSchema = z.string();
2121

22+
const RequestMetaSchema = z
23+
.object({
24+
/**
25+
* If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
26+
*/
27+
progressToken: z.optional(ProgressTokenSchema),
28+
})
29+
.passthrough();
30+
2231
const BaseRequestParamsSchema = z
2332
.object({
24-
_meta: z.optional(
25-
z
26-
.object({
27-
/**
28-
* If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
29-
*/
30-
progressToken: z.optional(ProgressTokenSchema),
31-
})
32-
.passthrough(),
33-
),
33+
_meta: z.optional(RequestMetaSchema),
3434
})
3535
.passthrough();
3636

@@ -1173,6 +1173,7 @@ type Infer<Schema extends ZodTypeAny> = Flatten<z.infer<Schema>>;
11731173
export type ProgressToken = Infer<typeof ProgressTokenSchema>;
11741174
export type Cursor = Infer<typeof CursorSchema>;
11751175
export type Request = Infer<typeof RequestSchema>;
1176+
export type RequestMeta = Infer<typeof RequestMetaSchema>;
11761177
export type Notification = Infer<typeof NotificationSchema>;
11771178
export type Result = Infer<typeof ResultSchema>;
11781179
export type RequestId = Infer<typeof RequestIdSchema>;

0 commit comments

Comments
 (0)