feat: GBRAIN_EXPOSED_TOOLS env var for MCP tool filtering#747
Open
joelwp wants to merge 1 commit intogarrytan:masterfrom
Open
feat: GBRAIN_EXPOSED_TOOLS env var for MCP tool filtering#747joelwp wants to merge 1 commit intogarrytan:masterfrom
joelwp wants to merge 1 commit intogarrytan:masterfrom
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_TOOLSthat filters which operations the MCP server registers.[mcp] GBRAIN_EXPOSED_TOOLS: exposing 12 of 51 toolsCLI 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 addedTest plan
GBRAIN_EXPOSED_TOOLS=get_page,search-> only 2 tools in tools/listGBRAIN_EXPOSED_TOOLS=nonexistent-> falls back to all tools with warningNeed help on this PR? Tag
@codesmithwith what you need.