Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix(mcp): default -p connects folded .mcp.json

Cursor Agent9ec5884cc53a
diff --git a/docs/adr/0029-mcp-inside-rlm-and-return-shapes.md b/docs/adr/0029-mcp-inside-rlm-and-return-shapes.md
index 2d5e0a5e..16697bba 100644
--- a/docs/adr/0029-mcp-inside-rlm-and-return-shapes.md
+++ b/docs/adr/0029-mcp-inside-rlm-and-return-shapes.md
@@ -143,3 +143,15 @@ called `rlm`). The learnt part is therefore applied in Zig: after
When two MCP shapes are stored, `annotate` adds a one-line `# muscle:`
playbook on the load **result** (never the catalog prefix). No new
`GRAFF_` knob. Live L–Q sweep: `eval-mcp-shapes.py --only L,M,N,O,P,Q`.
+
+## Out of the box (default `-p`)
+
+Lean used to **skip MCP connect** and **hide** `load_tool_schemas` even
+when a workspace `.mcp.json` was present. That forced `--no-lean` for
+every MCP one-shot (ADR 0024 leftover). Default `-p` implies lean +
+yolo: now it **connects** and **folds** (names + one-liners, full
+schemas a load away). Empty `-p` (no deferred MCP) still hides the meta
+tool. Consent is unchanged. `--no-lean` is the eager-schema opt-out, not
+the MCP on-switch.
+
+Prove with variant **R**: `graff-dev` (no `--no-lean`) + `linear-nohint`.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index 8d77e61a..94d57321 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -39,7 +39,7 @@ record only when you need the evidence or the edge cases.
| [0026](0026-foreground-bash-auto-backgrounds.md) | Root foreground `bash` auto-backgrounds after 120s (or `timeout` ms); it is not killed. Subagents still kill at 120s (#93). |
| [0027](0027-kimi-identity-is-graff.md) | Kimi Coding User-Agent is `graff/<version>`, not a spoofed `kimi-code-cli` token. X-Msh device fields follow kimi-code's shapes. |
| [0028](0028-codex-session-id-is-the-cache-key.md) | Codex HTTP/WS `session_id` is the `prompt_cache_key` (openai/codex ModelClient default), not a per-process random UUID. |
-| [0029](0029-mcp-inside-rlm-and-return-shapes.md) | Loaded MCP tools are rlm host functions; persist return shapes on the load result, never the prefix; fat MCP results auto-slim from learnt keys. |
+| [0029](0029-mcp-inside-rlm-and-return-shapes.md) | Loaded MCP tools are rlm host functions; persist return shapes on the load result, never the prefix; fat MCP results auto-slim; default `-p` connects `.mcp.json` (folded, not skipped). |
## When to write one
diff --git a/scripts/eval-mcp-shapes.py b/scripts/eval-mcp-shapes.py
index 6ff57737..f5b5ad06 100755
--- a/scripts/eval-mcp-shapes.py
+++ b/scripts/eval-mcp-shapes.py
@@ -136,6 +136,12 @@ VARIANTS = [
"task": "linear-reduce-warm",
"label": "learnt slim + len/project recipe, warm",
},
+ {
+ "id": "R",
+ "harness": "graff-dev",
+ "task": "linear-nohint",
+ "label": "out of the box: default -p (lean + yolo), no each() hint",
+ },
]
diff --git a/scripts/test-smolify-boundary.py b/scripts/test-smolify-boundary.py
index bf4e428e..e14d872e 100644
--- a/scripts/test-smolify-boundary.py
+++ b/scripts/test-smolify-boundary.py
@@ -128,8 +128,8 @@ def run(graff: Path) -> None:
"codex",
"--yolo",
"--no-telemetry",
- # -p implies --lean, which skips MCP (ADR 0024). This
- # test is the MCP advertisement/secret-egress boundary.
+ # --no-lean so this test sees the full MCP advertisement
+ # surface (secret-egress boundary), not the lean fold.
"--no-lean",
"-p",
"try the hosted docs query, then report",
diff --git a/src/args.zig b/src/args.zig
index 67a73eeb..e28ec22d 100644
--- a/src/args.zig
+++ b/src/args.zig
@@ -34,7 +34,7 @@ pub const Flags = struct {
yolo_flag: bool = false,
safe_flag: bool = false, // --safe: one-shot WITHOUT the implied --yolo (approval-gated, the old -p default)
no_lean_flag: bool = false, // --no-lean: one-shot WITHOUT the implied --lean (full tool surface + eager MCP, the old -p default)
- lean_flag: bool = false, // --lean: skip connecting MCP servers entirely (GRAFF_LEAN=1) — a smaller per-turn prefix for one-shot/CI runs
+ lean_flag: bool = false, // --lean: slim catalog + MCP schemas folded behind load_tool_schemas (GRAFF_LEAN=1); does not skip connect
no_telemetry_flag: bool = false,
learning_privacy_flag: ?learning_privacy.Mode = null,
schema_flag: bool = false,
diff --git a/src/cli.zig b/src/cli.zig
index c4ce6c95..23d8c7f9 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -256,8 +256,8 @@ pub const usage_text =
\\ --yolo skip all permission prompts for the session
\\ --rlm advertise the rlm REPL (default; persistent binds, subagent(), llm_query, mid-stream spec-ptc; GRAFF_RLM=1)
\\ --old, --no-rlm restore the pre-rlm structured-only catalog (GRAFF_OLD=1 or GRAFF_RLM=0)
- \\ --lean slim tool surface (8 core tools) + MCP deferred behind load_tool_schemas — the DEFAULT for -p one-shots (GRAFF_LEAN=1)
- \\ --no-lean opt a one-shot out of the implied --lean: full tool surface + eager MCP, the pre-default -p behavior
+ \\ --lean slim tool surface (8 core tools) + MCP schemas folded behind load_tool_schemas — the DEFAULT for -p one-shots (GRAFF_LEAN=1). `.mcp.json` still connects.
+ \\ --no-lean opt a one-shot out of the implied --lean: full tool surface + eager MCP schemas, the pre-default -p behavior
\\ --no-local-tools embedder mode: hard-disable the built-in bash/bash_output/bash_kill/read_file/edit_file/write_file/codedb tools for the whole process (subagents included), so graff can run outside the sandbox and get its coding tools from an MCP server instead; webfetch, orchestration and MCP tools still work (GRAFF_NO_LOCAL_TOOLS=1)
\\ -p, --print one-shot print mode (answer on stdout, progress on stderr)
\\ --timing show per-tool wall-clock on result lines
diff --git a/src/mcp_schema_gate.zig b/src/mcp_schema_gate.zig
index e4d89845..abdb1338 100644
--- a/src/mcp_schema_gate.zig
+++ b/src/mcp_schema_gate.zig
@@ -295,9 +295,9 @@ pub fn hiddenSpec(name: []const u8, all: []const mcp.Tool) bool {
std.mem.eql(u8, name, "mcp_search_tools") or
std.mem.eql(u8, name, "mcp_select_tool");
if (!progressive) return false;
- // -p: even a deferred home MCP kept the 1.4kB meta tool on every
- // turn. One-shots that need MCP pass --no-lean (ADR 0024).
- if (@import("no_local_tools.zig").lean) return true;
+ // Lean used to hide this even when MCP was connected, which made
+ // default `-p` unable to unfold `.mcp.json`. Show it whenever
+ // something is deferred; hide it when the listing would be empty.
return !anyDeferred(all);
}
diff --git a/src/mcp_schema_gate_tests.zig b/src/mcp_schema_gate_tests.zig
index 1543396c..f085272b 100644
--- a/src/mcp_schema_gate_tests.zig
+++ b/src/mcp_schema_gate_tests.zig
@@ -357,9 +357,9 @@ test "an eager tool is never blocked, and the load tool is advertised only when
try testing.expect(!gate.blocked(fat, "mcp__fat__ghost"));
}
-test "lean hides load_tool_schemas even when MCP is deferred" {
- // Home Smolify still counts as deferred and used to keep the 1.4kB
- // meta tool on every -p turn. --no-lean is the MCP one-shot.
+test "lean shows load_tool_schemas only when MCP is actually deferred" {
+ // Empty -p stays cheap (no meta tool). A connected `.mcp.json` must
+ // still unfold on the default lean one-shot (ADR 0029).
const schema = @import("schema.zig");
const no_local = @import("no_local_tools.zig");
withDefaults();
@@ -374,12 +374,12 @@ test "lean hides load_tool_schemas even when MCP is deferred" {
try testing.expect(gate.hiddenSpec(gate.tool_name, &.{}));
const specs = try schema.effectiveRootSpecs(arena);
const empty = try schema.renderRootTools(arena, .openai, specs, &.{});
- try testing.expect(std.mem.indexOf(u8, empty, gate.tool_name) == null);
+ try testing.expect(std.mem.indexOf(u8, empty, "\"name\":\"load_tool_schemas\"") == null);
const fat = try fixture(arena, "fat", 8, 2000);
- try testing.expect(gate.hiddenSpec(gate.tool_name, fat));
+ try testing.expect(!gate.hiddenSpec(gate.tool_name, fat));
const with_mcp = try schema.renderRootTools(arena, .openai, specs, fat);
- try testing.expect(std.mem.indexOf(u8, with_mcp, gate.tool_name) == null);
+ try testing.expect(std.mem.indexOf(u8, with_mcp, "\"name\":\"load_tool_schemas\"") != null);
}
test "tool_desc stays JSON-escape-free (it is spliced into a raw schema string)" {
diff --git a/src/no_local_tools.zig b/src/no_local_tools.zig
index c112088e..45f65d4f 100644
--- a/src/no_local_tools.zig
+++ b/src/no_local_tools.zig
@@ -66,7 +66,7 @@ pub fn blocks(name: []const u8) bool {
}
/// --lean / GRAFF_LEAN=1 tool surface — the token-cost counterpart of the MCP
-/// skip (session_start.leanSkipsMcp reads the same flag/env). A one-shot
+/// fold (session_start.leanMode reads the same flag/env). A one-shot
/// coding task keeps the file/shell tools plus attempt_completion; every
/// other schema is prefix re-sent on EVERY model turn. Unlike #330 this
/// is NOT a security boundary: an unadvertised tool is simply unknown.
@@ -77,7 +77,8 @@ pub var lean: bool = false;
/// calls / 4/6. Dropping catalog `read_file` (085320) made it worse
/// (63 calls) — the model retried rlm/bash cat when print(read_file)
/// was a no-op. `load_tool_schemas` stays so MCP can unfold; it is
-/// hidden on lean. Overflow paging (`read_tool_result`) is interactive.
+/// hidden only when nothing is deferred. Overflow paging
+/// (`read_tool_result`) is interactive.
pub const lean_tools = [_][]const u8{
"bash",
"read_file",
@@ -396,7 +397,7 @@ test "lean catalog drops overflow pager and empty load_tool_schemas" {
const specs = try schema.effectiveRootSpecs(arena);
const json = try schema.renderRootTools(arena, .openai, specs, &.{});
try std.testing.expect(std.mem.indexOf(u8, json, "read_tool_result") == null);
- try std.testing.expect(std.mem.indexOf(u8, json, "load_tool_schemas") == null);
+ try std.testing.expect(std.mem.indexOf(u8, json, "\"name\":\"load_tool_schemas\"") == null);
try std.testing.expect(std.mem.indexOf(u8, json, "\"rlm\"") != null);
try std.testing.expect(std.mem.indexOf(u8, json, "\"name\":\"read_file\"") != null);
}
diff --git a/src/rlm.zig b/src/rlm.zig
index f4e7c03d..a2a95ae3 100644
--- a/src/rlm.zig
+++ b/src/rlm.zig
@@ -27,7 +27,7 @@ pub const tool_name = "rlm";
pub const tool_desc = "Programmatic tool calling (RLM + sPTC). Functions ARE this session's tools. Literal read_file/codedb/bash/webfetch/sleep_ms/llm_query/subagent start as the script streams. Binds persist. subagent(\"task\") is sidecar-only (keep the critical-path next step local). Loaded MCP names are host functions after load_tool_schemas; each(arr, tool, field) maps a JSON array; len(x)/project(x, field) slim it. print() is the answer. Prefer one rlm over N tool calls.";
/// --lean catalog desc: same contract, no REPL essay. maybeAppend is after
/// compactLeanSpecs, so this is the one-shot wire text.
-pub const lean_tool_desc = "Batch independent read_file/codedb/bash here. print(read_file(\"p\")) returns the file — do not catalog-read it again. Then edit_file/write_file/bash as catalog tools. Literal calls start as it streams. Binds persist.";
+pub const lean_tool_desc = "Batch independent read_file/codedb/bash here. print(read_file(\"p\")) returns the file — do not catalog-read it again. Then edit_file/write_file/bash as catalog tools. Literal calls start as it streams. Binds persist. Loaded MCP names are host functions after load_tool_schemas.";
pub const tool_schema =
\\{"type": "object", "properties": {"code": {"type": "string", "description": "Python-like script: name = read_file(\"path\") / codedb(\"command\") / bash(\"cmd\") / sleep_ms(ms) / llm_query(\"prompt\") / subagent(\"task\") / loaded mcp__server__tool(); each(arr, tool, field) maps a JSON array; len(x) and project(x, field) slim it; print(...) is the result. Assignments persist across rlm calls."}}, "required": ["code"]}
;
diff --git a/src/rlm_mcp.zig b/src/rlm_mcp.zig
index 78467501..e152ae62 100644
--- a/src/rlm_mcp.zig
+++ b/src/rlm_mcp.zig
@@ -270,6 +270,10 @@ test "unloaded MCP name is refused; loaded name is prepared for exec" {
}
}
+test "MCP-inside-rlm host functions are on by default" {
+ try std.testing.expect(host_enabled);
+}
+
test "short name resolves when unique and loaded; consent/deferral still block" {
const gpa = std.testing.allocator;
var arena_state = std.heap.ArenaAllocator.init(gpa);
diff --git a/src/rlm_tests.zig b/src/rlm_tests.zig
index 0cfe4401..41da1e77 100644
--- a/src/rlm_tests.zig
+++ b/src/rlm_tests.zig
@@ -370,6 +370,8 @@ test "rlm prompt: subagent() is advertised as sidecar-only, not a critical-path
try std.testing.expect(std.mem.indexOf(u8, rlm_spec.system_note, "sidecar-only") != null);
try std.testing.expect(std.mem.indexOf(u8, rlm_spec.system_note, "critical-path") != null);
try std.testing.expect(rlm.tool_desc.len < 600);
+ try std.testing.expect(std.mem.indexOf(u8, rlm.lean_tool_desc, "load_tool_schemas") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rlm.lean_tool_desc, "MCP") != null);
}
test "runScript refuses an unloaded MCP name and does not treat it as a host tool" {
diff --git a/src/session_settings.zig b/src/session_settings.zig
index bfb5a3c6..7f2c7645 100644
--- a/src/session_settings.zig
+++ b/src/session_settings.zig
@@ -138,7 +138,7 @@ pub fn applyEnvKnobs(arena: Allocator, environ_map: anytype) !void {
}
}
if (environ_map.get("GRAFF_NO_LOCAL_TOOLS")) |v| no_local_tools.enabled = no_local_tools.enabled or no_local_tools.envEnables(v);
- // GRAFF_LEAN: presence-based, exactly matching session_start.leanSkipsMcp
+ // GRAFF_LEAN: presence-based, matching session_start.leanMode
// (the MCP half of the same switch) — a "0" still means lean, by design.
if (environ_map.get("GRAFF_LEAN") != null) no_local_tools.lean = true;
// GRAFF_REQ_STATS: presence-based request-anatomy print (req_stats).
diff --git a/src/session_start.zig b/src/session_start.zig
index 4779e584..b262512c 100644
--- a/src/session_start.zig
+++ b/src/session_start.zig
@@ -439,10 +439,10 @@ pub fn initRegistryConsent(io: Io, gpa: Allocator, arena: Allocator, out: *Io.Wr
}
const mcp_count = mcp_cli.countMcpServers(merged);
const defer_join = flags.effectiveYolo() and flags.oneshot_prompt == null and !json_mode;
+ // Lean folds schemas (deferAllRuntime); it does not skip connect.
+ // --yolo / -p still connect so `.mcp.json` works on the default one-shot
+ // (ADR 0029). Interactive without --yolo still asks.
var connect_mcp = flags.yolo_flag or mcp_count == 0;
- // Lean: home MCP (Smolify) was 1.4kB of load_tool_schemas on every
- // turn. Sessions that need MCP pass --no-lean (ADR 0024).
- if (leanMode(flags.effectiveLean(), environ_map)) connect_mcp = false;
if (mcp_count > 0 and !flags.yolo_flag and !json_mode and use_color) {
sink.emit(io, .{ .mcp_consent_prompt = .{ .count = mcp_count } });
// Still an inline read: only the QUESTION is inverted here, and the