From 3fffaa2214f4f097fcc419f9bb75c92e3fd22a96 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 30 Nov 2026 03:14:16 +0700 Subject: [PATCH] MCP, #2534: list_commands {brief} lists commands without their parameter docs --- crates/mcp/src/tools.rs | 30 +++++++++++++++++++++--------- crates/mcp/tests/it/protocol.rs | 9 +++++++++ docs/mcp.md | 2 +- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/crates/mcp/src/tools.rs b/crates/mcp/src/tools.rs index 3319dff43..9a1cd44b1 100644 --- a/crates/mcp/src/tools.rs +++ b/crates/mcp/src/tools.rs @@ -164,8 +164,14 @@ fn tools() -> Vec { tool( "list_commands", "List commands", - "List FigCraft commands: id, label, menu path, shortcut, whether it is undoable, and a parameter description. Every menu item, panel action and shortcut is a command; run one with run_command (or several as one undo step with batch). Most commands act on `ids` when given, else on the selection. Use `filter` to narrow (e.g. \"align\", \"layout\", \"variable\", \"style\", \"component\", \"proto\").", - obj(json!({"filter": string("Case-insensitive substring matched against id, label, menu path and parameter docs")}), &[]), + "List FigCraft commands: id, label, menu path, shortcut, whether it is undoable, and a parameter description. Every menu item, panel action and shortcut is a command; run one with run_command (or several as one undo step with batch). Most commands act on `ids` when given, else on the selection. Use `filter` to narrow (e.g. \"align\", \"layout\", \"variable\", \"style\", \"component\", \"proto\"). `brief: true` leaves the parameter docs out (a fraction of the size) and matches `filter` against the id, label and menu path only; read one command's parameters from the figcraft://command/{id} resource or by filtering on its id.", + obj( + json!({ + "filter": string("Case-insensitive substring matched against id, label, menu path and (unless brief) parameter docs"), + "brief": {"type": "boolean", "description": "One line per command without parameter docs"} + }), + &[], + ), true, ), tool( @@ -763,16 +769,19 @@ pub fn call_tool(b: &mut dyn Backend, name: &str, args: &Value) -> ToolResult { fn list_commands(b: &mut dyn Backend, a: &Map) -> Result { let filter = s_arg(a, "filter")?.map(str::to_lowercase).unwrap_or_default(); + let brief = match a.get("brief") { + None | Some(Value::Null) => false, + Some(Value::Bool(v)) => *v, + Some(_) => return Err("`brief` must be true or false".into()), + }; + let fields: &[&str] = if brief { &["id", "label", "menu"] } else { &["id", "label", "menu", "params"] }; let all = b.call("engine.commands", json!({}))?; let list: Vec = all .as_array() .map(|v| { v.iter() .filter(|c| { - filter.is_empty() - || ["id", "label", "menu", "params"] - .iter() - .any(|k| c.get(*k).and_then(Value::as_str).is_some_and(|s| s.to_lowercase().contains(&filter))) + filter.is_empty() || fields.iter().any(|k| c.get(*k).and_then(Value::as_str).is_some_and(|s| s.to_lowercase().contains(&filter))) }) .cloned() .collect() @@ -782,7 +791,8 @@ fn list_commands(b: &mut dyn Backend, a: &Map) -> Result) -> Result