libmcp: arguments that arrive as a string no longer mean "no filter"
Refresh the vendored header to libmcp 6d2fcb4. A client in the OpenAI
function-call shape sends arguments as a JSON string; until now every handler
saw no argument at all, so task_next(scope="splinter") claimed the
highest-priority task of the whole store - t0352, makronix/mcde, priority 630 -
because scope was invisible to it (2026-11-22, written up in that task).
The new test replays exactly that: two tasks, one at priority 900 in
makronix/mcde and one at 1 in splinter, then tools/call with
"arguments":"{\"scope\": \"splinter\"}". It must claim the splinter task.
tests/run.py 27 PASS, 0 FAIL; test-http.sh ok.
This commit is contained in:
1 parent
e557edd3ae
commit
5e28b21f47
2 files changed
+95
-1
No files matched your search
@@ -30,6 +30,14 @@ def run(msgs):
|
||||
return [json.loads(l) for l in proc.stdout.splitlines() if l.strip()]
|
||||
|
||||
|
||||
def run_in(root, msgs):
|
||||
env = dict(os.environ)
|
||||
env["TASKDIR"] = root
|
||||
proc = subprocess.run([BIN], input="\n".join(json.dumps(m) for m in msgs) + "\n",
|
||||
capture_output=True, text=True, env=env, timeout=60)
|
||||
return [json.loads(l) for l in proc.stdout.splitlines() if l.strip()]
|
||||
|
||||
|
||||
def txt(r):
|
||||
try:
|
||||
return r["result"]["content"][0]["text"]
|
||||
@@ -174,6 +182,32 @@ if ready:
|
||||
check("http: the write is in the same files",
|
||||
os.path.isfile(os.path.join(ROOT, "t0004.json")), sorted(os.listdir(ROOT)))
|
||||
|
||||
# ---- arguments that arrive as a JSON string ------------------------------
|
||||
# A client in the OpenAI/Anthropic function-call shape sends
|
||||
# "arguments":"{\"scope\": \"fleet\"}" - a string, not an object. Until
|
||||
# libmcp parsed that, every handler saw no argument at all and task_next with
|
||||
# scope="splinter" handed out the highest-priority task of ANOTHER project
|
||||
# (found 2026-11-22: t0352 makronix/mcde claimed by an agent that asked for
|
||||
# scope="splinter"). Its own store, so the counts above stay predictable.
|
||||
string_root = tempfile.mkdtemp(prefix="tasksd-string-")
|
||||
string_run = run_in(string_root, [
|
||||
{"jsonrpc": "2.0", "id": 1, "method": "initialize",
|
||||
"params": {"protocolVersion": "2024-11-05", "capabilities": {}}},
|
||||
{"jsonrpc": "2.0", "method": "notifications/initialized"},
|
||||
call(2, "task_create", title="big elsewhere", goal="other project",
|
||||
scope="makronix/mcde", priority=900),
|
||||
call(3, "task_create", title="mine", goal="this project", scope="splinter", priority=1),
|
||||
# arguments as a string: the shape a proxy in the OpenAI format produces
|
||||
{"jsonrpc": "2.0", "id": 4, "method": "tools/call",
|
||||
"params": {"name": "task_next", "arguments": "{\"scope\": \"splinter\"}"}},
|
||||
])
|
||||
sby = {r.get("id"): r for r in string_run}
|
||||
claimed = json.loads(txt(sby.get(4, {}))).get("task")
|
||||
check("arguments sent as a string are still a scope filter",
|
||||
claimed is not None and claimed.get("scope") == "splinter",
|
||||
claimed if claimed is None else claimed.get("scope"))
|
||||
shutil.rmtree(string_root, ignore_errors=True)
|
||||
|
||||
proc.terminate()
|
||||
proc.wait(timeout=10)
|
||||
shutil.rmtree(ROOT, ignore_errors=True)
|
||||
|
||||
Vendored
+61
-1
@@ -731,22 +731,80 @@ static void tools_list(mcp_conn *c, const mcp_server *srv)
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
/*
|
||||
* The arguments of a tools/call, always as an object or NULL.
|
||||
*
|
||||
* Some clients send arguments as a JSON *string* instead of an object: the
|
||||
* OpenAI/Anthropic function-call shape has "arguments":"{\"key\":1}", and a
|
||||
* proxy that forwards that shape unchanged produces exactly such a request.
|
||||
* Passing the string straight to the handler made mcp_arg() return NULL for
|
||||
* every key, so a handler that filters on an argument silently saw "no
|
||||
* filter" and acted on everything - task_next(scope="splinter") handed out a
|
||||
* makronix task because scope was invisible to it. So: a string is parsed,
|
||||
* and anything that does not yield an object is an error, never "no
|
||||
* arguments".
|
||||
*
|
||||
* Returns 0 and sets *outp, or -1 when the value is neither absent, an object,
|
||||
* nor a string holding an object. *owned says who owns the object: when it is
|
||||
* 0 the object is part of the request and must NOT be freed; when it is 1 the
|
||||
* caller frees it with mcp_json_free.
|
||||
*/
|
||||
static int call_arguments(const mcp_json *params, mcp_json **outp, int *owned)
|
||||
{
|
||||
const mcp_json *args = params != NULL ? mcp_arg(params, "arguments") : NULL;
|
||||
|
||||
*outp = NULL;
|
||||
*owned = 0;
|
||||
if (args == NULL || args->t == MCP_NULL)
|
||||
return 0;
|
||||
if (args->t == MCP_OBJ) {
|
||||
*outp = (mcp_json *)args;
|
||||
return 0;
|
||||
}
|
||||
if (args->t == MCP_STR) {
|
||||
mcp_json *v = mcp_parse(args->s);
|
||||
|
||||
if (v == NULL || v->t != MCP_OBJ) {
|
||||
mcp_json_free(v);
|
||||
return -1;
|
||||
}
|
||||
*outp = v;
|
||||
*owned = 1;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void tools_call(mcp_conn *c, const mcp_server *srv, const mcp_json *params)
|
||||
{
|
||||
const char *name = mcp_arg_string(params, "name");
|
||||
const mcp_json *args = mcp_arg(params, "arguments");
|
||||
mcp_json *parsed = NULL;
|
||||
const mcp_json *args;
|
||||
int owned = 0;
|
||||
size_t i;
|
||||
|
||||
if (name == NULL) {
|
||||
mcp_reply_rpc_error(c, -32602, "missing tool name");
|
||||
return;
|
||||
}
|
||||
if (call_arguments(params, &parsed, &owned) != 0) {
|
||||
mcp_buf b;
|
||||
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_printf(&b, "the arguments of '%s' are not a JSON object", name);
|
||||
emit_content(c, b.p, 1);
|
||||
mcp_buf_free(&b);
|
||||
return;
|
||||
}
|
||||
args = parsed;
|
||||
for (i = 0; i < srv->ntools; i++) {
|
||||
if (strcmp(srv->tools[i].name, name) != 0)
|
||||
continue;
|
||||
c->replied = 0;
|
||||
if (srv->tools[i].handler != NULL)
|
||||
srv->tools[i].handler(c, args, srv->user);
|
||||
if (owned)
|
||||
mcp_json_free(parsed);
|
||||
if (!c->replied) {
|
||||
mcp_buf b;
|
||||
|
||||
@@ -760,6 +818,8 @@ static void tools_call(mcp_conn *c, const mcp_server *srv, const mcp_json *param
|
||||
{
|
||||
mcp_buf b;
|
||||
|
||||
if (owned)
|
||||
mcp_json_free(parsed);
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_printf(&b, "unknown tool: %s", name);
|
||||
mcp_reply_rpc_error(c, -32601, b.p);
|
||||
|
||||
Reference in new issue
Block a user