Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
46ee1a8
mcp: port the automation roots onto the clap CLI
nicholasgower Nov 2, 2026
0f33f43
security: confine plotter settings I/O and refuse the write root itself
nicholasgower Oct 22, 2026
f09c50d
mcp: refuse unclassified commands under the automation roots and walk…
adikshan11 Nov 4, 2026
c03fb71
Merge remote-tracking branch 'origin/main' into carry/1472-automation…
adikshan11 Nov 5, 2026
09e4f90
Hold automation roots to exact names, the folder a name stands in, an…
adikshan11 Nov 5, 2026
290e578
Give the automation root tests folders of their own, and a control fo…
adikshan11 Nov 6, 2026
0479ddc
Merge remote-tracking branch 'origin/main' into carry/1472-automation…
adikshan11 Nov 6, 2026
b19c366
Classify the commands main added under the automation roots
adikshan11 Nov 6, 2026
8314fb8
Search fonts beside a drawing when they stay inside the roots, and ke…
adikshan11 Nov 6, 2026
1a64ca2
Document the functions the automation roots touch
adikshan11 Nov 6, 2026
8a42e8a
Refuse a network path before the automation roots open it
adikshan11 Nov 6, 2026
19495fc
Merge remote-tracking branch 'upstream/main' into cursor/automation-r…
adikshan11 Nov 12, 2026
5785644
Fix the Windows clippy lints and the junction test, and state each pr…
adikshan11 Nov 12, 2026
387a6e6
Check each font the search would open under the roots, and say what c…
adikshan11 Nov 14, 2026
d4c4c79
Probe only the places the roots allow when matching a name's case, an…
adikshan11 Nov 14, 2026
99118a2
Document the font guard's remaining functions and the xref case test
adikshan11 Nov 14, 2026
cebfbeb
Merge remote-tracking branch 'origin/main' into carry/1472-automation…
adikshan11 Nov 14, 2026
99f442d
Skip the case-correction test where the file system ignores case
adikshan11 Nov 14, 2026
4efecc2
Keep every owner's font guard for a folder and require all of them
adikshan11 Nov 14, 2026
8cfb9cf
Hold a font folder named twice to its guards, and fix the guard test'…
adikshan11 Nov 14, 2026
72ff6c6
Merge remote-tracking branch 'origin/main' into carry/1472-automation…
adikshan11 Nov 14, 2026
d4c1ae0
Keep a folder's font guards after it drops off the list of drawing fo…
adikshan11 Nov 14, 2026
9cea2f7
Keep a refusal found by case correction, stat the .bak name without f…
adikshan11 Nov 14, 2026
61cfaab
Report a case-corrected name the roots refuse as a refusal
adikshan11 Nov 14, 2026
529b75f
Format the new code and assert the walk's seed circle has a handle
adikshan11 Nov 14, 2026
e10109e
Document that a reference outside the roots can load a same-named fil…
adikshan11 Nov 14, 2026
6dfcbf2
Keep every guard given past the limit instead of replacing one with a…
adikshan11 Nov 14, 2026
8b5503e
Require write evidence for the writer controls and read evidence for …
adikshan11 Nov 14, 2026
f097a68
Count plottermanager as a reader in the control walk, and list every …
adikshan11 Nov 14, 2026
de6b841
Track a full overflow list with a flag, not an owner name
adikshan11 Nov 14, 2026
b42d54a
Give the font guard tests an exclusive, self-cleaning folder and reso…
adikshan11 Nov 15, 2026
8cbade6
Ask the guards about a font folder before listing it, and document co…
adikshan11 Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ The logger is `apps/cadcraft/src/logging.rs`; the web build logs to the browser
cadcraft-cli mcp
# …or bridged to the running app (start it with --control 7979):
cadcraft-cli mcp --connect 127.0.0.1:7979
# …or headless, with the agent confined to a work folder:
cadcraft-cli mcp --automation-read-root ~/work --automation-write-root ~/work/out

# One-shot headless runs:
cadcraft-cli run --sample --script 'CIRCLE 22,3 1\n' --save out.dxf --export out.png
Expand Down
48 changes: 42 additions & 6 deletions apps/cadcraft-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ pub(crate) struct McpArgs {
/// port first (macOS)
#[arg(long, requires = "connect")]
pub(crate) launch: bool,
/// The only folder the agent's commands may read from; reads are also allowed under the write
/// root (headless only)
#[arg(long, value_name = "DIR")]
pub(crate) automation_read_root: Option<String>,
/// The only folder the agent's commands may write to, never the folder itself (headless only)
#[arg(long, value_name = "DIR")]
pub(crate) automation_write_root: Option<String>,
#[command(flatten)]
pub(crate) settings: Settings,
}
Expand Down Expand Up @@ -408,12 +415,18 @@ enum UsageError {
/// The output is one of the input files, so writing it would replace the original.
#[error("{} is an input file, so the result would replace the original: choose another output, or pass --in-place to overwrite it", .0.display())]
OutIsInput(PathBuf),
/// The automation roots confine the headless server; a running app enforces its own access.
#[error(
"--automation-read-root and --automation-write-root confine the headless MCP server; a running app enforces its own file access (not yet available: see issue #1585)"
)]
AutomationRootsNeedHeadless,
}

