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

Function cbm_upsert_codex_mcp

src/cli/cli.c:3881–3920  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3879}
3880
3881int cbm_upsert_codex_mcp(const char *binary_path, const char *config_path) {
3882 if (!binary_path || !config_path) {
3883 return CLI_ERR;
3884 }
3885 char escaped[CLI_BUF_8K];
3886 if (cbm_toml_escape_basic_string(binary_path, escaped, sizeof(escaped)) != 0) {
3887 return CLI_ERR;
3888 }
3889 char block[CLI_BUF_8K];
3890 /* #1562: Codex sanitizes the environment of stdio MCP subprocesses, passing
3891 * through only the names listed in env_vars. Without CBM_CACHE_DIR the
3892 * Codex-spawned server silently falls back to the DEFAULT cache while the
3893 * account daemon uses the configured one; the two disagree and the
3894 * handshake closes during initialization, so Codex exposes no cbm tools at
3895 * all.
3896 *
3897 * The names are listed unconditionally rather than only when a variable is
3898 * set at install time: env_vars names variables to FORWARD IF PRESENT, so
3899 * listing them costs nothing when unset and keeps working for someone who
3900 * sets one after installing — which install-time detection would silently
3901 * fail to cover.
3902 *
3903 * CBM_RUNTIME_DIR joined the list with #1664: since #1645 it relocates
3904 * the daemon rendezvous, so a Codex subprocess that does not receive it
3905 * looks for the daemon in the DEFAULT location and never finds it — the
3906 * same silent client/daemon split CBM_CACHE_DIR caused. Both names decide
3907 * WHICH daemon a process talks to; behavioural knobs stay unforwarded. */
3908 int written = snprintf(block, sizeof(block),
3909 CODEX_CMM_SECTION "\ncommand = \"%s\"\nargs = []\n"
3910 "env_vars = [\"CBM_CACHE_DIR\", "
3911 "\"CBM_RUNTIME_DIR\"]\n",
3912 escaped);
3913 if (written < 0 || (size_t)written >= sizeof(block) ||
3914 cbm_remove_codex_legacy_mcp(config_path) != 0) {
3915 return CLI_ERR;
3916 }
3917 return cbm_toml_upsert_managed_block(config_path, CODEX_MCP_BEGIN, CODEX_MCP_END, block) == 0
3918 ? CLI_OK
3919 : CLI_ERR;
3920}
3921
3922int cbm_remove_codex_mcp(const char *config_path) {
3923 /* #2228: only our table goes; foreign tables found between the markers

Callers 1

test_cli.cFile · 0.85

Tested by

no test coverage detected