`#[tool(description = …)]` accepts only a bare literal, while `#[doc]` and `#[schemars]` on the same items accept `include_str!` and `const` paths
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
このレポートには実装ファイルやテストが記載されていないため、まず #[tool] 属性パーサーと description に対するその検証を見つけてください。 &'static str の const パスと concat! のカバレッジを追加し、リテラルの動作を維持して、生成された description と文書化された動作またはエラー動作がリクエストに一致することを確認してください。
索引モデルが issue の本文から書いたものです。
説明
Summary
description in #[tool] accepts only a bare string literal. Two attributes that sit on the very same items are more permissive: #[doc] on the function accepts include_str! and that value does reach the published description, and #[schemars(extend(…))] on the argument struct accepts const paths.
So a server can already source a tool's published text from outside the attribute — through #[doc], or through a literal handed in by a wrapper macro — just not through description, which is the field that names it. Accepting a const path and concat! there would remove the inconsistency.
This is an enhancement request, not a blocker: the workarounds below all work.
Version
rmcp 3.1.2, rustc 1.96.1, edition 2024.
What was measured
| form | result |
|---|---|
#[tool(description = "…")] |
works |
#[tool(description = my_crate::caps::TEXT)] |
error: Unexpected type \path`` |
#[tool(description = concat!("a", "b"))] |
error: Unexpected type \macro`` |
/// doc comment + #[tool] |
works — becomes the description |
#[doc = include_str!("text.md")] + #[tool] |
works — becomes the description |
#[schemars(extend("maximum" = MOST_STARTS_AT_ONCE))] on the args struct |
works — a const path, in the same attribute stack |
doc comment and description together |
description wins (no surprise here) |
macro_rules! wrapping the whole #[tool_router] impl |
works |
macro_rules! wrapping only the fn inside the impl |
compiles, registers nothing — filed separately |
The schemars row is the one that makes this feel like an oversight rather than a decision: a const is already acceptable one attribute away, for a value that is likewise baked into the published schema.
Why it matters on a larger surface
On a server with many tools the published text is an interface, and it usefully has two halves: a short one broadcast in tools/list before the first call, and a longer one fetched on demand. Ours measures 82 953 B of description across 66 tools, against a 13 590 B fetchable handbook — so keeping the split is worth real bytes, and it is far easier to keep the two halves honest when both can be declared together and the short one referenced from the attribute:
// what one would like to write
const GET_OR_CREATE_PROJECT: Capability = Capability {
broadcast: "…what prevents a wrong call…",
taught: "…the full explanation, fetched on demand…",
};
#[tool(description = GET_OR_CREATE_PROJECT.broadcast)]
Today that requires either moving the text into a file and using #[doc = include_str!(…)], or keeping a second copy plus a test comparing it to the literal.
Suggested change
Accept in description what neighbouring attributes already accept: a path to a const &'static str, and concat!. The generated code stores a &'static str either way.
If the literal is required because the value is needed during macro expansion, a line saying so in the docs — and an error message reading "only a string literal is accepted here" rather than naming the token type — would save the next person the experiment.
What this report does not establish
It does not claim the current behaviour is wrong, only that it is inconsistent with #[doc] and #[schemars] on the same items. name was not tested against a non-literal; only description was.
- 主要言語
- Rust
- スター
- 4k
- フォーク
- 654
- 平均マージ
- 4日 3時間
- マージ済み PR(30日)
- 40
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/rust-sdk のほかの issue
-
P3 question T-documentation T-enhancement
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
modelcontextprotocol/rust-sdk#1155 ·
メンテナーはふだん 3 日以内に返信
-
LocalSessionManager session workers don't cancel in-flight tool calls on client disconnect (follow-up to #857)対応中かも @kkkhs が今日担当しました。 オープンbug P1 ready for work T-transport
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
modelcontextprotocol/rust-sdk#1325 ·
メンテナーはふだん 3 日以内に返信
-
streamable-http server: client responses to server-initiated requests (sampling/elicitation/roots) are 202-accepted and silently discarded under the 2026-07-28 protocol — the pending request hangs forever対応中かも @DaleSeo が今日担当しました。 オープンbug P1 ready for work T-transport
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
modelcontextprotocol/rust-sdk#1321 · リアクション 1 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
Bound pre-lifecycle bootstrap attempts in server initialization対応中かも @DaleSeo が 4 日前に担当しました。 オープンenhancement P2 T-service T-transport
modelcontextprotocol/rust-sdk#1315 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
ProgressDispatcher: a slow progress subscriber blocks subscribe() and delivery for other tokens対応中かも @monody0007 が 8 日前に担当しました。 オープンbug P1 ready for work T-handler
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
modelcontextprotocol/rust-sdk#1312 ·
メンテナーはふだん 3 日以内に返信
modelcontextprotocol/rust-sdk の issue をすべて見る
似ている issue
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
fastrevmd-lab/rustmistmcp#161 ·
-
arch-audit refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
SocketDev/socket-patch#1011 ·
メンテナーはふだん 1 日以内に返信
-
bug user-priority/P2
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
メンテナーはふだん 1 日以内に返信
-
opencode: an unanswered --version probe launches opencode 2 without per-session service isolationオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
security-advisory
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
MinBZK/regelrecht#1686 ·
メンテナーはふだん 1 日以内に返信