Skip to content

Conversation

rliang
Copy link

@rliang rliang commented Sep 18, 2025

Add support for macros in doc attributes parsed by the tool macro.

Motivation and Context

Currently the #[tool] macro only supports literal strings for #[doc] attributes, and some codebases use external docs, .e.g, #[doc = include_str!(...)].

How Has This Been Tested?

Test cases have been added.

Breaking Changes

N/A

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

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

@Copilot Copilot AI review requested due to automatic review settings September 18, 2025 13:51
@github-actions github-actions bot added the T-macros Macro changes label Sep 18, 2025
Copy link
Contributor

@Copilot 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 support for macros in doc attributes for both the tool and prompt macros, enabling the use of external documentation sources like #[doc = include_str!(...)] instead of just literal strings.

  • Changes the description field type from String to Expr in both tool and prompt attribute structs
  • Updates the extract_doc_line function to handle macro expressions and preserve them in the generated code
  • Adds comprehensive test coverage for the new macro support functionality

Reviewed Changes

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

File Description
crates/rmcp-macros/src/tool.rs Updates tool macro to support macro expressions in doc attributes and adds test for include_str! usage
crates/rmcp-macros/src/prompt.rs Updates prompt macro to support macro expressions in doc attributes and adds corresponding test case
crates/rmcp-macros/src/common.rs Modifies extract_doc_line function to handle both literal strings and macro expressions, using concat! for combining multiple doc lines

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

Update callers to use Iterator::try_fold and propagate errors with ?.
Also switch parse2().ok() to map(Some) and convert early returns to
Ok(...) variants.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-macros Macro changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants