`#[tool(description = …)]` accepts only a bare literal, while `#[doc]` and `#[schemars]` on the same items accept `include_str!` and `const` paths
Maintainer antworten meist innerhalb von 3 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 62/100
Rechercherichtung
Der Bericht nennt keine Implementierungsdateien oder Tests; beginne damit, den Parser für das Attribut #[tool] und seine Validierung für description zu finden. Füge Abdeckung für einen &'static str const-Pfad und concat! hinzu, bewahre das Verhalten von Literalen und überprüfe, dass die generierte description sowie das dokumentierte oder Fehlerverhalten mit der Anforderung übereinstimmen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Rust
- Sterne
- 4.1k
- Forks
- 680
- Ø Merge
- 3 T. 20 Std.
- Gemergte PRs (30 T.)
- 32
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus modelcontextprotocol/rust-sdk
-
auth: refresh_token() requests offline_access that was never granted, so refreshes fail with invalid_scopeEvtl. vergeben @jstar0 hat das vor 21 Tagen übernommen. Offenbug P1 ready for work T-security T-transport
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
modelcontextprotocol/rust-sdk#1330 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Enterprise-managed auth: ID-JAG `resource` claim should be optionalEvtl. vergeben @gocamille hat das vor 1 Tag übernommen. Offenbug P1 ready for work T-security T-transport
modelcontextprotocol/rust-sdk#1404 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Auto discovery timeout rejects a late probe response during legacy initializationEvtl. vergeben @gocamille hat das vor 2 Tagen übernommen. Offenbug P1 ready for work T-service
modelcontextprotocol/rust-sdk#1400 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 3 Tagen
-
URL mode elicitation requires elicitationId, which the 2026-07-28 schema removedEvtl. vergeben @gocamille hat das vor 2 Tagen übernommen. Offenbug P1 ready for work T-model
modelcontextprotocol/rust-sdk#1399 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 3 Tagen
-
stdio transport: a request over the maximum line length gets no answerEvtl. vergeben @gocamille hat das vor 3 Tagen übernommen. Offenbug P1 ready for work T-transport
modelcontextprotocol/rust-sdk#1395 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 3 Tagen
Alle Issues in modelcontextprotocol/rust-sdk
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
Maintainer antworten meist innerhalb von 1 Tag
-
o8 next debug build aborts on Glass to Dark appearance switch (nil identifier messaged before check)Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
hurttlocker/o8#5112 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
memory_patch_page drops the `#` of headings like `## Notes on C#`Evtl. vergeben @viniciusdsandrade hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
akitaonrails/ai-memory#1859 ·
Maintainer antworten meist innerhalb von 1 Tag