* MCP: compact inspect_design and tool JSON, off by default (--compact / SOLIDCRAFT_MCP_COMPACT) Split out of #2901 per review: the smaller inspect_design changed the default for everyone, so it is now an MCP server option that is off unless asked for. - solidcraft-cli mcp --compact, or SOLIDCRAFT_MCP_COMPACT=1 (true/yes/on; 0/false/no/off/empty leave it off; anything else is an error at start-up). solidcraft_mcp::Options::resolve is the one place that decides, so an app Preferences setting can feed it later. - With it on, inspect_design summarises sketches (id, name, plane, counts of points, curves, constraints and profiles, dof, status), returns full contents only for the sketches named in `sketches` (names/ids, true, false or "summary"), takes a `bodies` filter and measures only those; unknown names list the existing ones. Tool JSON is compact rather than pretty-printed. - Off, tools/list, argument checks, inspect_design and tool JSON are exactly as before. - document.inspect gains an opt-in `sketch_counts` (plane, points, constraints); without it its reply is unchanged. Tests: both modes in the MCP suite, Options parsing, and the CLI flag and variable end to end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MCP compact output: a Preferences setting too (AI › Agents through MCP) The desktop app's Preferences › AI gets "Compact output" under a new "Agents through MCP" section, off by default and shown with the chat off too. The app reports it on the control channel as `mcp.options` ({"compact": bool}); the agent chat lets its own MCP server read it. A bridged MCP server (`solidcraft-cli mcp --connect`) asks the app when an agent first lists or calls a tool and keeps the answer for the session, so the tools it listed keep their shape. An app not running yet, or busy past 2 s, is asked again on the next call; an app from before the setting counts as off. `--compact` and SOLIDCRAFT_MCP_COMPACT=1 still turn it on whatever the app says. Tests: the server follows the app's answer (waits for it, keeps it, the flag still wins); the checkbox reaches `mcp.options` and Restore Defaults clears it; the chat gate allows `mcp.options`. docs/mcp.md and docs/control-protocol.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MCP compact output: review fixes (mcp.options never blocks, headless test, locales, prefs doc) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MCP compact output: the setting is a section of the AI page; the bridged test answers mcp.options Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MCP compact output: the preference test sets it through ui.prefs; rustfmt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MCP compact output: look for a newly started app before asking its options; counts from sketch.inspect for an older app Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2.2 KiB
Rust
49 lines
2.2 KiB
Rust
//! `mcp --compact` and `SOLIDCRAFT_MCP_COMPACT` turn on compact tool output; without them the
|
|
//! server's tools are as they always were.
|
|
|
|
use std::io::Write;
|
|
use std::process::{Command, Stdio};
|
|
|
|
use serde_json::{Value, json};
|
|
|
|
/// `inspect_design`'s input schema as `solidcraft-cli mcp` with `args` and `env` lists it, or
|
|
/// the server's stderr when it does not start.
|
|
fn inspect_schema(args: &[&str], env: Option<&str>) -> Result<Value, String> {
|
|
let mut cmd = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli"));
|
|
// --headless: never bridge to (and read the preference of) an app the developer has running.
|
|
cmd.args(["mcp", "--headless", "--allow-any-path"]).args(args).stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped());
|
|
match env {
|
|
Some(v) => cmd.env("SOLIDCRAFT_MCP_COMPACT", v),
|
|
None => cmd.env_remove("SOLIDCRAFT_MCP_COMPACT"),
|
|
};
|
|
let mut child = cmd.spawn().unwrap();
|
|
{
|
|
let mut stdin = child.stdin.take().unwrap();
|
|
// The server may refuse to start and close stdin first.
|
|
let _ = writeln!(stdin, "{}", json!({"jsonrpc": "2.0", "id": 1, "method": "tools/list"}));
|
|
}
|
|
let out = child.wait_with_output().unwrap();
|
|
if !out.status.success() {
|
|
return Err(String::from_utf8_lossy(&out.stderr).into_owned());
|
|
}
|
|
let reply: Value = serde_json::from_slice(&out.stdout).unwrap();
|
|
let tools = reply["result"]["tools"].as_array().cloned().unwrap_or_default();
|
|
Ok(tools.into_iter().find(|t| t["name"] == "inspect_design").map(|t| t["inputSchema"].clone()).unwrap_or(Value::Null))
|
|
}
|
|
|
|
#[test]
|
|
fn compact_output_is_off_unless_asked() {
|
|
let plain = inspect_schema(&[], None).unwrap();
|
|
assert_eq!(plain["properties"]["sketches"]["type"], "boolean", "{plain}");
|
|
assert!(plain["properties"].get("bodies").is_none(), "{plain}");
|
|
assert_eq!(inspect_schema(&[], Some("0")).unwrap(), plain);
|
|
|
|
for (args, env) in [(&["--compact"][..], None), (&[][..], Some("1")), (&[][..], Some("true"))] {
|
|
let compact = inspect_schema(args, env).unwrap();
|
|
assert!(compact["properties"]["bodies"].is_object(), "{args:?} {env:?}: {compact}");
|
|
}
|
|
|
|
let e = inspect_schema(&[], Some("maybe")).unwrap_err();
|
|
assert!(e.contains("SOLIDCRAFT_MCP_COMPACT"), "{e}");
|
|
}
|