| 8599 | } |
| 8600 | |
| 8601 | static 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) { |
no test coverage detected