Skip to content

Commit 4b88690

Browse files
committed
fix(mcp): give format:"json" the evidence columns it advertises (DeusData#1542)
`trace_path(include_evidence:true)` added `strategy` and `confidence` per hop in the default tree output, and returned `cols: ["name","hop"]` under format:"json" — no error, no warning, just two fields missing from the response shape the schema and `--help` both promise. include_evidence was only ever implemented in bfs_to_tree_table; bfs_to_tree_json never took the flag. So the callers most likely to want the evidence — the ones asking for structured output to consume programmatically — were exactly the ones who silently got none of it. Reported by @asemraza. The json path now emits both columns with the same semantics as the tree path, including the placeholder case: the root hop has no inbound edge and non-CALLS edges record no strategy, so those rows carry nulls rather than dropping fields and leaving callers with ragged rows. Tree says "-", json says null — the same promise in the form each consumer can test. The existing evidence test covered only the tree path, which is why this went unnoticed; it now asserts both formats. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent f3d78b1 commit 4b88690

2 files changed

Lines changed: 55 additions & 7 deletions

File tree

‎src/mcp/mcp.c‎

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6203,14 +6203,23 @@ static int trace_watermark_index(const cbm_traverse_result_t *tr, int hop, int64
62036203
* output — {cols, groups:[{qn_prefix, rows:[[name,hop,...]]}]}. Optional
62046204
* risk/args columns mirror the flags. */
62056205
static yyjson_mut_val *bfs_to_tree_json(yyjson_mut_doc *doc, cbm_traverse_result_t *tr,
6206-
bool risk_labels, bool include_tests, bool data_flow) {
6206+
bool risk_labels, bool include_tests, bool data_flow,
6207+
bool include_evidence) {
62076208
yyjson_mut_val *leg = yyjson_mut_obj(doc);
62086209
yyjson_mut_val *cols = yyjson_mut_arr(doc);
62096210
yyjson_mut_arr_add_str(doc, cols, "name");
62106211
yyjson_mut_arr_add_str(doc, cols, "hop");
62116212
if (risk_labels) {
62126213
yyjson_mut_arr_add_str(doc, cols, "risk");
62136214
}
6215+
/* #1542: include_evidence was implemented on the tree path only, so
6216+
* format:"json" silently returned cols ["name","hop"] while the schema and
6217+
* --help promised two more. A structured caller — the one most likely to
6218+
* ask for json — got no error, just missing fields. */
6219+
if (include_evidence) {
6220+
yyjson_mut_arr_add_str(doc, cols, "strategy");
6221+
yyjson_mut_arr_add_str(doc, cols, "confidence");
6222+
}
62146223
if (data_flow) {
62156224
yyjson_mut_arr_add_str(doc, cols, "args");
62166225
}
@@ -6258,6 +6267,25 @@ static yyjson_mut_val *bfs_to_tree_json(yyjson_mut_doc *doc, cbm_traverse_result
62586267
yyjson_mut_arr_add_str(doc, row, "");
62596268
}
62606269
}
6270+
if (include_evidence) {
6271+
const char *ev_class = NULL;
6272+
double ev_conf = -1.0;
6273+
if (bfs_edge_evidence_for_hop(tr, tr->visited[i].node.id, &ev_class, &ev_conf)) {
6274+
yyjson_mut_arr_add_strcpy(doc, row, ev_class ? ev_class : "");
6275+
if (ev_conf >= 0.0) {
6276+
yyjson_mut_arr_add_real(doc, row, ev_conf);
6277+
} else {
6278+
yyjson_mut_arr_add_null(doc, row);
6279+
}
6280+
} else {
6281+
/* The root hop has no inbound edge and non-CALLS edges record
6282+
* no strategy. The tree path emits "-" placeholders to keep the
6283+
* column count fixed; json says null, which is the same promise
6284+
* in a form a structured caller can test. */
6285+
yyjson_mut_arr_add_null(doc, row);
6286+
yyjson_mut_arr_add_null(doc, row);
6287+
}
6288+
}
62616289
yyjson_mut_arr_add_val(cur_rows, row);
62626290
}
62636291
yyjson_mut_obj_add_val(doc, leg, "groups", groups);
@@ -6710,15 +6738,15 @@ static char *handle_trace_call_path(cbm_mcp_server_t *srv, const char *args) {
67106738
}
67116739
if (do_outbound) {
67126740
yyjson_mut_obj_add_int(doc, root, "callees_total", out_total);
6713-
yyjson_mut_obj_add_val(
6714-
doc, root, "callees",
6715-
bfs_to_tree_json(doc, &view_out, risk_labels, include_tests, data_flow));
6741+
yyjson_mut_obj_add_val(doc, root, "callees",
6742+
bfs_to_tree_json(doc, &view_out, risk_labels, include_tests,
6743+
data_flow, include_evidence));
67166744
}
67176745
if (do_inbound) {
67186746
yyjson_mut_obj_add_int(doc, root, "callers_total", in_total);
6719-
yyjson_mut_obj_add_val(
6720-
doc, root, "callers",
6721-
bfs_to_tree_json(doc, &view_in, risk_labels, include_tests, data_flow));
6747+
yyjson_mut_obj_add_val(doc, root, "callers",
6748+
bfs_to_tree_json(doc, &view_in, risk_labels, include_tests,
6749+
data_flow, include_evidence));
67226750
}
67236751
if (more_rows) {
67246752
yyjson_mut_obj_add_bool(doc, root, "truncated", true);

‎tests/test_mcp.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3161,6 +3161,26 @@ TEST(tool_trace_path_evidence_is_opt_in_and_class_mapped) {
31613161
ASSERT_NULL(strstr(ev_txt, "lsp_trait_dispatch"));
31623162
free(ev_txt);
31633163
free(ev);
3164+
3165+
/* #1542: the same request with format:"json" returned cols ["name","hop"]
3166+
* — include_evidence was implemented on the tree path only, so the callers
3167+
* most likely to ask for structured output were the ones who silently got
3168+
* nothing. The two formats must promise the same fields. */
3169+
char *ev_json = cbm_mcp_server_handle(
3170+
srv, "{\"jsonrpc\":\"2.0\",\"id\":93,\"method\":\"tools/call\","
3171+
"\"params\":{\"name\":\"trace_path\",\"arguments\":{\"function_name\":\"caller\","
3172+
"\"project\":\"ev-proj\",\"direction\":\"outbound\",\"include_evidence\":true,"
3173+
"\"format\":\"json\"}}}");
3174+
ASSERT_NOT_NULL(ev_json);
3175+
char *ev_json_txt = extract_text_content(ev_json);
3176+
ASSERT_NOT_NULL(ev_json_txt);
3177+
ASSERT_NOT_NULL(strstr(ev_json_txt, "\"strategy\""));
3178+
ASSERT_NOT_NULL(strstr(ev_json_txt, "\"confidence\""));
3179+
ASSERT_NOT_NULL(strstr(ev_json_txt, "lsp"));
3180+
ASSERT_NOT_NULL(strstr(ev_json_txt, "0.95"));
3181+
ASSERT_NULL(strstr(ev_json_txt, "lsp_trait_dispatch"));
3182+
free(ev_json_txt);
3183+
free(ev_json);
31643184
cbm_mcp_server_free(srv);
31653185
PASS();
31663186
}

0 commit comments

Comments
 (0)