From d9cc4ab0b9a9a72a912b87fc7f1255c3e2afe40a Mon Sep 17 00:00:00 2001 From: olaservo Date: Sun, 22 Feb 2026 08:26:10 -0700 Subject: [PATCH] fix: add missing `size` field to ResourceSchema The MCP specification defines an optional `size?: number` field on the Resource interface (added in spec revision 2025-06-18), but the Zod schema was missing it. This adds the field so servers can declare resource sizes and hosts can display file sizes / estimate context window usage. Fixes modelcontextprotocol/typescript-sdk#1573 Co-Authored-By: Claude Opus 4.6 --- .changeset/add-resource-size-field.md | 5 +++++ src/types.ts | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 .changeset/add-resource-size-field.md diff --git a/.changeset/add-resource-size-field.md b/.changeset/add-resource-size-field.md new file mode 100644 index 000000000..92064689b --- /dev/null +++ b/.changeset/add-resource-size-field.md @@ -0,0 +1,5 @@ +--- +'@modelcontextprotocol/sdk': patch +--- + +Add missing `size` field to `ResourceSchema` to match the MCP specification diff --git a/src/types.ts b/src/types.ts index bdd2dfed0..e683a4e20 100644 --- a/src/types.ts +++ b/src/types.ts @@ -901,6 +901,13 @@ export const ResourceSchema = z.object({ */ mimeType: z.optional(z.string()), + /** + * The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known. + * + * This can be used by Hosts to display file sizes and estimate context window usage. + */ + size: z.optional(z.number()), + /** * Optional annotations for the client. */