Repository navigation
Add Content::ResourceLink class for resource link content type - #710
Conversation
| end | ||
| end | ||
|
|
||
| class ResourceLink |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Thanks. I moved ResourceLink before EmbeddedResource to follow the order of the spec's ContentBlock.
| ``` | ||
|
|
||
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
577f3f8 to
5870fec
Compare
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::Contentcovered the otherfour members of the specification's
ContentBlock(text, image, audio, and embedded resource) and hadno helper for building a resource link.
Add
Content::ResourceLink, which wraps a resource object and serializes it viato_h, asContent::EmbeddedResource(#244) does for resource contents. In the specification,ResourceLinkextendsResourcewithtype: "resource_link", so the link is the resource's ownto_hwith thattypeadded andcarries the resource's
title,icons,annotations,size, and_meta. It accepts a resource built withMCP::Resource.newand a class-basedMCP::Resource. The tools page documents it next to the other contenttypes.
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::ResourceLinkis a new class.Types of changes
Checklist