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

Function help_append

src/mcp/mcp.c:1164–1177  ·  view source on GitHub ↗

Render the top-level --help "Tools:" block from the registry tools/list * serves. The list used to be hand-maintained in the help text and drifted * when check_index_coverage was added (#1361); deriving it here makes that * divergence impossible. Heap-allocated; caller frees. */ Append at out[len] and return the bytes ACTUALLY written. * * snprintf returns the length it WOULD have written, so

Source from the content-addressed store, hash-verified

1162 * changing the wrap rule would turn it into an overflow with nothing to notice.
1163 * Clamping makes `len <= cap - 1` a local invariant no later edit can void. */
1164static size_t help_append(char *out, size_t cap, size_t len, const char *fmt, ...) {
1165 if (len + 1 >= cap) {
1166 return 0;
1167 }
1168 va_list args;
1169 va_start(args, fmt);
1170 int written = vsnprintf(out + len, cap - len, fmt, args);
1171 va_end(args);
1172 if (written <= 0) {
1173 return 0;
1174 }
1175 size_t room = cap - len - 1;
1176 return (size_t)written > room ? room : (size_t)written;
1177}
1178
1179char *cbm_mcp_tools_help_list(void) {
1180 size_t cap = SLEN("Tools:") + 2; /* trailing newline + NUL */

Callers 1

cbm_mcp_tools_help_listFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected