Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#1,374 2 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@connor4312 đang làm issue này rồi.

Từ ngày 17/10/2026.

  • #1378 của @atarutin — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
4k
Fork
688
Merge trung bình
3 ngày 11 giờ
Pull request đã merge (30 ngày)
36

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/rust-sdk

Tất cả issue của modelcontextprotocol/rust-sdk

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.