Skip to content

Pass request _meta to request handlers extra param #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
RequestId,
Result,
ServerCapabilities,
RequestMeta,
} from "../types.js";
import { Transport } from "./transport.js";

Expand Down Expand Up @@ -114,6 +115,11 @@ export type RequestHandlerExtra<SendRequestT extends Request,
*/
sessionId?: string;

/**
* Metadata from the original request.
*/
_meta?: RequestMeta;

/**
* Sends a notification that relates to the current request being handled.
*
Expand Down Expand Up @@ -355,6 +361,7 @@ export abstract class Protocol<
const extra: RequestHandlerExtra<SendRequestT, SendNotificationT> = {
signal: abortController.signal,
sessionId: this._transport?.sessionId,
_meta: request.params?._meta,
sendNotification:
(notification) =>
this.notification(notification, { relatedRequestId: request.id }),
Expand Down
21 changes: 11 additions & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -1173,6 +1173,7 @@ type Infer<Schema extends ZodTypeAny> = Flatten<z.infer<Schema>>;
export type ProgressToken = Infer<typeof ProgressTokenSchema>;
export type Cursor = Infer<typeof CursorSchema>;
export type Request = Infer<typeof RequestSchema>;
export type RequestMeta = Infer<typeof RequestMetaSchema>;
export type Notification = Infer<typeof NotificationSchema>;
export type Result = Infer<typeof ResultSchema>;
export type RequestId = Infer<typeof RequestIdSchema>;
Expand Down