Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions src/mcp/mcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,13 @@ 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 "
Expand Down Expand Up @@ -1917,12 +1921,14 @@ static void append_cross_repo_summary(yyjson_mut_doc *doc, yyjson_mut_val *root,

static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
char *project = cbm_mcp_get_string_arg(args, "project");
char *scope_path = cbm_mcp_get_string_arg(args, "path");
cbm_store_t *store = resolve_store(srv, project);
REQUIRE_STORE(store, project);

char *not_indexed = verify_project_indexed(store, project);
if (not_indexed) {
free(project);
free(scope_path);
return not_indexed;
}

Expand Down Expand Up @@ -1962,14 +1968,17 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
/* Counts-only: this handler renders label/type counts but never property
* keys, and full key discovery json_each-scans every row (seconds-to-
* minutes on multi-million-node graphs). */
cbm_store_get_schema_counts(store, project, &schema);
cbm_store_get_schema_counts_scoped(store, project, scope_path, &schema);

cbm_architecture_info_t arch = {0};
cbm_store_get_architecture(store, project, aspects_strs_count > 0 ? aspects_strs : NULL,
aspects_strs_count, &arch);
cbm_store_get_architecture(store, project, scope_path,
aspects_strs_count > 0 ? aspects_strs : NULL, aspects_strs_count,
&arch);

int node_count = cbm_store_count_nodes(store, project);
int edge_count = cbm_store_count_edges(store, project);
int node_count = cbm_store_count_nodes_scoped(store, project, scope_path);
int edge_count = cbm_store_count_edges_scoped(store, project, scope_path);
char norm_path[CBM_SZ_512];
bool path_scoped = cbm_store_normalize_arch_path(scope_path, norm_path, sizeof(norm_path));

yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
yyjson_mut_val *root = yyjson_mut_obj(doc);
Expand All @@ -1978,6 +1987,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", norm_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);

Expand Down Expand Up @@ -2193,6 +2211,7 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
yyjson_doc_free(aspects_doc);
}
free(project);
free(scope_path);

char *result = cbm_mcp_text_result(json, false);
free(json);
Expand Down
Loading
Loading