Skip to content

add LinkedResource to CallToolResult #603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

bhosmer-ant
Copy link
Contributor

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

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

Motivation and Context

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

LinkedResource 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
Contributor

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
Contributor

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
Contributor

@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
Contributor

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
Contributor

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.

@@ -646,7 +646,7 @@ export type Role = "user" | "assistant";
*/
export interface PromptMessage {
role: Role;
content: TextContent | ImageContent | AudioContent | EmbeddedResource;
content: ContentBlock;
Copy link
Contributor

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

5 participants