From f152a4dcf751f012e8d1c175aacc762c9af94e20 Mon Sep 17 00:00:00 2001 From: Marcel Samyn Date: Sun, 13 Apr 2025 09:36:42 +0200 Subject: [PATCH] Pass request _meta to request handlers extra param --- src/shared/protocol.ts | 7 +++++++ src/types.ts | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/shared/protocol.ts b/src/shared/protocol.ts index 07bfc02c..ab5e4d47 100644 --- a/src/shared/protocol.ts +++ b/src/shared/protocol.ts @@ -21,6 +21,7 @@ import { RequestId, Result, ServerCapabilities, + RequestMeta, } from "../types.js"; import { Transport } from "./transport.js"; @@ -114,6 +115,11 @@ export type RequestHandlerExtra = { signal: abortController.signal, sessionId: this._transport?.sessionId, + _meta: request.params?._meta, sendNotification: (notification) => this.notification(notification, { relatedRequestId: request.id }), diff --git a/src/types.ts b/src/types.ts index db6bf125..80919b76 100644 --- a/src/types.ts +++ b/src/types.ts @@ -19,18 +19,18 @@ export const ProgressTokenSchema = z.union([z.string(), z.number().int()]); */ export const CursorSchema = z.string(); +const RequestMetaSchema = z + .object({ + /** + * 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. + */ + progressToken: z.optional(ProgressTokenSchema), + }) + .passthrough(); + const BaseRequestParamsSchema = z .object({ - _meta: z.optional( - z - .object({ - /** - * 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. - */ - progressToken: z.optional(ProgressTokenSchema), - }) - .passthrough(), - ), + _meta: z.optional(RequestMetaSchema), }) .passthrough(); @@ -1173,6 +1173,7 @@ type Infer = Flatten>; export type ProgressToken = Infer; export type Cursor = Infer; export type Request = Infer; +export type RequestMeta = Infer; export type Notification = Infer; export type Result = Infer; export type RequestId = Infer;