Skip to content

fix(mcp): honor AGENTMEMORY_TOOLS from .env in getVisibleTools#616

Open
ccf wants to merge 1 commit into
rohitg00:mainfrom
ccf:fix/553-tools-env-merge
Open

fix(mcp): honor AGENTMEMORY_TOOLS from .env in getVisibleTools#616
ccf wants to merge 1 commit into
rohitg00:mainfrom
ccf:fix/553-tools-env-merge

Conversation

@ccf
Copy link
Copy Markdown

@ccf ccf commented May 23, 2026

What

getVisibleTools() in src/mcp/tools-registry.ts read process.env["AGENTMEMORY_TOOLS"] directly, bypassing getMergedEnv() — the { ...fileEnv, ...process.env } helper that every other config reader reaches through getEnvVar(). This routes the lookup through getEnvVar() instead.

Why

AGENTMEMORY_TOOLS=all set in ~/.agentmemory/.env was silently ignored. The MCP tool surface stayed at the 8-tool core set instead of the full surface, even though .env.example documents that variable as the way to opt in:

AGENTMEMORY_TOOLS=all   # core (default) | all — surface exposed to MCP clients

Because getMergedEnv() is { ...fileEnv, ...process.env }, process.env (shell export, the --tools flag) still takes precedence over the file — only the missing .env fallback is restored.

This is the root cause behind #553: the "8 tools, not 51" state is the server returning its core surface over a working proxy — not a probe/proxy failure. It may also explain #400 (Codex full-surface) where a healthy server still serves the reduced set.

To be clear about scope: this does not address #510, which is the distinct "literal ${AGENTMEMORY_URL} placeholder breaks the shim's localhost fallback" connection bug — that one is already handled on main by the resolveEnvOrEmpty guard in #588.

How to verify

# with AGENTMEMORY_TOOLS=all only in ~/.agentmemory/.env (not exported):
# before — server reports 8 core tools; after — full surface

Automated coverage added in test/tools-visibility-env.test.ts (hermetic; sandboxes HOME and writes a temp .env):

  • AGENTMEMORY_TOOLS=all in .env → full surface (getAllTools().length, incl. memory_graph_query)
  • unset → core subset (regression guard)
  • process.env overrides the .env value (precedence preserved)

npm run build is clean and the suite passes (the 5 unrelated auto-compress / embedding-provider failures only occur when a real ~/.agentmemory/.env is present in the test environment; they pass with a clean HOME).

Fixes #553

getVisibleTools() read process.env["AGENTMEMORY_TOOLS"] directly, bypassing
getMergedEnv() — the { ...fileEnv, ...process.env } helper that every other
config reader reaches through getEnvVar(). As a result, AGENTMEMORY_TOOLS=all
set in ~/.agentmemory/.env was silently ignored: the MCP surface stayed at the
8-tool core set instead of the full surface, even though .env.example documents
that variable as the way to opt in.

Route the lookup through getEnvVar() so the documented .env knob takes effect,
while process.env (shell export, --tools flag) keeps precedence over the file.

Fixes rohitg00#553

Signed-off-by: Charles C. Figueiredo <ccf@ccf.io>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 23, 2026

@ccf is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 2026

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenCode plugin exposes only 8 agentmemory tools instead of advertised 51 MCP surface (server running, proxy mode not activating)

1 participant