impl UsageError {
/// This error in clap's form, so it prints with the usual usage text.
fn into_clap(self, cmd: &mut clap::Command) -> clap::Error {
let kind = match self {
Self::FramingNeedsImage { .. } | Self::OutIsInput(_) => ErrorKind::ArgumentConflict,
Self::FramingNeedsImage { .. } | Self::OutIsInput(_) | Self::AutomationRootsNeedHeadless => ErrorKind::ArgumentConflict,
};
cmd.error(kind, self)
}
Expand Down Expand Up @@ -485,6 +498,13 @@ fn framing_error(cli: &Cli) -> Option<UsageError> {
(!cadcraft_io::is_image(out)).then(|| UsageError::FramingNeedsImage { flag, out: out.to_path_buf() })
}

/// The automation roots confine the headless server only, as the other Craft apps' do.
fn roots_need_headless(cli: &Cli) -> Option<UsageError> {
let Command::Mcp(m) = &cli.command else { return None };
(m.connect.is_some() && (m.automation_read_root.is_some() || m.automation_write_root.is_some()))
.then_some(UsageError::AutomationRootsNeedHeadless)
}

/// An output that is the same file as an input, without `--in-place`. An output that doesn't exist
/// can't be an input, and an I/O error in the comparison is left to the open or write that follows.
fn out_is_input(cli: &Cli) -> Option<UsageError> {
Expand All @@ -503,19 +523,20 @@ fn out_is_input(cli: &Cli) -> Option<UsageError> {
/// The backend `cadcraft-cli mcp` serves from.
#[derive(Debug, PartialEq, Eq)]
pub(crate) enum McpTarget {
/// An in-process drawing session (no `--connect`).
Headless,
/// An in-process drawing session (no `--connect`), optionally confined to the two folders.
Headless { read_root: Option<String>, write_root: Option<String> },
/// The running app's control channel at `HOST:PORT`; `lazy`: reached at the first call;
/// `launch`: opened then if it isn't running.
Connect { addr: String, lazy: bool, launch: bool },
}

impl McpArgs {
/// What these arguments ask the server to talk to.
pub(crate) fn target(&self) -> McpTarget {
match &self.connect {
// `--launch` connects at the first call too (the app opens then).
Some(addr) => McpTarget::Connect { addr: addr.clone(), lazy: self.lazy || self.launch, launch: self.launch },
None => McpTarget::Headless,
None => McpTarget::Headless { read_root: self.automation_read_root.clone(), write_root: self.automation_write_root.clone() },
}
}
}
Expand Down Expand Up @@ -588,7 +609,7 @@ fn parse_with(mut cmd: clap::Command, args: &[OsString]) -> Result<Cli, clap::Er
if let (Command::Run(r), Some((_, m))) = (&mut cli.command, matches.subcommand()) {
(r.drawings, r.steps) = run_order(m);
}
if let Some(e) = framing_error(&cli).or_else(|| out_is_input(&cli)) {
if let Some(e) = framing_error(&cli).or_else(|| out_is_input(&cli)).or_else(|| roots_need_headless(&cli)) {
if let Some(sub) = matches.subcommand_name().and_then(|n| cmd.find_subcommand_mut(n)) {
return Err(e.into_clap(sub));
}
Expand Down Expand Up @@ -644,9 +665,24 @@ mod tests {
}
}

/// Without `--connect` the server runs headless, confining nothing unless asked.
#[test]
fn mcp_without_connect_is_headless() {
assert_eq!(mcp(&[]).unwrap(), McpTarget::Headless);
assert_eq!(mcp(&[]).unwrap(), McpTarget::Headless { read_root: None, write_root: None });
}

/// The automation roots confine a headless server; `--connect` is refused with the reason
/// (the running app's control channel is not confined yet, #1585).
#[test]
fn mcp_automation_roots_confine_a_headless_server_only() {
assert_eq!(
mcp(&["--automation-read-root", "/work", "--automation-write-root=/work/out"]).unwrap(),
McpTarget::Headless { read_root: Some("/work".into()), write_root: Some("/work/out".into()) }
);
let e = mcp(&["--connect", "127.0.0.1:7979", "--automation-read-root", "/work"]).unwrap_err().to_string();
assert!(e.contains("headless MCP server") && e.contains("#1585"), "{e}");
let e = mcp(&["--automation-write-root=/work", "--connect", "127.0.0.1:7979"]).unwrap_err().to_string();
assert!(e.contains("headless MCP server"), "{e}");
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions apps/cadcraft-cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub(crate) enum CliError {
NotUnicode(std::path::PathBuf),
#[error("cannot connect to {addr}: {source}")]
McpConnect { addr: String, source: std::io::Error },
/// An `--automation-*-root` that cannot be opened (missing, a file, a link that escapes).
#[error("{0}")]
AutomationRoots(String),
}

pub(crate) type Result<T = (), E = CliError> = std::result::Result<T, E>;
10 changes: 9 additions & 1 deletion apps/cadcraft-cli/src/mcp.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
use super::args::{McpArgs, McpTarget};
use super::error::{CliError, Result};

/// Serve MCP on stdin and stdout against the running app or a headless session held to any roots given.
pub(crate) fn mcp(a: &McpArgs) -> Result {
let backend: Box<dyn cadcraft_mcp::Backend> = match a.target() {
McpTarget::Connect { addr, lazy: true, launch } => Box::new(cadcraft_mcp::Remote::lazy(&addr, launch)),
McpTarget::Connect { addr, .. } => match cadcraft_mcp::Remote::connect(&addr) {
Ok(r) => Box::new(r),
Err(source) => return Err(CliError::McpConnect { addr, source }),
},
McpTarget::Headless => Box::new(cadcraft_mcp::Headless::default()),
McpTarget::Headless { read_root, write_root } => {
let roots = cadcraft_engine::file_access::AutomationRoots::new(
read_root.as_deref().map(std::path::Path::new),
write_root.as_deref().map(std::path::Path::new),
)
.map_err(CliError::AutomationRoots)?;
Box::new(cadcraft_mcp::Headless::default().with_automation_roots(roots))
}
};
let stdin = std::io::stdin();
let stdout = std::io::stdout();
Expand Down
Loading
Loading