| 8732 | } |
| 8733 | |
| 8734 | static char *handle_get_code_snippet(cbm_mcp_server_t *srv, const char *args) { |
| 8735 | char *qn = cbm_mcp_get_string_arg(args, "qualified_name"); |
| 8736 | char *project = get_project_arg(args); |
| 8737 | bool include_neighbors = cbm_mcp_get_bool_arg(args, "include_neighbors"); |
| 8738 | |
| 8739 | if (!qn) { |
| 8740 | free(project); |
| 8741 | return cbm_mcp_text_result("qualified_name is required", true); |
| 8742 | } |
| 8743 | |
| 8744 | cbm_store_t *store = resolve_store(srv, project); |
| 8745 | if (!store) { |
| 8746 | char *_err = build_project_list_error("project not found or not indexed"); |
| 8747 | char *_res = cbm_mcp_text_result(_err, true); |
| 8748 | free(_err); |
| 8749 | free(qn); |
| 8750 | free(project); |
| 8751 | return _res; |
| 8752 | } |
| 8753 | |
| 8754 | char *not_indexed = verify_project_indexed(store, project); |
| 8755 | if (not_indexed) { |
| 8756 | free(qn); |
| 8757 | free(project); |
| 8758 | return not_indexed; |
| 8759 | } |
| 8760 | |
| 8761 | /* Default to current project (same as all other tools) */ |
| 8762 | const char *effective_project = project ? project : srv->current_project; |
| 8763 | |
| 8764 | /* Tier 1: Exact QN match */ |
| 8765 | cbm_node_t node = {0}; |
| 8766 | int rc = cbm_store_find_node_by_qn(store, effective_project, qn, &node); |
| 8767 | if (rc == CBM_STORE_OK) { |
| 8768 | char *result = build_snippet_response(srv, &node, NULL, include_neighbors, NULL, 0); |
| 8769 | free_node_contents(&node); |
| 8770 | free(qn); |
| 8771 | free(project); |
| 8772 | return result; |
| 8773 | } |
| 8774 | |
| 8775 | /* Tier 2: Suffix match — handles partial QNs ("main.HandleRequest") |
| 8776 | * and short names ("ProcessOrder") via LIKE '%.X'. */ |
| 8777 | cbm_node_t *suffix_nodes = NULL; |
| 8778 | int suffix_count = 0; |
| 8779 | cbm_store_find_nodes_by_qn_suffix(store, effective_project, qn, &suffix_nodes, &suffix_count); |
| 8780 | |
| 8781 | if (suffix_count == SKIP_ONE) { |
| 8782 | copy_node(&suffix_nodes[0], &node); |
| 8783 | cbm_store_free_nodes(suffix_nodes, suffix_count); |
| 8784 | char *result = build_snippet_response(srv, &node, "suffix", include_neighbors, NULL, 0); |
| 8785 | free_node_contents(&node); |
| 8786 | free(qn); |
| 8787 | free(project); |
| 8788 | return result; |
| 8789 | } |
| 8790 | |
| 8791 | if (suffix_count > SKIP_ONE) { |
no test coverage detected