shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

[Enhancement] Encode MCP request-template bodies as declared form or multipart media types

Open Aias00 opened this issue 1 month ago • 1 comments

Current limitation

MCP request templates and examples advertise non-JSON request types, but body construction remains JSON-only:

Preserving an explicitly configured header alone would not solve the missing form/multipart serialization.

Executed evidence / limits

A probe compiled the current BodyWriterExchange and captured its actual output for the same structured JSON body under three declared content types:

TYPE=application/json BODY={"name":"Ada & Bob"}
TYPE=application/x-www-form-urlencoded BODY={"name":"Ada & Bob"}
TYPE=multipart/form-data BODY={"name":"Ada & Bob"}

The form path does not produce name=Ada+%26+Bob, and the multipart path has neither a generated boundary nor parts. The callback's header override and bodyJson-to-string flow were inspected in source; this probe exercises the writer directly and does not execute a full MCP session or upload to an external service. A separate reviewer confirmed the end-to-end scope must include both header choice and body encoding.

Proposed enhancement / acceptance criteria

  • Keep current JSON serialization for application/json.
  • Preserve an explicit supported template Content-Type; use JSON only as the documented default.
  • Serialize form bodies as properly escaped name/value pairs.
  • Build real multipart parts and generate a matching boundary parameter. Define how the documented Base64 file input maps to bytes, part names and filenames rather than sending Base64 inside a JSON object.
  • Make the checked-in form and upload examples consumable by their intended downstream handlers, and document unsupported input shapes clearly.
  • Maintain correct content length/stream ownership and avoid buffering a binary upload multiple times unnecessarily.

Related existing work

#6254 concerns custom header variable substitution; #6751 concerns URL/path/query argument encoding; #7453 concerns fixed target endpoints being overwritten by URL-valued arguments. #7737 concerns Spring route registration. No matching request-template form/multipart encoding issue was found in complete-title, open-PR and targeted MCP media-type searches. Header precedence and actual encoding are intentionally grouped as one enhancement.

Reviewed revision

Apache ShenYu 2.7.2-SNAPSHOT, master@66d7d954ca37d651a5ad916f988a8081157a7ab4. Priority P2 / Medium, high confidence in the described source/runtime behavior. Unit-test and CI issue categories excluded.

Aias00 avatar Oct 17 '26 12:10 Aias00

/assign

Neymar-10-JR avatar Oct 17 '26 17:10 Neymar-10-JR