Skip to content

elicitation/create with an integer bound like 150.0 falls through to CustomRequest #1581

Todo

Description

@orangeCatDeveloper

Describe the bug

An elicitation/create request whose schema writes an integer bound in float form, such as "maximum": 150.0 or "minimum": 1e2, does not reach the client's elicitation handler. IntegerSchema::{minimum, maximum, default} are Option<i64> and serde rejects 150.0 for them. PrimitiveSchemaDefinition is untagged, so the error surfaces as "data did not match any variant", the typed ElicitRequest fails to parse, and the message falls through to CustomRequest. The default on_custom_request answers METHOD_NOT_FOUND.

StringSchema::{min_length, max_length} and the multi-select {min_items, max_items} have the same problem.

To Reproduce

On main (3725772):

let raw = r#"{"jsonrpc":"2.0","id":7,"method":"elicitation/create","params":{"message":"Age?","requestedSchema":{"type":"object","properties":{"age":{"type":"integer","minimum":0,"maximum":150.0}}}}}"#;
let msg: ServerJsonRpcMessage = serde_json::from_str(raw).unwrap();

msg is a Request holding CustomRequest, not ElicitRequest.

Expected behavior

It parses as ElicitRequest. The MCP schema types these fields as number (minimum?: number, minLength?: number, minItems?: number), and JSON Schema treats 150.0 as an integer. Python servers emit this form whenever a bound is a float (json.dumps(150.0) gives 150.0).

Fractional or out-of-range values (99.5, 1e300, a negative minLength) should still be rejected.

Additional context

NumberOrString already accepts integral floats through integral_f64_to_i64 in model.rs; these fields could do the same.

I have a fix with tests and can open a PR.

Activity

  1. github-actions commented on Dec 6, 2026

    @github-actions
    Contributor

    @connor4312 is on triage rotation this week and is the reviewer for this one.

    Automated classification did not run for this one, so it needs a full manual pass.

    Automated triage. Labels are a first pass and the assigned maintainer has the final say.

  2. orangeCatDeveloper commented on Dec 6, 2026

    @orangeCatDeveloper
    Author

    I'm working on this and have a fix with tests ready. The repo allows one open PR per contributor without write access, so I'll open it once #1583 is resolved.

  3. jokemanfire commented on Dec 6, 2026

    @jokemanfire
    Member

    Reproduced independently on 3725772; the report is accurate, and the blast radius is slightly wider than the two examples.

    What I ran and saw

    serde_json::from_str::<PrimitiveSchemaDefinition>(r#"{"type":"integer","minimum":0,"maximum":150.0}"#)
    // Err(Error("data did not match any variant of untagged enum PrimitiveSchemaDefinition", line: 0, column: 0))

    The full elicitation/create message does not error at the JSON-RPC layer; it lands in CustomRequest and is answered -32601:

    Request(JsonRpcRequest { id: Number(7), request: CustomRequest(CustomRequest { method: "elicitation/create", ... }) })
    

    Also confirmed, with the same opaque error:

    • {"type":"string","minLength":1.0,"maxLength":10} — rejected (integer form parses)
    • {"type":"array","minItems":1.0,"maxItems":5,"items":{"anyOf":[{"const":"a","title":"A"}]}} — rejected; the same payload with minItems":1 parses to Enum(Multi(Titled(...)))

    I did not re-check default, but it is the same field type as the bounds.

    Every integer-typed field in the file

    crates/rmcp/src/model/elicitation_schema.rs:

    • IntegerSchema::minimum / maximum / default → Option<i64> (378, 382, 386)
    • StringSchema::min_length / max_length → Option<u32> (111, 115)
    • UntitledMultiSelectEnumSchema and TitledMultiSelectEnumSchema min_items / max_items → Option<u64> (689, 691, 710, 712)

    serde_json delivers a JSON number written as 150.0 to visit_f64, and the integer visitors reject it. Because PrimitiveSchemaDefinition is #[serde(untagged)] (52-65), one failed variant fails the whole enum, and untagged errors lose the field path, which is why the error is just "did not match any variant" at line 0 column 0.

    Why this is ours to accept, not just a client quirk

    minimum/maximum are number in JSON Schema 2020-12, so 150.0 is a legal bound on an integer property, and json.dumps({"maximum": 150.0}) in Python emits exactly that. The same file already accepts float-form numbers for NumberSchema via super::serde_impl::json_float::option_f64 (261, 269, 277), so lenient number parsing is established practice here — this is an inconsistency, not a deliberate strictness.

    Two shapes for the fix

    1. Add a json_int sibling to json_float in crates/rmcp/src/model/serde_impl.rs: read serde_json::Number, accept when as_i64/as_u64 works, else accept a finite as_f64 with fract() == 0.0, else error naming the value. Apply with #[serde(default, deserialize_with = ...)] to the fields above. No public type change, so it fits 3.x. Cost: a fractional bound (minimum: 0.5 on an integer property) is still rejected even though JSON Schema allows it — no way to express it in i64, and the MCP elicitation use case for it is thin.
    2. Change IntegerSchema bounds to Option<f64> to match NumberSchema. Spec-faithful and no silent narrowing, but it changes public field types and the i64 builders, and every consumer that applies the bound then has to validate integrality — that is 4.0 material alongside the #1547 removals.

    I would take (1) now and (2) only if the elicitation types get a breaking pass anyway. Whichever you have ready, please include all four cases above (integer, string, multi-select, and the integer-value form as a positive control) so a future refactor cannot regress one of them quietly.

    Heads-up on timing: you mentioned the one-open-PR limit — I reviewed #1583 today and asked only for an assertion that client_info/client_capabilities also survive extraction (or trimming that half of the issue text). That is the only thing I am waiting on there, so it should not hold this for long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions