Skip to content

feat: add resource_link support to tools and prompts - #381

Merged
4t145 merged 3 commits into
modelcontextprotocol:mainfrom
aharvard:feat/resource-link
Aug 29, 2025
Merged

feat: add resource_link support to tools and prompts#381
4t145 merged 3 commits into
modelcontextprotocol:mainfrom
aharvard:feat/resource-link

Conversation

@aharvard

@aharvardaharvard commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR adds support for the resource_link content type to the Rust SDK, as specified in the MCP specification. This allows both tools and prompts to return links to resources without embedding the full content, which is useful for large files or resources that should be fetched on-demand.

Changes

Core Implementation

  • Added ResourceLink variant to RawContent enum in content.rs with snake_case discriminant
  • Added ResourceLink variant to PromptMessageContent enum in prompt.rs
  • Both enums use #[serde(rename_all = "snake_case")] to match the MCP spec

Helper Methods

  • Content::resource_link() - Create resource link content for tools
  • RawContent::resource_link() - Create raw resource link content
  • RawContent::as_resource_link() - Access resource link from content
  • PromptMessageContent::resource_link() - Create resource link for prompts
  • PromptMessage::new_resource_link() - Create resource link prompt message

Tests

  • Comprehensive unit tests for serialization/deserialization
  • Integration tests verifying compatibility between tools and prompts
  • Tests for mixed content types (text, resource links, embedded resources)
  • All tests verify correct JSON format with "type": "resource_link"

Schema Updates

  • Updated JSON schema generation to include the new resource_link type
  • Schema fixtures updated to reflect the changes

Example Usage

Tools returning resource links:

use rmcp::model::{CallToolResult,Content,RawResource};let resource = RawResource::new("file:///data.json","Data File");let result = CallToolResult::success(vec![Content::text("Found data file"),Content::resource_link(resource),]);

Prompts returning resource links:

use rmcp::model::{PromptMessage,PromptMessageRole,RawResource};let resource = RawResource::new("file:///doc.md","Documentation");let message = PromptMessage::new_resource_link(PromptMessageRole::User,
resource.no_annotation(),);

Compatibility

  • Maintains backward compatibility - this is an additive change
  • The mimeType field correctly uses camelCase in JSON serialization (Rust field is mime_type)
  • Follows the MCP draft specification for resource links

Testing

All tests pass including:

  • Unit tests for content types
  • Integration tests for tool/prompt compatibility
  • Schema generation tests
  • Formatting and clippy checks

@github-actionsgithub-actionsBot added T-core Core library changes T-model Model/data structure changes labels Aug 19, 2025
@aharvard
aharvardforce-pushed the feat/resource-link branch 3 times, most recently from 28057c6 to c9fde77CompareAugust 19, 2025 12:53
@aharvardaharvard changed the title feat(rmcp): add MCP resource_link content typefeat(rmcp): add MCP resource_link (2025-06-18)Aug 19, 2025
@aharvardaharvard changed the title feat(rmcp): add MCP resource_link (2025-06-18)feat: add MCP resource_link (2025-06-18)Aug 19, 2025
@github-actionsgithub-actionsBot added T-test Testing related changes T-config Configuration file changes labels Aug 19, 2025
@aharvard
aharvardforce-pushed the feat/resource-link branch 2 times, most recently from c34d426 to c4acd32CompareAugust 19, 2025 13:30
@github-actionsgithub-actionsBot added T-documentation Documentation improvements T-dependencies Dependencies related changes T-macros Macro changes labels Aug 19, 2025
@aharvard
aharvardforce-pushed the feat/resource-link branch 2 times, most recently from aa4fef7 to 5812189CompareAugust 19, 2025 14:47
@github-actionsgithub-actionsBot removed T-documentation Documentation improvements T-dependencies Dependencies related changes T-macros Macro changes labels Aug 19, 2025
@aharvard
aharvard marked this pull request as ready for review August 19, 2025 14:50
@4t145
4t145 requested a review from CopilotAugust 20, 2025 04:25

This comment was marked as outdated.

@aharvard

Copy link
Copy Markdown
ContributorAuthor

FYI... I used the copilot commit suggestion and it introduce a failed merge check due to git message formatting

imageimage

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds MCP ResourceLink content block support to align rmcp with the MCP 2025-06-18 specification, enabling references to server resources without embedding their payloads.

  • Adds ResourceLink content type with URI-based resource referencing
  • Updates embedded text MIME type to use proper "text/plain" instead of generic "text"
  • Includes comprehensive test coverage for new functionality

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

FileDescription
crates/rmcp/src/model/content.rsAdds ResourceLink variant to RawContent enum and constructors for resource linking
crates/rmcp/src/model/prompt.rsAdds ResourceLink support to PromptMessageContent for prompts/get
crates/rmcp/tests/test_message_schema/*.jsonUpdates JSON schema files to reflect new ResourceLink type definitions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadcrates/rmcp/src/model/content.rs Outdated
4t145
4t145 previously approved these changes Aug 25, 2025
Comment threadcrates/rmcp/src/model/content.rs Outdated
@github-actionsgithub-actionsBot added T-test Testing related changes T-config Configuration file changes T-CI Changes to CI/CD workflows and configuration and removed T-dependencies Dependencies related changes T-test Testing related changes T-config Configuration file changes T-examples Example code changes T-handler Handler implementation changes T-macros Macro changes T-transport Transport layer changes labels Aug 26, 2025
@aharvard

Copy link
Copy Markdown
ContributorAuthor

@4t145, I am converting this PR back to a draft state. Something happened when I rebased and force-pushed. I've been working thru failing merge checks with Goose and don't like the edits I'm seeing.

I'll notify when ready for another review.

@aharvard
aharvard marked this pull request as draft August 26, 2025 13:13
@github-actionsgithub-actionsBot removed the T-CI Changes to CI/CD workflows and configuration label Aug 26, 2025
@aharvard
aharvardforce-pushed the feat/resource-link branch 3 times, most recently from d3273e0 to 3b1cd0fCompareAugust 26, 2025 17:39
@aharvardaharvard changed the title feat: add MCP resource_link (2025-06-18)feat: add resource_link support to tools and promptsAug 26, 2025
@aharvard
aharvard marked this pull request as ready for review August 26, 2025 18:47
@aharvard

Copy link
Copy Markdown
ContributorAuthor

Ready for re-review @4t145. Please take another look at everything I re-rolled my attempt entirely.

Pinging @alexhancock as well.

@alexhancock

Copy link
Copy Markdown
Contributor

Will look later today @aharvard

@4t145
4t145 merged commit 98b77fd into modelcontextprotocol:mainAug 29, 2025
11 checks passed
@github-actionsgithub-actionsBot mentioned this pull request Aug 28, 2025
takumi-earth pushed a commit to earthlings-dev/rmcp that referenced this pull request Jan 27, 2026
…tocol#381)
* feat: add resource_link support to tools and prompts
* chore: remove unused serde_json import from test_resource_link_integration.rs
* chore: remove unused serde_json import from test_resource_link.rs
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-configConfiguration file changesT-coreCore library changesT-modelModel/data structure changesT-testTesting related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@aharvard@alexhancock@4t145