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

Function extract_text_content

tests/test_mcp.c:18520–18549  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

18518 * The MCP envelope is: {"content":[{"type":"text","text":"<inner json>"}]}
18519 * This returns the unescaped inner JSON. Caller must free. */
18520static char *extract_text_content(const char *mcp_result) {
18521 if (!mcp_result)
18522 return NULL;
18523 yyjson_doc *doc = yyjson_read(mcp_result, strlen(mcp_result), 0);
18524 if (!doc)
18525 return strdup(mcp_result); /* fallback */
18526 yyjson_val *root = yyjson_doc_get_root(doc);
18527 yyjson_val *content = yyjson_obj_get(root, "content");
18528 if (!content) {
18529 /* Handle JSON-RPC wrapper: {"jsonrpc":...,"result":{"content":[...]}} */
18530 yyjson_val *rpc_result = yyjson_obj_get(root, "result");
18531 if (rpc_result) {
18532 content = yyjson_obj_get(rpc_result, "content");
18533 }
18534 }
18535 if (!content || !yyjson_is_arr(content)) {
18536 yyjson_doc_free(doc);
18537 return strdup(mcp_result);
18538 }
18539 yyjson_val *item = yyjson_arr_get(content, 0);
18540 if (!item) {
18541 yyjson_doc_free(doc);
18542 return strdup(mcp_result);
18543 }
18544 yyjson_val *text = yyjson_obj_get(item, "text");
18545 const char *str = yyjson_get_str(text);
18546 char *result = str ? strdup(str) : strdup(mcp_result);
18547 yyjson_doc_free(doc);
18548 return result;
18549}
18550
18551typedef struct {
18552 char cache[512];

Callers 11

test_mcp.cFile · 0.85
check_tool_outputFunction · 0.85
mcp_test_semantic_pageFunction · 0.85
detect_default_base_runFunction · 0.85
dc_walk_callFunction · 0.85
call_snippetFunction · 0.85
budget_result_docFunction · 0.85
prose_searchFunction · 0.85
search_code_with_contextFunction · 0.85
search_root_probeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected