MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / handle_query_graph

Function handle_query_graph

src/mcp/mcp.c:3803–3932  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3801}
3802
3803static char *handle_query_graph(cbm_mcp_server_t *srv, const char *args) {
3804 char *query = cbm_mcp_get_string_arg(args, "query");
3805 char *project = get_project_arg(args);
3806 cbm_store_t *store = resolve_store(srv, project);
3807 int max_rows = cbm_mcp_get_int_arg(args, "max_rows", 0);
3808
3809 /* graph="missed" (#963): run the SAME cypher against the derived
3810 * miss-graph view (shadow project "<project>::missed") instead of the
3811 * code graph — file structure of not-fully-indexed files only. */
3812 char *graph_arg = cbm_mcp_get_string_arg(args, "graph");
3813 bool missed_graph = graph_arg && strcmp(graph_arg, "missed") == 0;
3814 free(graph_arg);
3815
3816 if (!query) {
3817 free(project);
3818 return cbm_mcp_text_result("query is required", true);
3819 }
3820 if (missed_graph && !project) {
3821 free(query);
3822 return cbm_mcp_text_result("project is required when graph=\"missed\"", true);
3823 }
3824 if (!store) {
3825 char *_err = build_project_list_error("project not found or not indexed");
3826 char *_res = cbm_mcp_text_result(_err, true);
3827 free(_err);
3828 free(project);
3829 free(query);
3830 return _res;
3831 }
3832
3833 char *not_indexed = verify_project_indexed(store, project);
3834 if (not_indexed) {
3835 free(project);
3836 free(query);
3837 return not_indexed;
3838 }
3839
3840 char covproj[CBM_SZ_512];
3841 const char *cypher_project = project;
3842 if (missed_graph) {
3843 cbm_store_coverage_shadow_project(covproj, sizeof(covproj), project);
3844 cypher_project = covproj;
3845 }
3846
3847 cbm_cypher_result_t result = {0};
3848 int rc = cbm_cypher_execute(store, query, cypher_project, max_rows, &result);
3849
3850 if (rc < 0) {
3851 char *err_msg = result.error ? result.error : "query execution failed";
3852 char *resp = cbm_mcp_text_result(err_msg, true);
3853 cbm_cypher_result_free(&result);
3854 free(query);
3855 free(project);
3856 return resp;
3857 }
3858
3859 /* Response encoding: TOON table by default (the columns double as the
3860 * table header); format:"json" restores the legacy columns/rows arrays. */

Callers 1

dispatch_toolFunction · 0.85

Calls 15

cbm_mcp_get_string_argFunction · 0.85
get_project_argFunction · 0.85
resolve_storeFunction · 0.85
cbm_mcp_get_int_argFunction · 0.85
cbm_mcp_text_resultFunction · 0.85
build_project_list_errorFunction · 0.85
verify_project_indexedFunction · 0.85
cbm_cypher_executeFunction · 0.85
cbm_cypher_result_freeFunction · 0.85
cbm_sb_initFunction · 0.85
cbm_tree_table_headerFunction · 0.85

Tested by

no test coverage detected