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

Function cli_print_mcp_result

src/main.c:212–238  ·  view source on GitHub ↗

Extract text content from MCP tool result envelope and print it. * MCP results: {"content":[{"type":"text","text":"..."}],"isError":...} * Returns 1 if the result was an error, 0 otherwise. */

Source from the content-addressed store, hash-verified

210 * MCP results: {"content":[{"type":"text","text":"..."}],"isError":...}
211 * Returns 1 if the result was an error, 0 otherwise. */
212static int cli_print_mcp_result(const char *result) {
213 yyjson_doc *doc = yyjson_read(result, strlen(result), 0);
214 if (!doc) {
215 printf("%s\n", result);
216 return 0;
217 }
218
219 yyjson_val *root = yyjson_doc_get_root(doc);
220 yyjson_val *err_val = yyjson_obj_get(root, "isError");
221 bool is_error = err_val && yyjson_get_bool(err_val);
222
223 const char *text = NULL;
224 yyjson_val *content = yyjson_obj_get(root, "content");
225 if (yyjson_is_arr(content) && yyjson_arr_size(content) > 0) {
226 yyjson_val *tv = yyjson_obj_get(yyjson_arr_get_first(content), "text");
227 text = tv ? yyjson_get_str(tv) : NULL;
228 }
229
230 if (text) {
231 (void)fprintf(is_error ? stderr : stdout, "%s\n", text);
232 } else {
233 printf("%s\n", result);
234 }
235
236 yyjson_doc_free(doc);
237 return is_error ? SKIP_ONE : 0;
238}
239
240/* Strip a flag from argv, returning true if found. */
241static bool cli_strip_flag(int *argc, char **argv, const char *flag) {

Callers 1

run_cliFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected