Skip to content

feat(mcp): add AGENTMEMORY_TOOLS_DISABLE env to trim the MCP tool surface#955

Open
shgew wants to merge 1 commit into
rohitg00:mainfrom
shgew:feat/mcp-tools-disable
Open

feat(mcp): add AGENTMEMORY_TOOLS_DISABLE env to trim the MCP tool surface#955
shgew wants to merge 1 commit into
rohitg00:mainfrom
shgew:feat/mcp-tools-disable

Conversation

@shgew

@shgew shgew commented Jun 20, 2026

Copy link
Copy Markdown

What

Add a comma- or whitespace-separated denylist read from the AGENTMEMORY_TOOLS_DISABLE env. Applied after the existing AGENTMEMORY_TOOLS=all|core mode filter so it composes cleanly with both modes, in two places:

  • getVisibleTools() - server-side, src/mcp/tools-registry.ts
  • handleToolsList() - bridge proxy + fallback paths in src/mcp/standalone.ts

Why

Deployments often want to drop tools whose handlers are gated by feature flags (memory_vision_search, memory_team_share, memory_team_feed, memory_claude_bridge_sync, memory_snapshot_create), peer fan-out features no host actually configures (memory_mesh_sync), sandboxed exports (memory_obsidian_export), or the markdown-compress utility (memory_compress_file). Today the only path is a fork. This adds a single env knob.

How

The bridge filters the remote response inline, so the env is useful without redeploying the server. Unknown tool names are silently ignored to keep the value forward-compatible.

Tests

  • test/tool-disable-env.test.ts (8 cases): parseToolDisableList + getVisibleTools under all/core modes and unknown names.
  • test/standalone-tools-disable.test.ts (6 cases): bridge filter on the standalone shim (proxy + local fallback paths).
  • Existing test/tool-count-consistency.test.ts and test/mcp-standalone.test.ts pass unchanged.
  • Targeted suite: 20/20 pass.

Compatibility

Unset env = no behavior change. No new dependencies.

How to verify

# fallback path
AGENTMEMORY_TOOLS_DISABLE='memory_mesh_sync,memory_team_share' \
  node dist/standalone.mjs < tools-list.jsonl | jq '.result.tools | length'

# proxy path against a running server
AGENTMEMORY_URL=http://localhost:3111 \
  AGENTMEMORY_TOOLS_DISABLE='memory_vision_search memory_snapshot_create' \
  node dist/standalone.mjs < tools-list.jsonl | jq '.result.tools | length'

Summary by CodeRabbit

  • New Features

    • MCP tools can now be selectively disabled through environment variable configuration for both proxy and local operation modes.
  • Tests

    • Added comprehensive test coverage validating tool disabling across various configurations and edge cases.

…face

Add a comma- or whitespace-separated denylist read from the
AGENTMEMORY_TOOLS_DISABLE env. Applied after the existing
AGENTMEMORY_TOOLS=all|core mode filter so it composes cleanly with both
modes:

  - getVisibleTools()   - server-side, src/mcp/tools-registry.ts
  - handleToolsList()   - bridge proxy + fallback paths in src/mcp/standalone.ts

The bridge filters the remote response inline, so the env is useful
without redeploying the server. Unknown tool names are silently
ignored to keep the value forward-compatible.

Use cases: drop tools whose handlers are gated by feature flags
(memory_vision_search, memory_team_share, memory_team_feed,
memory_claude_bridge_sync, memory_snapshot_create), peer fan-out
features no host actually configures (memory_mesh_sync), sandboxed
exports (memory_obsidian_export), and the markdown-compress utility
(memory_compress_file). Each tool can be dropped per-deployment
without touching the registry source.

Tests:
  - test/tool-disable-env.test.ts: parseToolDisableList +
    getVisibleTools under all/core modes and unknown names.
  - test/standalone-tools-disable.test.ts: bridge filter on the
    standalone shim (proxy + local fallback paths).
  - Existing test/tool-count-consistency.test.ts and
    test/mcp-standalone.test.ts pass unchanged.

Signed-off-by: Hleb Shauchenka <me@marleb.org>
@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

@shgew 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

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5fdf8efc-aed8-47ed-bc14-b2c5d8e4af3f

📥 Commits

Reviewing files that changed from the base of the PR and between f6f9e3c and d7dad7c.

📒 Files selected for processing (4)
  • src/mcp/standalone.ts
  • src/mcp/tools-registry.ts
  • test/standalone-tools-disable.test.ts
  • test/tool-disable-env.test.ts

📝 Walkthrough

Walkthrough

Adds AGENTMEMORY_TOOLS_DISABLE environment variable support to the MCP tool surface. A new exported parseToolDisableList helper parses the env var into a Set<string>, and filtering is applied in both getVisibleTools() (local registry) and handleToolsList() (standalone proxy and local fallback). Two new test files cover the parsing logic and proxy behavior.

Changes

AGENTMEMORY_TOOLS_DISABLE env-var filtering

Layer / File(s) Summary
parseToolDisableList and getVisibleTools filtering
src/mcp/tools-registry.ts
Adds exported parseToolDisableList that splits an optional env-var string into a trimmed Set<string>, and updates getVisibleTools() to apply that disable set after the existing AGENTMEMORY_TOOLS mode selection.
applyToolDisable wired into proxy and local fallback
src/mcp/standalone.ts
Imports parseToolDisableList, defines local applyToolDisable helper, and applies it to both the remote proxy tool list and the getAllTools() local fallback inside handleToolsList(); debug logging reports dropped tool count.
Unit tests for parsing and registry filtering
test/tool-disable-env.test.ts
Tests parseToolDisableList for nullish, empty, comma/whitespace/newline-separated, and trimming edge cases; tests getVisibleTools for unset env, default-mode disable, core-mode disable, and unknown tool name handling.
Integration tests for proxy and fallback filtering
test/standalone-tools-disable.test.ts
Tests handleToolsList with mocked fetch: unset env returns full server list, comma-separated names are filtered, whitespace/newline tokenization works, unknown names are ignored, malformed entries are preserved, and disable applies to the local fallback when fetch fails.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • Reduce MCP tool surface area #620: This PR directly implements the AGENTMEMORY_TOOLS_DISABLE mechanism described in that issue, adding env-var-driven tool filtering at both the registry (getVisibleTools) and standalone proxy (handleToolsList) levels.

Possibly related PRs

  • rohitg00/agentmemory#650: Modifies getVisibleTools() in src/mcp/tools-registry.ts around the AGENTMEMORY_TOOLS mode selection that this PR extends with an additional AGENTMEMORY_TOOLS_DISABLE filter step.

Poem

🐇 Hoppy news from the warren today,
Some tools were too many, I say!
With TOOLS_DISABLE set,
No unwanted ones left —
The filtered list hops on its way! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: adding an AGENTMEMORY_TOOLS_DISABLE environment variable to control MCP tool visibility.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.

1 participant