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): document path on get_architecture and emit root/scoped totals (#604)

Berserk Agentadf602ec94b2
diff --git a/src/mcp/mcp.c b/src/mcp/mcp.c
index 0bb5efa37..b7456c779 100644
--- a/src/mcp/mcp.c
+++ b/src/mcp/mcp.c
@@ -391,9 +391,11 @@ static const tool_def_t TOOLS[] = {
"structure at a glance. Includes 'clusters': Leiden community detection over the call/import "
"graph, surfacing the de-facto modules (each with a label, member count, cohesion score, "
"representative top_nodes, and the packages/edge_types that bind it) — use these to grasp "
- "the real architectural seams, which often cut across the folder layout.",
- "{\"type\":\"object\",\"properties\":{\"project\":{\"type\":\"string\"},\"aspects\":{\"type\":"
- "\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"project\"]}"},
+ "the real architectural seams, which often cut across the folder layout. Optional path scopes "
+ "analysis to nodes under that directory prefix (file_path).",
+ "{\"type\":\"object\",\"properties\":{\"project\":{\"type\":\"string\"},\"path\":{\"type\":"
+ "\"string\",\"description\":\"Optional directory prefix to scope architecture (e.g. apps/hoa)\"},"
+ "\"aspects\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"project\"]}"},
{"search_code",
"Graph-augmented code search. Finds text patterns via grep, then enriches results with "
@@ -1973,6 +1975,7 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
int node_count = cbm_store_count_nodes_scoped(store, project, scope_path);
int edge_count = cbm_store_count_edges_scoped(store, project, scope_path);
+ bool path_scoped = scope_path && scope_path[0];
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
yyjson_mut_val *root = yyjson_mut_obj(doc);
@@ -1981,6 +1984,15 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
if (project) {
yyjson_mut_obj_add_str(doc, root, "project", project);
}
+ if (path_scoped) {
+ yyjson_mut_obj_add_str(doc, root, "path", scope_path);
+ int root_nodes = cbm_store_count_nodes(store, project);
+ int root_edges = cbm_store_count_edges(store, project);
+ yyjson_mut_obj_add_int(doc, root, "root_total_nodes", root_nodes);
+ yyjson_mut_obj_add_int(doc, root, "root_total_edges", root_edges);
+ yyjson_mut_obj_add_int(doc, root, "scoped_total_nodes", node_count);
+ yyjson_mut_obj_add_int(doc, root, "scoped_total_edges", edge_count);
+ }
yyjson_mut_obj_add_int(doc, root, "total_nodes", node_count);
yyjson_mut_obj_add_int(doc, root, "total_edges", edge_count);
diff --git a/tests/test_mcp.c b/tests/test_mcp.c
index 68edc0e97..7dc7c1144 100644
--- a/tests/test_mcp.c
+++ b/tests/test_mcp.c
@@ -12,6 +12,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
+#include <stdio.h>
/* ══════════════════════════════════════════════════════════════════
* JSON-RPC PARSING
@@ -791,6 +792,91 @@ TEST(tool_get_architecture_emits_populated_sections) {
PASS();
}
+/* Regression for #604: path scopes architecture totals and content. */
+TEST(tool_get_architecture_path_scoping) {
+ cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);
+ ASSERT_NOT_NULL(srv);
+
+ cbm_store_t *st = cbm_mcp_server_store(srv);
+ ASSERT_NOT_NULL(st);
+
+ const char *proj = "arch-path";
+ cbm_mcp_server_set_project(srv, proj);
+ cbm_store_upsert_project(st, proj, "/tmp/arch-path");
+
+ cbm_node_t pkg_global = {.project = proj,
+ .label = "Package",
+ .name = "Django",
+ .qualified_name = "arch-path.Django",
+ .file_path = "vendor/django/__init__.py"};
+ cbm_store_upsert_node(st, &pkg_global);
+
+ cbm_node_t pkg_local = {.project = proj,
+ .label = "Package",
+ .name = "hoa",
+ .qualified_name = "arch-path.hoa",
+ .file_path = "apps/hoa/main.go"};
+ cbm_store_upsert_node(st, &pkg_local);
+
+ cbm_node_t f_hoa = {.project = proj,
+ .label = "File",
+ .name = "main.go",
+ .qualified_name = "arch-path.apps.hoa.main.go",
+ .file_path = "apps/hoa/main.go"};
+ cbm_store_upsert_node(st, &f_hoa);
+
+ cbm_node_t f_other = {.project = proj,
+ .label = "File",
+ .name = "other.go",
+ .qualified_name = "arch-path.other.go",
+ .file_path = "lib/other.go"};
+ cbm_store_upsert_node(st, &f_other);
+
+ char *resp_root = cbm_mcp_server_handle(
+ srv, "{\"jsonrpc\":\"2.0\",\"id\":92,\"method\":\"tools/call\","
+ "\"params\":{\"name\":\"get_architecture\","
+ "\"arguments\":{\"project\":\"arch-path\",\"aspects\":[\"packages\"]}}}");
+ ASSERT_NOT_NULL(resp_root);
+ char *inner_root = extract_text_content(resp_root);
+ ASSERT_NOT_NULL(inner_root);
+ ASSERT_NOT_NULL(strstr(inner_root, "Django"));
+
+ char *resp_scoped = cbm_mcp_server_handle(
+ srv, "{\"jsonrpc\":\"2.0\",\"id\":93,\"method\":\"tools/call\","
+ "\"params\":{\"name\":\"get_architecture\","
+ "\"arguments\":{\"project\":\"arch-path\",\"path\":\"apps/hoa\","
+ "\"aspects\":[\"packages\"]}}}");
+ ASSERT_NOT_NULL(resp_scoped);
+ char *inner_scoped = extract_text_content(resp_scoped);
+ ASSERT_NOT_NULL(inner_scoped);
+
+ ASSERT_NOT_NULL(strstr(inner_scoped, "root_total_nodes"));
+ ASSERT_NOT_NULL(strstr(inner_scoped, "scoped_total_nodes"));
+ ASSERT_NOT_NULL(strstr(inner_scoped, "\"path\""));
+ ASSERT_NOT_NULL(strstr(inner_scoped, "hoa"));
+ ASSERT_NULL(strstr(inner_scoped, "Django"));
+
+ int root_nodes = 0;
+ int scoped_nodes = 0;
+ const char *rt = strstr(inner_scoped, "\"root_total_nodes\":");
+ const char *stn = strstr(inner_scoped, "\"scoped_total_nodes\":");
+ if (rt) {
+ sscanf(rt, "\"root_total_nodes\":%d", &root_nodes);
+ }
+ if (stn) {
+ sscanf(stn, "\"scoped_total_nodes\":%d", &scoped_nodes);
+ }
+ ASSERT_TRUE(root_nodes > scoped_nodes);
+ ASSERT_TRUE(scoped_nodes > 0);
+
+ free(inner_scoped);
+ free(resp_scoped);
+ free(inner_root);
+ free(resp_root);
+ cbm_mcp_server_free(srv);
+ PASS();
+}
+
TEST(tool_query_graph_missing_query) {
cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);
@@ -2294,6 +2380,7 @@ SUITE(mcp) {
RUN_TEST(tool_delete_project_not_found);
RUN_TEST(tool_get_architecture_empty);
RUN_TEST(tool_get_architecture_emits_populated_sections);
+ RUN_TEST(tool_get_architecture_path_scoping);
RUN_TEST(tool_query_graph_missing_query);
/* Pipeline-dependent tool handlers */