Skip to content

feat: GBRAIN_EXPOSED_TOOLS env var for MCP tool filtering#747

Open
joelwp wants to merge 1 commit intogarrytan:masterfrom
joelwp:feat/mcp-tool-filtering
Open

feat: GBRAIN_EXPOSED_TOOLS env var for MCP tool filtering#747
joelwp wants to merge 1 commit intogarrytan:masterfrom
joelwp:feat/mcp-tool-filtering

Conversation

@joelwp
Copy link
Copy Markdown

@joelwp joelwp commented May 8, 2026

Problem

GBrain MCP server exposes all 51 operations to every consumer. For chatbot integrations (OpenClaw, Claude Desktop, etc.), this creates prompt bloat (~10K+ tokens of tool schemas per LLM call) and tool confusion (LLM sees job management, source management, file upload tools it will never use in conversation).

Solution

A single env var GBRAIN_EXPOSED_TOOLS that filters which operations the MCP server registers.

GBRAIN_EXPOSED_TOOLS=get_page,put_page,search,query,list_pages,add_timeline_entry
  • Unset = all operations exposed (backward-compatible default)
  • Set but matches 0 = falls back to all operations with stderr warning
  • Logs on startup: [mcp] GBRAIN_EXPOSED_TOOLS: exposing 12 of 51 tools

CLI commands (gbrain call, gbrain dream, etc.) are unaffected -- they use operations directly, not the MCP server.

Use case

OpenClaw passes env vars to the MCP server process. Same GBrain install serves both a lean chatbot MCP (12 tools) and the full CLI/dream-cycle toolset (51 tools).

Changes

  • src/mcp/server.ts: 19 lines added

Test plan

  • Env var unset -> all tools exposed (no behavior change)
  • GBRAIN_EXPOSED_TOOLS=get_page,search -> only 2 tools in tools/list
  • GBRAIN_EXPOSED_TOOLS=nonexistent -> falls back to all tools with warning
  • CLI commands still work with full tool set regardless of env var

View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

Allow MCP consumers to control which tools are exposed via a
comma-separated GBRAIN_EXPOSED_TOOLS environment variable.

When set, only the listed operations are registered with the MCP server.
When unset, all operations are exposed (backward-compatible default).
If the filter matches zero operations, falls back to exposing all tools
with a stderr warning.

This lets chatbot integrations (OpenClaw, Claude Desktop, etc.) reduce
prompt size and LLM latency by exposing only the tools the agent needs
for conversation, while keeping the full 51-tool set available for CLI,
dream cycles, and background jobs.

Example: GBRAIN_EXPOSED_TOOLS=get_page,put_page,search,query,list_pages

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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