Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

outputSchema is generated for the deserialize contract; tool results are serialised

Aperta
#1,374 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@connor4312 ci sta già lavorando.

Dal 17/10/2026.

  • #1378 di @atarutin — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

bug P2 ready for work T-handler

Problem

schema_for_output::<T>() builds a tool's outputSchema through schema_for_type, which uses SchemaSettings::draft2020_12(), i.e. schemars' default Contract::Deserialize (crates/rmcp/src/handler/server/common.rs, still the case on main at ad5a284). A tool result is a value the server serialises, so its schema should describe what Serialize writes. Under the deserialize contract the advertised schema is wrong for common shapes:

  • an Option<T> field without skip_serializing_if is always written (as null), but is advertised as optional;
  • a #[serde(default)] field is always written, but is advertised as optional;
  • a type that accepts several forms and writes one (e.g. rust_decimal::Decimal: string or number in, string out) is advertised with every accepted form.

A client or model reading outputSchema is told a field may be absent when the server always sends it, or may be a number when the server sends a string.

Repro

#[derive(serde::Serialize, schemars::JsonSchema)]
struct Out {
    always: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    sometimes: Option<i32>,
}
// schema_for_output::<Out>()["required"] is absent; it should be ["always"].

Proposed fix

schema_for_output generates with SchemaSettings::draft2020_12().for_serialize(). Inputs (schema_for_type) stay on the deserialize contract. There is no public API change. For types whose two forms are equal, the output schema is byte-identical.

I have a patch against main with two tests (an always-written Option is required in an output schema; an input Option stays optional). cargo test -p rmcp --features server,client,macros,schemars,transport-io passes. I'm happy to open the PR if this direction is welcome.

Lingua principale
Rust
Stelle
4k
Fork
662
Merge medio
3g 11h
PR unite (30g)
36

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modelcontextprotocol/rust-sdk

Tutte le issue di modelcontextprotocol/rust-sdk

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.