Skip to content

Comments

feat: add resource_link support to tools and prompts#381

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

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

Conversation

@aharvard
Copy link
Contributor

@aharvard aharvard commented Aug 19, 2025

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-actions github-actions bot added T-core Core library changes T-model Model/data structure changes labels Aug 19, 2025
@aharvard aharvard force-pushed the feat/resource-link branch 3 times, most recently from 28057c6 to c9fde77 Compare August 19, 2025 12:53
@aharvard aharvard changed the title feat(rmcp): add MCP resource_link content type feat(rmcp): add MCP resource_link (2025-06-18) Aug 19, 2025
@aharvard aharvard changed the title feat(rmcp): add MCP resource_link (2025-06-18) feat: add MCP resource_link (2025-06-18) Aug 19, 2025
@github-actions github-actions bot added T-test Testing related changes T-config Configuration file changes labels Aug 19, 2025
@aharvard aharvard force-pushed the feat/resource-link branch 2 times, most recently from c34d426 to c4acd32 Compare August 19, 2025 13:30
@github-actions github-actions bot added T-documentation Documentation improvements T-dependencies Dependencies related changes T-macros Macro changes labels Aug 19, 2025
@aharvard aharvard force-pushed the feat/resource-link branch 2 times, most recently from aa4fef7 to 5812189 Compare August 19, 2025 14:47
@github-actions github-actions bot 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 Copilot August 20, 2025 04:25

This comment was marked as outdated.

@aharvard
Copy link
Contributor Author

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

image image

@aharvard aharvard force-pushed the feat/resource-link branch from 0a53835 to 305b58e Compare August 22, 2025 20:00
@aharvard aharvard requested a review from Copilot August 22, 2025 20:18
Copy link
Contributor

Copilot AI left a comment

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.

File Description
crates/rmcp/src/model/content.rs Adds ResourceLink variant to RawContent enum and constructors for resource linking
crates/rmcp/src/model/prompt.rs Adds ResourceLink support to PromptMessageContent for prompts/get
crates/rmcp/tests/test_message_schema/*.json Updates 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.

4t145
4t145 previously approved these changes Aug 25, 2025
@github-actions github-actions bot added T-test Testing related changes T-config Configuration file changes T-CI Changes to CI/CD workflows and configuration and removed T-documentation Documentation improvements 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
Contributor Author

@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
@aharvard aharvard force-pushed the feat/resource-link branch from 364059f to dc96c4a Compare August 26, 2025 17:15
@github-actions github-actions bot removed the T-CI Changes to CI/CD workflows and configuration label Aug 26, 2025
@aharvard aharvard force-pushed the feat/resource-link branch 3 times, most recently from d3273e0 to 3b1cd0f Compare August 26, 2025 17:39
@aharvard aharvard force-pushed the feat/resource-link branch from 3b1cd0f to 71978a9 Compare August 26, 2025 17:41
@aharvard aharvard changed the title feat: add MCP resource_link (2025-06-18) feat: add resource_link support to tools and prompts Aug 26, 2025
@aharvard aharvard marked this pull request as ready for review August 26, 2025 18:47
@aharvard
Copy link
Contributor Author

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

Pinging @alexhancock as well.

@alexhancock
Copy link
Contributor

Will look later today @aharvard

@4t145 4t145 merged commit 98b77fd into modelcontextprotocol:main Aug 29, 2025
11 checks passed
@github-actions github-actions bot 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 free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-config Configuration file changes T-core Core library changes T-model Model/data structure changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants