Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(mcp): give format:"json" the evidence columns it advertises (#1542)

Martin Vogel4b886904d70b
diff --git a/src/mcp/mcp.c b/src/mcp/mcp.c
index 2bbbec52d..7cbee0bf9 100644
--- a/src/mcp/mcp.c
+++ b/src/mcp/mcp.c
@@ -6203,7 +6203,8 @@ static int trace_watermark_index(const cbm_traverse_result_t *tr, int hop, int64
* output — {cols, groups:[{qn_prefix, rows:[[name,hop,...]]}]}. Optional
* risk/args columns mirror the flags. */
static yyjson_mut_val *bfs_to_tree_json(yyjson_mut_doc *doc, cbm_traverse_result_t *tr,
- bool risk_labels, bool include_tests, bool data_flow) {
+ bool risk_labels, bool include_tests, bool data_flow,
+ bool include_evidence) {
yyjson_mut_val *leg = yyjson_mut_obj(doc);
yyjson_mut_val *cols = yyjson_mut_arr(doc);
yyjson_mut_arr_add_str(doc, cols, "name");
@@ -6211,6 +6212,14 @@ static yyjson_mut_val *bfs_to_tree_json(yyjson_mut_doc *doc, cbm_traverse_result
if (risk_labels) {
yyjson_mut_arr_add_str(doc, cols, "risk");
}
+ /* #1542: include_evidence was implemented on the tree path only, so
+ * format:"json" silently returned cols ["name","hop"] while the schema and
+ * --help promised two more. A structured caller — the one most likely to
+ * ask for json — got no error, just missing fields. */
+ if (include_evidence) {
+ yyjson_mut_arr_add_str(doc, cols, "strategy");
+ yyjson_mut_arr_add_str(doc, cols, "confidence");
+ }
if (data_flow) {
yyjson_mut_arr_add_str(doc, cols, "args");
}
@@ -6258,6 +6267,25 @@ static yyjson_mut_val *bfs_to_tree_json(yyjson_mut_doc *doc, cbm_traverse_result
yyjson_mut_arr_add_str(doc, row, "");
}
}
+ if (include_evidence) {
+ const char *ev_class = NULL;
+ double ev_conf = -1.0;
+ if (bfs_edge_evidence_for_hop(tr, tr->visited[i].node.id, &ev_class, &ev_conf)) {
+ yyjson_mut_arr_add_strcpy(doc, row, ev_class ? ev_class : "");
+ if (ev_conf >= 0.0) {
+ yyjson_mut_arr_add_real(doc, row, ev_conf);
+ } else {
+ yyjson_mut_arr_add_null(doc, row);
+ }
+ } else {
+ /* The root hop has no inbound edge and non-CALLS edges record
+ * no strategy. The tree path emits "-" placeholders to keep the
+ * column count fixed; json says null, which is the same promise
+ * in a form a structured caller can test. */
+ yyjson_mut_arr_add_null(doc, row);
+ yyjson_mut_arr_add_null(doc, row);
+ }
+ }
yyjson_mut_arr_add_val(cur_rows, row);
}
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) {
}
if (do_outbound) {
yyjson_mut_obj_add_int(doc, root, "callees_total", out_total);
- yyjson_mut_obj_add_val(
- doc, root, "callees",
- bfs_to_tree_json(doc, &view_out, risk_labels, include_tests, data_flow));
+ yyjson_mut_obj_add_val(doc, root, "callees",
+ bfs_to_tree_json(doc, &view_out, risk_labels, include_tests,
+ data_flow, include_evidence));
}
if (do_inbound) {
yyjson_mut_obj_add_int(doc, root, "callers_total", in_total);
- yyjson_mut_obj_add_val(
- doc, root, "callers",
- bfs_to_tree_json(doc, &view_in, risk_labels, include_tests, data_flow));
+ yyjson_mut_obj_add_val(doc, root, "callers",
+ bfs_to_tree_json(doc, &view_in, risk_labels, include_tests,
+ data_flow, include_evidence));
}
if (more_rows) {
yyjson_mut_obj_add_bool(doc, root, "truncated", true);
diff --git a/tests/test_mcp.c b/tests/test_mcp.c
index 854330053..b83a8031c 100644
--- a/tests/test_mcp.c
+++ b/tests/test_mcp.c
@@ -3161,6 +3161,26 @@ TEST(tool_trace_path_evidence_is_opt_in_and_class_mapped) {
ASSERT_NULL(strstr(ev_txt, "lsp_trait_dispatch"));
free(ev_txt);
free(ev);
+
+ /* #1542: the same request with format:"json" returned cols ["name","hop"]
+ * — include_evidence was implemented on the tree path only, so the callers
+ * most likely to ask for structured output were the ones who silently got
+ * nothing. The two formats must promise the same fields. */
+ char *ev_json = cbm_mcp_server_handle(
+ srv, "{\"jsonrpc\":\"2.0\",\"id\":93,\"method\":\"tools/call\","
+ "\"params\":{\"name\":\"trace_path\",\"arguments\":{\"function_name\":\"caller\","
+ "\"project\":\"ev-proj\",\"direction\":\"outbound\",\"include_evidence\":true,"
+ "\"format\":\"json\"}}}");
+ ASSERT_NOT_NULL(ev_json);
+ char *ev_json_txt = extract_text_content(ev_json);
+ ASSERT_NOT_NULL(ev_json_txt);
+ ASSERT_NOT_NULL(strstr(ev_json_txt, "\"strategy\""));
+ ASSERT_NOT_NULL(strstr(ev_json_txt, "\"confidence\""));
+ ASSERT_NOT_NULL(strstr(ev_json_txt, "lsp"));
+ ASSERT_NOT_NULL(strstr(ev_json_txt, "0.95"));
+ ASSERT_NULL(strstr(ev_json_txt, "lsp_trait_dispatch"));
+ free(ev_json_txt);
+ free(ev_json);
cbm_mcp_server_free(srv);
PASS();
}