Skip to content

Add Content::ResourceLink class for resource link content type - #710

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
yuki3738:add_content_resource_link
Nov 22, 2026
Merged

koic merged 1 commit into
modelcontextprotocol:mainfrom
yuki3738:add_content_resource_link

Conversation

@yuki3738

Copy link
Copy Markdown
Contributor

Motivation and Context

The MCP spec defines a resource link content type (since 2025-06-18) that lets a tool return a link to
a resource instead of its contents, but the SDK had no corresponding class. MCP::Content covered the other
four members of the specification's ContentBlock (text, image, audio, and embedded resource) and had
no helper for building a resource link.

Add Content::ResourceLink, which wraps a resource object and serializes it via to_h, as
Content::EmbeddedResource (#244) does for resource contents. In the specification, ResourceLink extends
Resource with type: "resource_link", so the link is the resource's own to_h with that type added and
carries the resource's title, icons, annotations, size, and _meta. It accepts a resource built with
MCP::Resource.new and a class-based MCP::Resource. The tools page documents it next to the other content
types.

https://modelcontextprotocol.io/specification/2026-07-28/server/tools#resource-links

How Has This Been Tested?

Added tests to test/mcp/content_test.rb covering the shape in the specification, the optional fields the link
carries from the resource (title, icons, annotations, size, and _meta), and a class-based resource.
At fb2e425 the three tests fail with NameError.

Breaking Changes

None. Content::ResourceLink is a new class.

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

Comment thread lib/mcp/content.rb Outdated
end
end

class ResourceLink

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order here differs from the one in docs/_server/tools.md (L440: "Image, Audio, Resource Links, and Embedded Resources"). The docs follow the spec, so could ResourceLink go before EmbeddedResource?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I moved ResourceLink before EmbeddedResource to follow the order of the spec's ContentBlock.

Comment thread docs/_server/tools.md Outdated
```

A resource link wraps an `MCP::Resource`, allowing a tool to point the client at a resource to read or subscribe to instead of returning
its contents. The linked resource does not have to be one the server returns from `resources/list`. To let the client read it with

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the docs say that returning a link does not make the resource readable? A resources/read of that URI goes through the read handler like any other, so the handler is where the read is authorized. The current sentence could be read the other way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I reworded it to say that returning a link does not make the resource readable: a resources/read of its URI goes through the read handler like any other request, so the handler is where the read is authorized. I also moved this after the example so the sentence before it only introduces the example.

## Motivation and Context

The MCP spec defines a resource link content type (since 2025-06-18) that lets a tool return a link to
a resource instead of its contents, but the SDK had no corresponding class. `MCP::Content` covered the other
four members of the specification's `ContentBlock` (text, image, audio, and embedded resource) and had
no helper for building a resource link.

Add `Content::ResourceLink`, which wraps a resource object and serializes it via `to_h`, as
`Content::EmbeddedResource` (modelcontextprotocol#244) does for resource contents. In the specification, `ResourceLink` extends
`Resource` with `type: "resource_link"`, so the link is the resource's own `to_h` with that `type` added and
carries the resource's `title`, `icons`, `annotations`, `size`, and `_meta`. It accepts a resource built with
`MCP::Resource.new` and a class-based `MCP::Resource`. The tools page documents it next to the other content
types.

https://modelcontextprotocol.io/specification/2026-07-28/server/tools#resource-links

## How Has This Been Tested?

Added tests to test/mcp/content_test.rb covering the shape in the specification, the optional fields the link
carries from the resource (`title`, `icons`, `annotations`, `size`, and `_meta`), and a class-based resource.
At fb2e425 the three tests fail with `NameError`.

## Breaking Changes

None. `Content::ResourceLink` is a new class.
@yuki3738
yuki3738 force-pushed the add_content_resource_link branch from 577f3f8 to 5870fec Compare November 22, 2026 16:28
@koic
koic merged commit b20fe62 into modelcontextprotocol:main Nov 22, 2026
13 checks passed
@yuki3738
yuki3738 deleted the add_content_resource_link branch November 23, 2026 04:27
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.

2 participants