Skip to content

fix: add missing size field to ResourceSchema#1574

Merged
felixweinberger merged 1 commit into
modelcontextprotocol:mainfrom
olaservo:fix/resource-schema-size-field
Mar 26, 2026
Merged

fix: add missing size field to ResourceSchema#1574
felixweinberger merged 1 commit into
modelcontextprotocol:mainfrom
olaservo:fix/resource-schema-size-field

Conversation

@olaservo

Copy link
Copy Markdown
Member

Summary

  • Adds the optional size number field to ResourceSchema in the Zod schema definition, matching the MCP specification (added in spec revision 2025-06-18)
  • The spec.types.ts (auto-generated from spec) already includes size?: number on the Resource interface, but the hand-maintained Zod schema was missing it
  • Downstream schemas (ResourceLinkSchema, ListResourcesResultSchema) inherit the field automatically

Fixes #1573

Test plan

  • pnpm typecheck:all passes
  • pnpm --filter @modelcontextprotocol/core test — all 440 tests pass
  • Verified ResourceSchema.shape.size exists after the change

🤖 Generated with Claude Code

@olaservo olaservo requested a review from a team as a code owner February 22, 2026 15:38
@changeset-bot

changeset-bot Bot commented Feb 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 79f3120

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Feb 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1574

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1574

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1574

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1574

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1574

commit: 79f3120

Adds the optional `size` field to `ResourceSchema` to match the MCP
specification. The auto-generated spec types already include
`size?: number` on the Resource interface, but the hand-maintained
Zod schema was missing it.

Rebased onto main after schemas moved from types.ts to schemas.ts.
@felixweinberger felixweinberger force-pushed the fix/resource-schema-size-field branch from e0f61c4 to 79f3120 Compare March 26, 2026 16:07
@felixweinberger felixweinberger merged commit 379392d into modelcontextprotocol:main Mar 26, 2026
12 checks passed
yuki3738 added a commit to yuki3738/ruby-sdk that referenced this pull request Jun 7, 2026
## Motivation and Context

The MCP specification defines an optional `size` field on the `Resource`
type, added in spec revision 2025-06-18 and retained in 2025-11-25:
https://modelcontextprotocol.io/specification/2025-11-25/server/resources

> 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.

`MCP::Resource` was missing this field, so servers had no way to declare a
resource's byte size. Without it, hosts cannot show file sizes or estimate
context window usage before reading the resource contents.

This aligns the Ruby SDK with the spec, matching the TypeScript SDK
(modelcontextprotocol/typescript-sdk#1574).

## How Has This Been Tested?

Added tests in `test/mcp/resource_test.rb`:

- `#to_h` omits `size` when nil
- `#to_h` includes `size` when present

The full unit suite and RuboCop pass locally.

## Breaking Changes

None. `size:` is a new optional keyword argument defaulting to `nil`, and it
is omitted from `#to_h` output when not set, so existing callers are unaffected.
yuki3738 added a commit to yuki3738/ruby-sdk that referenced this pull request Jun 7, 2026
## Motivation and Context

The MCP specification defines an optional `size` field on the `Resource`
type, added in spec revision 2025-06-18 and retained in 2025-11-25:
https://modelcontextprotocol.io/specification/2025-11-25/server/resources

> 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.

`MCP::Resource` was missing this field, so servers had no way to declare a
resource's byte size. Without it, hosts cannot show file sizes or estimate
context window usage before reading the resource contents.

This aligns the Ruby SDK with the spec, matching the TypeScript SDK
(modelcontextprotocol/typescript-sdk#1574).

## How Has This Been Tested?

Added tests in `test/mcp/resource_test.rb`:

- `#to_h` omits `size` when nil
- `#to_h` includes `size` when present
- `#to_h` includes `size` when zero (distinguishes an unset size from a
  0-byte resource)

The full unit suite and RuboCop pass locally.

## Breaking Changes

None. `size:` is a new optional keyword argument defaulting to `nil`, and it
is omitted from `#to_h` output when not set, so existing callers are unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResourceSchema missing size field from MCP spec

2 participants