Skip to content

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

Python

rlm: a lone object argument is the keyword arguments (ADR 0236)

justrachb08198712a72
diff --git a/docs/adr/0236-rlm-takes-json-literals-and-each-maps-plain-values.md b/docs/adr/0236-rlm-takes-json-literals-and-each-maps-plain-values.md
index 7fb2515f..c9bcb795 100644
--- a/docs/adr/0236-rlm-takes-json-literals-and-each-maps-plain-values.md
+++ b/docs/adr/0236-rlm-takes-json-literals-and-each-maps-plain-values.md
@@ -28,6 +28,9 @@ off they did it often enough to cost real time on MCP tasks:
text as a JSON string. `True`, `False`, `None` and single-quoted strings are
read the Python way. `name = "text"`, `name = 3` and `name = other` bind too
(`rlm_literal.zig`). For `write_file`, the file holds the literal's JSON text.
+ A lone object argument is the keyword arguments: `tool({"id": "x"})` is
+ `tool(id="x")`. Passed as the first parameter's value instead, the object
+ reached an MCP server as a malformed id.
- The statement and argument splitters nest `[...]` and `{...}` as well as
`(...)`.
- `each(arr, tool[, field])`: `arr` may be a literal; a plain item (a string
diff --git a/src/rlm_literal_tests.zig b/src/rlm_literal_tests.zig
index 9d767ac7..7d67f933 100644
--- a/src/rlm_literal_tests.zig
+++ b/src/rlm_literal_tests.zig
@@ -72,3 +72,13 @@ test "ADR 0236: an unsupported statement lists the forms that work" {
try std.testing.expect(out.is_error);
try std.testing.expect(std.mem.indexOf(u8, out.text, "A statement is one of") != null);
}
+
+test "ADR 0236: a lone object argument is the keyword arguments" {
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+ const ptc = @import("spec_ptc.zig");
+ const call = (try ptc.extractCallBound(arena.allocator(), "c = mcp__linear__list_comments({\"id\": \"ISS-1\"})", &.{})).?;
+ try std.testing.expectEqualStrings("{\"id\":\"ISS-1\"}", call.args_json);
+ const list = (try ptc.extractCallBound(arena.allocator(), "c = mcp__linear__get_many([\"ISS-1\"])", &.{})).?;
+ try std.testing.expectEqualStrings("{\"arg\":[\"ISS-1\"]}", list.args_json);
+}
diff --git a/src/spec_ptc.zig b/src/spec_ptc.zig
index e745fb5e..7dd17afe 100644
--- a/src/spec_ptc.zig
+++ b/src/spec_ptc.zig
@@ -345,7 +345,12 @@ fn canonicalize(arena: Allocator, tool: []const u8, args: []const Arg) ![]const
else => |v| v,
});
} else if (args.len == 1 and args[0].key == null) {
- try putValue(arena, &obj, field, args[0].value);
+ // ADR 0236: `tool({"id": "x"})` is `tool(id="x")`, not an object for the first parameter.
+ const kw: ?std.json.Value = switch (args[0].value) {
+ .json => |j| try std.json.parseFromSliceLeaky(std.json.Value, arena, j, .{}),
+ else => null,
+ };
+ if (kw != null and kw.? == .object) obj = kw.?.object else try putValue(arena, &obj, field, args[0].value);
} else {
for (args) |a| {
const k = a.key orelse return error.NeedKeywords;