From 75eb1c431a0c972279a9bf05c3d4076bc8e25609 Mon Sep 17 00:00:00 2001 From: Marcel Samyn Date: Fri, 25 Apr 2025 14:42:59 +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 2a6bb7f2..4694929d 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, TransportSendOptions } from "./transport.js"; import { AuthInfo } from "../server/auth/types.js"; @@ -115,6 +116,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 17b485f8..daf9921e 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(); @@ -1240,6 +1240,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;