Skip to content

Commit d0c83e9

Browse files
committed
Fix notification params schemas not permitting _meta
1 parent f6c986d commit d0c83e9

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

src/types.ts

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ export const RequestSchema = z.object({
3939
params: z.optional(BaseRequestParamsSchema),
4040
});
4141

42+
const BaseNotificationParamsSchema = z
43+
.object({
44+
/**
45+
* This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.
46+
*/
47+
_meta: z.optional(z.object({}).passthrough()),
48+
})
49+
.passthrough();
50+
4251
export const NotificationSchema = z.object({
4352
method: z.string(),
44-
params: z.optional(
45-
z
46-
.object({
47-
/**
48-
* This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.
49-
*/
50-
_meta: z.optional(z.object({}).passthrough()),
51-
})
52-
.passthrough(),
53-
),
53+
params: z.optional(BaseNotificationParamsSchema),
5454
});
5555

5656
export const ResultSchema = z
@@ -312,7 +312,7 @@ export const ProgressSchema = z
312312
*/
313313
export const ProgressNotificationSchema = NotificationSchema.extend({
314314
method: z.literal("notifications/progress"),
315-
params: ProgressSchema.extend({
315+
params: BaseNotificationParamsSchema.merge(ProgressSchema).extend({
316316
/**
317317
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
318318
*/
@@ -522,14 +522,12 @@ export const UnsubscribeRequestSchema = RequestSchema.extend({
522522
*/
523523
export const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
524524
method: z.literal("notifications/resources/updated"),
525-
params: z
526-
.object({
527-
/**
528-
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
529-
*/
530-
uri: z.string(),
531-
})
532-
.passthrough(),
525+
params: BaseNotificationParamsSchema.extend({
526+
/**
527+
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
528+
*/
529+
uri: z.string(),
530+
}),
533531
});
534532

535533
/* Prompts */
@@ -786,22 +784,20 @@ export const SetLevelRequestSchema = RequestSchema.extend({
786784
*/
787785
export const LoggingMessageNotificationSchema = NotificationSchema.extend({
788786
method: z.literal("notifications/message"),
789-
params: z
790-
.object({
791-
/**
792-
* The severity of this log message.
793-
*/
794-
level: LoggingLevelSchema,
795-
/**
796-
* An optional name of the logger issuing this message.
797-
*/
798-
logger: z.optional(z.string()),
799-
/**
800-
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
801-
*/
802-
data: z.unknown(),
803-
})
804-
.passthrough(),
787+
params: BaseNotificationParamsSchema.extend({
788+
/**
789+
* The severity of this log message.
790+
*/
791+
level: LoggingLevelSchema,
792+
/**
793+
* An optional name of the logger issuing this message.
794+
*/
795+
logger: z.optional(z.string()),
796+
/**
797+
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
798+
*/
799+
data: z.unknown(),
800+
}),
805801
});
806802

807803
/* Sampling */

0 commit comments

Comments
 (0)