Craft Anything: understand how any software works, and craft your own.
Rust
A large approved action keeps its allow decision over MCP (#314)
BFlat1dd342f48206
diff --git a/crates/mcp/src/lib.rs b/crates/mcp/src/lib.rsindex 13071a11..c0f7ca01 100644--- a/crates/mcp/src/lib.rs+++ b/crates/mcp/src/lib.rs@@ -393,7 +393,9 @@ impl Server {};let resp = ok_response(id.clone(), body);let size = serde_json::to_string(&resp).map(|s| s.len()).unwrap_or(usize::MAX);- if size > self.budget() {+ // An approval answer is a protocol message, not result data: an error in its place loses+ // the decision (#253). It echoes the input the client sent, so its size is the client's.+ if size > self.budget() && !self.raw_value(name) {// Prefer a summary-first collapse (the full record is retained) over a bare error.if let Some(summary) = self.oversize_summary(&resp) {let sresp = ok_response(id.clone(), summary);diff --git a/crates/mcp/src/tests.rs b/crates/mcp/src/tests.rsindex 6bb0949c..ecfeb7e4 100644--- a/crates/mcp/src/tests.rs+++ b/crates/mcp/src/tests.rs@@ -63,6 +63,20 @@ fn approval_tool_answers_in_the_permission_prompt_shape() {assert_eq!(bad["behavior"], "deny", "a malformed request is refused in the protocol's own words");}+/// #253: an allowed action with a large input came back as an `over_limit` error with no decision.+#[test]+fn a_large_approval_keeps_its_decision() {+ let input = json!({"file_path": "x", "note": "a".repeat(4096)});+ let out = run_with(+ ServerOptions { max_response_bytes: 300, ..Default::default() },+ &[req(1, "tools/call", json!({"name": "core_action_approve", "arguments": {"tool_name": "Read", "input": input, "tool_use_id": "t"}}))],+ );+ let r = response(&out, 1)["result"].clone();+ assert_eq!(r["isError"], false, "{r}");+ let decision: Value = serde_json::from_str(r["content"][0]["text"].as_str().unwrap()).unwrap();+ assert_eq!(decision, json!({"behavior": "allow", "updatedInput": input}));+}+fn tool_names(v: &Value) -> Vec<String> {v["result"]["tools"].as_array().unwrap().iter().map(|t| t["name"].as_str().unwrap().to_string()).collect()}