Skip to content

Add size field to MCP::Resource per MCP specification#1

Closed
yuki3738 wants to merge 1 commit into
mainfrom
add_size_field_to_resource
Closed

Add size field to MCP::Resource per MCP specification#1
yuki3738 wants to merge 1 commit into
mainfrom
add_size_field_to_resource

Conversation

@yuki3738

@yuki3738 yuki3738 commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Note: This is a practice / self-review PR inside my own fork. Not the upstream contribution.

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. 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, omitted from #to_h when not set.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@yuki3738 yuki3738 force-pushed the add_size_field_to_resource branch from f06c576 to 4f33c05 Compare June 7, 2026 09:46
## 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.
@yuki3738 yuki3738 force-pushed the add_size_field_to_resource branch from 4f33c05 to 91ff179 Compare June 7, 2026 12:10
@yuki3738

yuki3738 commented Jun 7, 2026

Copy link
Copy Markdown
Owner Author

Practice/self-review PR. Superseded by the upstream PR modelcontextprotocol#393. Closing.

@yuki3738 yuki3738 closed this Jun 7, 2026
@yuki3738 yuki3738 deleted the add_size_field_to_resource branch June 7, 2026 16:57
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.

1 participant