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

Function handle_get_code_snippet

src/mcp/mcp.c:8601–8690  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8599}
8600
8601static char *handle_get_code_snippet(cbm_mcp_server_t *srv, const char *args) {
8602 char *qn = cbm_mcp_get_string_arg(args, "qualified_name");
8603 char *project = get_project_arg(args);
8604 bool include_neighbors = cbm_mcp_get_bool_arg(args, "include_neighbors");
8605
8606 if (!qn) {
8607 free(project);
8608 return cbm_mcp_text_result("qualified_name is required", true);
8609 }
8610
8611 cbm_store_t *store = resolve_store(srv, project);
8612 if (!store) {
8613 char *_err = build_project_list_error("project not found or not indexed");
8614 char *_res = cbm_mcp_text_result(_err, true);
8615 free(_err);
8616 free(qn);
8617 free(project);
8618 return _res;
8619 }
8620
8621 char *not_indexed = verify_project_indexed(store, project);
8622 if (not_indexed) {
8623 free(qn);
8624 free(project);
8625 return not_indexed;
8626 }
8627
8628 /* Default to current project (same as all other tools) */
8629 const char *effective_project = project ? project : srv->current_project;
8630
8631 /* Tier 1: Exact QN match */
8632 cbm_node_t node = {0};
8633 int rc = cbm_store_find_node_by_qn(store, effective_project, qn, &node);
8634 if (rc == CBM_STORE_OK) {
8635 char *result = build_snippet_response(srv, &node, NULL, include_neighbors, NULL, 0);
8636 free_node_contents(&node);
8637 free(qn);
8638 free(project);
8639 return result;
8640 }
8641
8642 /* Tier 2: Suffix match — handles partial QNs ("main.HandleRequest")
8643 * and short names ("ProcessOrder") via LIKE '%.X'. */
8644 cbm_node_t *suffix_nodes = NULL;
8645 int suffix_count = 0;
8646 cbm_store_find_nodes_by_qn_suffix(store, effective_project, qn, &suffix_nodes, &suffix_count);
8647
8648 if (suffix_count == SKIP_ONE) {
8649 copy_node(&suffix_nodes[0], &node);
8650 cbm_store_free_nodes(suffix_nodes, suffix_count);
8651 char *result = build_snippet_response(srv, &node, "suffix", include_neighbors, NULL, 0);
8652 free_node_contents(&node);
8653 free(qn);
8654 free(project);
8655 return result;
8656 }
8657
8658 if (suffix_count > SKIP_ONE) {

Callers 1

dispatch_toolFunction · 0.85

Calls 15

cbm_mcp_get_string_argFunction · 0.85
get_project_argFunction · 0.85
cbm_mcp_get_bool_argFunction · 0.85
cbm_mcp_text_resultFunction · 0.85
resolve_storeFunction · 0.85
build_project_list_errorFunction · 0.85
verify_project_indexedFunction · 0.85
build_snippet_responseFunction · 0.85
free_node_contentsFunction · 0.85
copy_nodeFunction · 0.85

Tested by

no test coverage detected