Skip to content

Conversation

@bhosmer-ant
Copy link
Contributor

@bhosmer-ant bhosmer-ant commented May 30, 2025

Enables tool calls to return ResourceLinks (in addition to full EmbeddedResources) in results.

Motivation and Context

Returning resource links enables interaction flows where returning resource content inline is impractical.

ResourceLink reuses the Resource structure unchanged, but adds a necessary type tag for disambiguation in ContentBlock arrays.

How Has This Been Tested?

No testing yet.

Breaking Changes

Older clients will not be able to interpret the new content type.

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 TODO

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

Additional context

@connor4312
Copy link
Contributor

I would be happy to have and adopt this for VS Code 👍

@jonathanhefner
Copy link
Member

I think there is a use case for returning a temporary resource that can be read via resources/read but is not listed via resources/list. In which case, I think it would be useful to include all resource properties, such as mimeType and annotations (as @connor4312 mentioned). So would it be feasible to return Resource instead of ResourceReference?

@evalstate
Copy link
Member

We'd be far better off including Resource as it also has the LLM Facing description. And then at the same time we could add subscribable to Resource as I think that's missing. Happy to add to the PR

@evalstate
Copy link
Member

@bhosmer-ant if in agreement we switch to Resource we should also add this to the Prompt primitive too.

@davemssavage
Copy link

I think there is a use case for returning a temporary resource that can be read via resources/read but is not listed via resources/list. In which case, I think it would be useful to include all resource properties, such as mimeType and annotations (as @connor4312 mentioned). So would it be feasible to return Resource instead of ResourceReference?

I agree I've noted this idea in #617 as well in relation to the idea of sending back resources as part of progress notifications. I think the original motivation of resource is to find long lived static resources that the server holds. However I think there are a set of use cases for short lived temporary resources associated with a specific request.

This does open up the question of how long those resources are valid to avoid clogging up the server. I'm suggesting the idea of a keepAlive flag that tells the client how long it can expect the resource to be held by the server.

@bhosmer-ant
Copy link
Contributor Author

We'd be far better off including Resource as it also has the LLM Facing description.

@evalstate hey Shaun, yeah I think you and @jonathanhefner are totally right, Resource is better than ResourceReference here. (Going this way introduces ambiguity around whether resources/list is "total" - since we're now able to return resources from tool calls that may never appear in that listing - but I think that's fine.)

And then at the same time we could add subscribable to Resource as I think that's missing.

I'd like to leave subscribable to a separate PR/discussion, I think it's orthogonal to this change.

@bhosmer-ant if in agreement we switch to Resource we should also add this to the Prompt primitive too.

Yeah agreed. Actually I think it's worth factoring out

ContentBlock = TextContent | ImageContent | AudioContent | EmbeddedResource | Resource

and using it from both CallToolResult and and PromptMessage.

Happy to add to the PR

I mean, I'll take you up on it if you agree with the above, but also happy to do it if your offer has aged out! Just LMK (and 🙏 for the discussion either way)

@evalstate
Copy link
Member

Perfect! I'll update first thing in the morning and agree on moving the subscribable discussion elsewhere. 👍

