Skip to content

Commit 66b3e30

Browse files
authored
Merge pull request DeusData#614 from linze0721/berserk/fd632085-2b69-4b14-930b-47025d80d973
fix: get_architecture should honor path scope
2 parents 677582c + c80a294 commit 66b3e30

5 files changed

Lines changed: 692 additions & 97 deletions

File tree

‎src/mcp/mcp.c‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,13 @@ static const tool_def_t TOOLS[] = {
391391
"structure at a glance. Includes 'clusters': Leiden community detection over the call/import "
392392
"graph, surfacing the de-facto modules (each with a label, member count, cohesion score, "
393393
"representative top_nodes, and the packages/edge_types that bind it) — use these to grasp "
394-
"the real architectural seams, which often cut across the folder layout.",
395-
"{\"type\":\"object\",\"properties\":{\"project\":{\"type\":\"string\"},\"aspects\":{\"type\":"
396-
"\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"project\"]}"},
394+
"the real architectural seams, which often cut across the folder layout. Optional path scopes "
395+
"analysis to nodes under that directory prefix (file_path).",
396+
"{\"type\":\"object\",\"properties\":{\"project\":{\"type\":\"string\"},\"path\":{\"type\":"
397+
"\"string\",\"description\":\"Optional directory prefix to scope architecture (e.g. "
398+
"apps/hoa)\"},"
399+
"\"aspects\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"project\"]"
400+
"}"},
397401

398402
{"search_code",
399403
"Graph-augmented code search. Finds text patterns via grep, then enriches results with "
@@ -1917,12 +1921,14 @@ static void append_cross_repo_summary(yyjson_mut_doc *doc, yyjson_mut_val *root,
19171921

19181922
static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
19191923
char *project = cbm_mcp_get_string_arg(args, "project");
1924+
char *scope_path = cbm_mcp_get_string_arg(args, "path");
19201925
cbm_store_t *store = resolve_store(srv, project);
19211926
REQUIRE_STORE(store, project);
19221927

19231928
char *not_indexed = verify_project_indexed(store, project);
19241929
if (not_indexed) {
19251930
free(project);
1931+
free(scope_path);
19261932
return not_indexed;
19271933
}
19281934

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

19671973
cbm_architecture_info_t arch = {0};
1968-
cbm_store_get_architecture(store, project, aspects_strs_count > 0 ? aspects_strs : NULL,
1969-
aspects_strs_count, &arch);
1974+
cbm_store_get_architecture(store, project, scope_path,
1975+
aspects_strs_count > 0 ? aspects_strs : NULL, aspects_strs_count,
1976+
&arch);
19701977

1971-
int node_count = cbm_store_count_nodes(store, project);
1972-
int edge_count = cbm_store_count_edges(store, project);
1978+
int node_count = cbm_store_count_nodes_scoped(store, project, scope_path);
1979+
int edge_count = cbm_store_count_edges_scoped(store, project, scope_path);
1980+
char norm_path[CBM_SZ_512];
1981+
bool path_scoped = cbm_store_normalize_arch_path(scope_path, norm_path, sizeof(norm_path));
19731982

19741983
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
19751984
yyjson_mut_val *root = yyjson_mut_obj(doc);
@@ -1978,6 +1987,15 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
19781987
if (project) {
19791988
yyjson_mut_obj_add_str(doc, root, "project", project);
19801989
}
1990+
if (path_scoped) {
1991+
yyjson_mut_obj_add_str(doc, root, "path", norm_path);
1992+
int root_nodes = cbm_store_count_nodes(store, project);
1993+
int root_edges = cbm_store_count_edges(store, project);
1994+
yyjson_mut_obj_add_int(doc, root, "root_total_nodes", root_nodes);
1995+
yyjson_mut_obj_add_int(doc, root, "root_total_edges", root_edges);
1996+
yyjson_mut_obj_add_int(doc, root, "scoped_total_nodes", node_count);
1997+
yyjson_mut_obj_add_int(doc, root, "scoped_total_edges", edge_count);
1998+
}
19811999
yyjson_mut_obj_add_int(doc, root, "total_nodes", node_count);
19822000
yyjson_mut_obj_add_int(doc, root, "total_edges", edge_count);
19832001

@@ -2193,6 +2211,7 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
21932211
yyjson_doc_free(aspects_doc);
21942212
}
21952213
free(project);
2214+
free(scope_path);
21962215

21972216
char *result = cbm_mcp_text_result(json, false);
21982217
free(json);

0 commit comments

Comments
 (0)