Extract the inner "text" value from an MCP tool result JSON. * The MCP envelope is: {"content":[{"type":"text","text":" "}]} * This returns the unescaped inner JSON. Caller must free. */
| 7893 | * The MCP envelope is: {"content":[{"type":"text","text":"<inner json>"}]} |
| 7894 | * This returns the unescaped inner JSON. Caller must free. */ |
| 7895 | static char *extract_text_content(const char *mcp_result) { |
| 7896 | if (!mcp_result) |
| 7897 | return NULL; |
| 7898 | yyjson_doc *doc = yyjson_read(mcp_result, strlen(mcp_result), 0); |
| 7899 | if (!doc) |
| 7900 | return strdup(mcp_result); /* fallback */ |
| 7901 | yyjson_val *root = yyjson_doc_get_root(doc); |
| 7902 | yyjson_val *content = yyjson_obj_get(root, "content"); |
| 7903 | if (!content) { |
| 7904 | /* Handle JSON-RPC wrapper: {"jsonrpc":...,"result":{"content":[...]}} */ |
| 7905 | yyjson_val *rpc_result = yyjson_obj_get(root, "result"); |
| 7906 | if (rpc_result) { |
| 7907 | content = yyjson_obj_get(rpc_result, "content"); |
| 7908 | } |
| 7909 | } |
| 7910 | if (!content || !yyjson_is_arr(content)) { |
| 7911 | yyjson_doc_free(doc); |
| 7912 | return strdup(mcp_result); |
| 7913 | } |
| 7914 | yyjson_val *item = yyjson_arr_get(content, 0); |
| 7915 | if (!item) { |
| 7916 | yyjson_doc_free(doc); |
| 7917 | return strdup(mcp_result); |
| 7918 | } |
| 7919 | yyjson_val *text = yyjson_obj_get(item, "text"); |
| 7920 | const char *str = yyjson_get_str(text); |
| 7921 | char *result = str ? strdup(str) : strdup(mcp_result); |
| 7922 | yyjson_doc_free(doc); |
| 7923 | return result; |
| 7924 | } |
| 7925 | |
| 7926 | /* Call get_code_snippet and extract inner text content. |
| 7927 | * Caller must free returned string. */ |
no outgoing calls
no test coverage detected