feat: relax outputSchema to accept non-object JSON Schema types (SEP-2106)#895
feat: relax outputSchema to accept non-object JSON Schema types (SEP-2106)#895branben wants to merge 3 commits into
Conversation
|
thanks @branben if you can run a fmt over this to get CI happy - I think this is then good to merge, thanks! |
just checked on this @michaelneale happy I could contribute! |
|
Thanks for the review @DaleSeo! All 4 comments addressed in the latest push:
The Please let me know where else I can make meaningful contributions if there's a specific pain point that's bugging the team! |
|
@branben You might've forgotten to push those fixes? I'm still seeing the original code. 😅 |
47e5d23 to
6588978
Compare
…urns Result - Add strip_output() that strips title/description without validating type (Dale modelcontextprotocol#1) - Change schema_for_output to return Arc<JsonObject> instead of Result (Dale modelcontextprotocol#2) - Cache only Arc<JsonObject> success values, not Result (Dale modelcontextprotocol#3) - Remove dead unwrap_or_else panic paths in with_output_schema, ToolBase, and macros - Tighten test assertions from contains to assert_eq on type field (Dale modelcontextprotocol#4) - Update test_schema_for_output_rejects_primitive to accept_primitive (SEP-2106) Co-authored-by: Orca <help@stably.ai>
Add tests verifying schema_for_output accepts non-object types: - test_tool_builder_methods: primitive (i32), array (Vec<String>), option - test_structured_output: tool returning Json<Vec<T>> and Json<i32> - test_json_schema_detection: Json<Vec<T>>, Result<Json<Vec<T>>,E>, Json<String> - tool_traits: ToolBase::output_schema with Vec<AddOutput> output type
Add tests identified during code review: - description stripping for primitive types - composition types (Option<String> with anyOf/oneOf/null) - cache correctness (Arc::ptr_eq for repeated calls) - schema_for_input rejecting array types (not just primitives) - schema_for_output accepting unit type ()
6588978 to
28c2bcc
Compare
Summary
Relax
schema_for_outputto accept any JSON Schema 2020-12 root type (arrays, primitives, compositions) foroutputSchema, while keepingschema_for_inputenforcingtype: "object". This implements SEP-2106, which was accepted May 18 2026.PR #860 (merged Jun 2 2026) added title/desc stripping and input validation. This PR covers the remaining work: decoupling the type gate so output schemas are no longer rejected for non-object types.
Changes
crates/rmcp/src/handler/server/common.rs: Splitvalidate_and_stripinto:validate_and_strip_input— keepstype: "object"check for inputSchemavalidate_and_strip_output— strips title/desc, no type check (accepts any JSON Schema root type)crates/rmcp/src/model/tool.rs: Updatedwith_output_schemadoc comment to remove incorrect "root type object" panic referenceOption<T>), unit type,Json<T>macro path,ToolBasetrait path, cache correctness, and negative tests for input rejectionBackward Compatibility
schema_for_outputreturn type unchanged (Result<Arc<JsonObject>, String>)Verification
cargo test -p rmcp --all-features: 424 passed, 0 failedcargo clippy --all-targets --all-features -- -D warnings: No issues found