* of the LLM and/or the user.
*
*/
export interface LinkedResource {
Copy link
Member

Choose a reason for hiding this comment

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

This has been added for Type Discrimination within the content block.

export interface PromptMessage {
role: Role;
content: TextContent | ImageContent | AudioContent | EmbeddedResource;
content: ContentBlock;
Copy link
Member

Choose a reason for hiding this comment

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

This would be a good time to merge turns this in to an Array similar to the existing ToolCallResult.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took a quick look at that discussion, seems well motivated to me but I think best to keep it a separate PR

@connor4312
Copy link
Contributor

lgtm 🙂

@bhosmer-ant bhosmer-ant changed the title add ResourceReference to CallToolResult add LinkedResource to CallToolResult Jun 5, 2025
@bhosmer-ant bhosmer-ant marked this pull request as ready for review June 5, 2025 15:24
@bhosmer-ant bhosmer-ant requested a review from dsp-ant June 5, 2025 15:25
@bhosmer-ant bhosmer-ant force-pushed the basil/resource_reference_tool_result branch from 0096774 to 383772c Compare June 5, 2025 17:39
@dsp-ant dsp-ant moved this to Consulting in Standards Track Jun 6, 2025
@dsp-ant dsp-ant added this to the DRAFT 2025-06-XX milestone Jun 6, 2025
Comment on lines 982 to 970
| LinkedResource
| EmbeddedResource;
Copy link
Contributor

Choose a reason for hiding this comment

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

why aren't we letting CallToolResult include a Resource directly vs. introducing LinkedResource?

Copy link
Member

Choose a reason for hiding this comment

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

We need the type discriminator.

dsp-ant
dsp-ant previously approved these changes Jun 10, 2025
Copy link
Member

@dsp-ant dsp-ant left a comment

Choose a reason for hiding this comment

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

Thank you. Looks good to me. Some wording changes maybe.

Not sure I really like the name linked_resource compared to resource_link but I am not too fussed about it. Thoughts @ihrpr ?

Comment on lines 233 to 234
[Resources](/specification/draft/server/resources) **MAY** be linked, to provide additional context
or data, behind a URI that can be subscribed to or fetched by the client:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[Resources](/specification/draft/server/resources) **MAY** be linked, to provide additional context
or data, behind a URI that can be subscribed to or fetched by the client:
A tool **MAY** return links to [Resources](/specification/draft/server/resources) **MAY**, to provide additional context
or data. In this case, the tool will return a URI that can be subscribed to or fetched by the client:

@dsp-ant dsp-ant moved this from Consulting to Approved in Standards Track Jun 10, 2025
@ihrpr
Copy link
Contributor

ihrpr commented Jun 10, 2025

Thank you. Looks good to me. Some wording changes maybe.

Not sure I really like the name linked_resource compared to resource_link but I am not too fussed about it. Thoughts @ihrpr ?

Given that we are inheriting from the Resource which is basically a definition of a resource, it might be more intuitive to call it a resource_link. As then there might be confusion in type hierarchy around EmbeddedResources and LinkedResources etc

But also not a strong preference, just thinking out loud

@bhosmer-ant
Copy link
Contributor Author

bhosmer-ant commented Jun 10, 2025

@ihrpr @dsp-ant I'm also weak on the name. The "real" name is Resource (but with a type tag) and any name that sounds semantically nontrivial is potentially confusing, e.g. "link" (on either side) could easily be read to mean that we're adding an extra level of indirection to Resource, which we're totally not.

How about ResourceContent? It leaves EmbeddedResource in an awkward position (assuming we don't want to churn it to EmbeddedResourceContent) but eh

Followup: "content" sort of implies removing a level of indirection, so not a panacea. Going with ResourceLink

@bhosmer-ant bhosmer-ant changed the title add LinkedResource to CallToolResult add ResourceLink to CallToolResult Jun 10, 2025
ihrpr
ihrpr previously approved these changes Jun 10, 2025
Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

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

LGTM!

@evalstate
Copy link
Member

@ihrpr @dsp-ant I'm also weak on the name. The "real" name is Resource (but with a type tag) and any name that sounds semantically nontrivial is potentially confusing, e.g. "link" (on either side) could easily be read to mean that we're adding an extra level of indirection to Resource, which we're totally not.

How about ResourceContent? It leaves EmbeddedResource in an awkward position (assuming we don't want to churn it to EmbeddedResourceContent) but eh

Followup: "content" sort of implies removing a level of indirection, so not a panacea. Going with ResourceLink

I went down this path...:) We already have a ResourceContents. ResourceReference?

@ihrpr
Copy link
Contributor

ihrpr commented Jun 10, 2025

I went down this path...:) We already have a ResourceContents. ResourceReference?

Yeah, I also though about ResourceReference, but equally happy with ResourceLink

@evalstate
Copy link
Member

I ran this [naming] problem through the Claude quite a few times!

@bhosmer-ant bhosmer-ant force-pushed the basil/resource_reference_tool_result branch from 5ab58db to bfbd362 Compare June 10, 2025 19:01
@bhosmer-ant bhosmer-ant enabled auto-merge June 10, 2025 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Approved

Development

Successfully merging this pull request may close these issues.

10 participants