Skip to content

AGENTMEMORY_TOOLS=core in ~/.agentmemory/.env is ignored (getVisibleTools reads process.env directly) #1060

Closed

Description

@sageri

What

getVisibleTools() in src/mcp/tools-registry.ts reads process.env["AGENTMEMORY_TOOLS"] directly instead of going through getEnvVar() / getMergedEnv() ({ ...loadEnvFile(), ...process.env }), which is what every other config reader uses to merge ~/.agentmemory/.env.

function getVisibleTools() {
  if ((process.env["AGENTMEMORY_TOOLS"] || "all") === "core") {
    return getAllTools().filter((t) => ESSENTIAL_TOOLS.has(t.name));
  }
  return getAllTools();
}

Confirmed at dist/index.mjs:20195 and dist/tools-registry-D8XVVPbJ.mjs:1360 in @agentmemory/agentmemory@0.9.27.

Repro

# ~/.agentmemory/.env
AGENTMEMORY_TOOLS=core
pm2 restart agentmemory   # or: agentmemory (no --tools flag, no shell export)
(Invoke-RestMethod 'http://127.0.0.1:3111/agentmemory/mcp/tools').tools.Count

Expected: 8 (the ESSENTIAL_TOOLS core set).
Actual: 53 (full all surface).

Setting the same value via agentmemory --tools core or exporting AGENTMEMORY_TOOLS=core in the launching shell works correctly — only the .env file path is ignored.

Why this keeps resurfacing

This is the same root cause as #553 (there: .env set to all, server kept answering core). #616 proposed the fix (getVisibleTools() → route through getEnvVar()) but was closed without merging. #650 then flipped the default from core to all to reduce the symptom's visibility, but did not fix the underlying bypass — it just changed which direction of the misconfiguration you notice. Today .env-only core is silently ignored the same way .env-only all used to be.

Suggested fix

- function getVisibleTools() {
-   if ((process.env["AGENTMEMORY_TOOLS"] || "all") === "core") {
+ function getVisibleTools() {
+   if ((getEnvVar("AGENTMEMORY_TOOLS") || "all") === "core") {
    return getAllTools().filter((t) => ESSENTIAL_TOOLS.has(t.name));
  }
  return getAllTools();
}

Same change needed in src/mcp/standalone.ts's local-fallback tool listing path, per the pattern in #616.

Environment

  • @agentmemory/agentmemory@0.9.27, Windows 11, run via pm2 (npm global install)
  • ~/.agentmemory/.env has AGENTMEMORY_TOOLS=core (with a trailing # ... comment, correctly stripped by loadEnvFile())
  • No shell-level AGENTMEMORY_TOOLS export

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions