Skip to content

Commit 7473694

Browse files
authored
Merge pull request #328 from iamarcel/main
Pass request _meta to request handlers extra param
2 parents 1317767 + 75eb1c4 commit 7473694

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, TransportSendOptions } from "./transport.js";
2627
import { AuthInfo } from "../server/auth/types.js";
@@ -115,6 +116,11 @@ export type RequestHandlerExtra<SendRequestT extends Request,
115116
*/
116117
sessionId?: string;
117118

119+
/**
120+
* Metadata from the original request.
121+
*/
122+
_meta?: RequestMeta;
123+
118124
/**
119125
* The JSON-RPC ID of the request being handled.
120126
* This can be useful for tracking or logging purposes.
@@ -361,6 +367,7 @@ export abstract class Protocol<
361367
const fullExtra: RequestHandlerExtra<SendRequestT, SendNotificationT> = {
362368
signal: abortController.signal,
363369
sessionId: this._transport?.sessionId,
370+
_meta: request.params?._meta,
364371
sendNotification:
365372
(notification) =>
366373
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

@@ -1240,6 +1240,7 @@ type Infer<Schema extends ZodTypeAny> = Flatten<z.infer<Schema>>;
12401240
export type ProgressToken = Infer<typeof ProgressTokenSchema>;
12411241
export type Cursor = Infer<typeof CursorSchema>;
12421242
export type Request = Infer<typeof RequestSchema>;
1243+
export type RequestMeta = Infer<typeof RequestMetaSchema>;
12431244
export type Notification = Infer<typeof NotificationSchema>;
12441245
export type Result = Infer<typeof ResultSchema>;
12451246
export type RequestId = Infer<typeof RequestIdSchema>;

0 commit comments

Comments
 (0)