-
Notifications
You must be signed in to change notification settings - Fork 6
feat: MCP on-demand loading - reduce startup tokens by ~4.6K #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,59 +122,72 @@ SKIP_PRIMARY_AGENTS = {"plan-plus.md", "aidevops.md"} | |
|
|
||
| # Special tool configurations per agent (by display name) | ||
| # These are MCP tools that specific agents need access to | ||
| # Note: playwriter_* is ONLY enabled for agents with browser subagents | ||
| # to reduce context bloat from verbose tool descriptions | ||
| # | ||
| # MCP On-Demand Loading Strategy: | ||
| # The following MCPs are DISABLED globally to reduce context token usage (~4.6K saved): | ||
| # - playwriter_*: ~3K tokens - enable via @playwriter subagent | ||
| # - augment-context-engine_*: ~1K tokens - enable via @augment-context-engine subagent | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After removing Other Locations
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| # - gh_grep_*: ~600 tokens - replaced by @github-search subagent (uses rg/bash) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This claims Other Locations
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| # | ||
| # osgrep_* remains enabled as the primary semantic search tool (local, no auth). | ||
| # Use @augment-context-engine subagent when osgrep returns insufficient results. | ||
| AGENT_TOOLS = { | ||
| "Build+": { | ||
| # Unified coding agent - planning, implementation, and DevOps | ||
| # Has browser subagents (playwright, stagehand) so needs playwriter | ||
| # Browser automation: use @playwriter subagent (enables playwriter MCP on-demand) | ||
| # Semantic search: osgrep primary, @augment-context-engine fallback | ||
| # GitHub search: use @github-search subagent (rg/bash, no MCP needed) | ||
| "write": True, "edit": True, "bash": True, "read": True, "glob": True, "grep": True, | ||
| "webfetch": True, "task": True, "todoread": True, "todowrite": True, | ||
| "context7_*": True, "osgrep_*": True, "augment-context-engine_*": True, | ||
| "gh_grep_*": True, "playwriter_*": True | ||
| "context7_*": True, "osgrep_*": True | ||
| }, | ||
| "Onboarding": { | ||
| "write": True, "edit": True, "bash": True, "read": True, "glob": True, "grep": True, | ||
| "webfetch": True, "task": True, | ||
| "osgrep_*": True, "augment-context-engine_*": True | ||
| "osgrep_*": True | ||
| }, | ||
| "Accounts": { | ||
| "write": True, "edit": True, "bash": True, "read": True, "glob": True, "grep": True, | ||
| "webfetch": True, "task": True, "quickfile_*": True, | ||
| "osgrep_*": True, "augment-context-engine_*": True | ||
| "osgrep_*": True | ||
| }, | ||
| "Social-Media": { | ||
| "write": True, "edit": True, "bash": True, "read": True, "glob": True, "grep": True, | ||
| "webfetch": True, "task": True, | ||
| "osgrep_*": True, "augment-context-engine_*": True | ||
| "osgrep_*": True | ||
| }, | ||
| "SEO": { | ||
| "write": True, "read": True, "bash": True, "webfetch": True, | ||
| "gsc_*": True, "ahrefs_*": True, "dataforseo_*": True, | ||
| "context7_*": True, "osgrep_*": True, "augment-context-engine_*": True | ||
| "context7_*": True, "osgrep_*": True | ||
| }, | ||
| "WordPress": { | ||
| "write": True, "edit": True, "bash": True, "read": True, "glob": True, "grep": True, | ||
| "localwp_*": True, "context7_*": True, "osgrep_*": True, "augment-context-engine_*": True | ||
| "localwp_*": True, "context7_*": True, "osgrep_*": True | ||
| }, | ||
| "Content": { | ||
| "write": True, "edit": True, "read": True, "webfetch": True, | ||
| "osgrep_*": True, "augment-context-engine_*": True | ||
| "osgrep_*": True | ||
| }, | ||
| "Research": { | ||
| "read": True, "webfetch": True, "bash": True, | ||
| "context7_*": True, "osgrep_*": True, "augment-context-engine_*": True | ||
| "context7_*": True, "osgrep_*": True | ||
| }, | ||
| } | ||
|
|
||
| # Default tools for agents not in AGENT_TOOLS | ||
| # Note: playwriter_* NOT included by default - it adds significant | ||
| # context overhead from verbose tool descriptions. Enable per-agent as needed. | ||
| # Note: claude-code-mcp_* NOT included - use @claude-code subagent instead | ||
| # | ||
| # MCP On-Demand Loading: | ||
| # - playwriter_*: DISABLED - use @playwriter subagent (~3K tokens saved) | ||
| # - augment-context-engine_*: DISABLED - use @augment-context-engine subagent (~1K saved) | ||
| # - gh_grep_*: DISABLED - use @github-search subagent (~600 tokens saved) | ||
| # - claude-code-mcp_*: DISABLED - use @claude-code subagent | ||
| # | ||
| # osgrep_* remains enabled as primary semantic search (local, fast, no auth) | ||
| DEFAULT_TOOLS = { | ||
| "write": True, "edit": True, "bash": True, "read": True, "glob": True, "grep": True, | ||
| "webfetch": True, "task": True, | ||
| "osgrep_*": True, "augment-context-engine_*": True | ||
| "osgrep_*": True | ||
| } | ||
|
|
||
| # Temperature settings (by display name, default 0.2) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,161 @@ | ||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||
| description: Search GitHub repositories for code patterns using ripgrep and bash | ||||||||||||||||||||||||||||||||||||||||
| mode: subagent | ||||||||||||||||||||||||||||||||||||||||
| tools: | ||||||||||||||||||||||||||||||||||||||||
| read: true | ||||||||||||||||||||||||||||||||||||||||
| write: false | ||||||||||||||||||||||||||||||||||||||||
| edit: false | ||||||||||||||||||||||||||||||||||||||||
| bash: true | ||||||||||||||||||||||||||||||||||||||||
| glob: true | ||||||||||||||||||||||||||||||||||||||||
| grep: true | ||||||||||||||||||||||||||||||||||||||||
| webfetch: false | ||||||||||||||||||||||||||||||||||||||||
| task: false | ||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # GitHub Code Search | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| <!-- AI-CONTEXT-START --> | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ## Quick Reference | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| - **Purpose**: Find real-world code examples from public GitHub repositories | ||||||||||||||||||||||||||||||||||||||||
| - **Tools**: `rg` (ripgrep), `gh` CLI, bash | ||||||||||||||||||||||||||||||||||||||||
| - **No MCP required**: Uses standard CLI tools | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| **When to use**: | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| - Finding implementation patterns for unfamiliar APIs | ||||||||||||||||||||||||||||||||||||||||
| - Discovering how libraries are used in production | ||||||||||||||||||||||||||||||||||||||||
| - Learning correct syntax and configuration | ||||||||||||||||||||||||||||||||||||||||
| - Understanding how different tools work together | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| **Search patterns** (use actual code, not keywords): | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| - Good: `useState(`, `import React from`, `async function` | ||||||||||||||||||||||||||||||||||||||||
| - Bad: `react tutorial`, `best practices`, `how to use` | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| <!-- AI-CONTEXT-END --> | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ## Search Methods | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ### 1. GitHub Code Search (via gh CLI) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Search across all public GitHub repositories: | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||
| # Basic search | ||||||||||||||||||||||||||||||||||||||||
| gh search code "pattern" --limit 10 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Filter by language | ||||||||||||||||||||||||||||||||||||||||
| gh search code "useState(" --language typescript --limit 10 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Filter by repository | ||||||||||||||||||||||||||||||||||||||||
| gh search code "getServerSession" --repo nextauthjs/next-auth --limit 10 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Filter by file path | ||||||||||||||||||||||||||||||||||||||||
| gh search code "middleware" --filename "*.ts" --limit 10 | ||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ### 2. Local Repository Search (via ripgrep) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Search within cloned repositories: | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||
| # Basic pattern search | ||||||||||||||||||||||||||||||||||||||||
| rg "pattern" --type ts | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Case-insensitive | ||||||||||||||||||||||||||||||||||||||||
| rg -i "pattern" --type py | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # With context lines | ||||||||||||||||||||||||||||||||||||||||
| rg -C 3 "pattern" --type js | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Regex patterns | ||||||||||||||||||||||||||||||||||||||||
| rg "useState\(.*loading" --type tsx | ||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, check if the file exists and read the relevant lines
cat -n .agent/tools/context/github-search.md | sed -n '70,110p'Repository: marcusquinn/aidevops Length of output: 1050 🏁 Script executed: # Verify ripgrep's type system
rg --type-list | head -100Repository: marcusquinn/aidevops Length of output: 2914 🏁 Script executed: # Specifically search for ts/tsx types
rg --type-list | grep -i "ts\|tsx"Repository: marcusquinn/aidevops Length of output: 755 Use The Apply at lines 74 and 104: Recommended approach-rg "useState\(.*loading" --type tsx
+rg "useState\(.*loading" --type ts-rg "useEffect\(\(\) => \{" --type tsx -C 2
+rg "useEffect\(\(\) => \{" --type ts -C 2Also correct line 77: 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Multiple file types | ||||||||||||||||||||||||||||||||||||||||
| rg "pattern" -t ts -t tsx -t js | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Exclude directories | ||||||||||||||||||||||||||||||||||||||||
| rg "pattern" --glob '!node_modules' --glob '!dist' | ||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ### 3. Clone and Search Pattern | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| For deeper analysis, clone popular repositories: | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||
| # Clone a specific repo | ||||||||||||||||||||||||||||||||||||||||
| gh repo clone vercel/next.js -- --depth 1 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Search within it | ||||||||||||||||||||||||||||||||||||||||
| rg "getServerSession" next.js/ | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Clean up | ||||||||||||||||||||||||||||||||||||||||
| rm -rf next.js | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+88
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ## Common Search Patterns | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ### React Patterns | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||
| # Hooks usage | ||||||||||||||||||||||||||||||||||||||||
| rg "useEffect\(\(\) => \{" --type tsx -C 2 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Error boundaries | ||||||||||||||||||||||||||||||||||||||||
| rg "class.*ErrorBoundary" --type tsx | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Context providers | ||||||||||||||||||||||||||||||||||||||||
| rg "createContext<" --type tsx | ||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ### API Patterns | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||
| # Express middleware | ||||||||||||||||||||||||||||||||||||||||
| rg "app\.(use|get|post)\(" --type ts | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Authentication | ||||||||||||||||||||||||||||||||||||||||
| rg "getServerSession|getSession" --type ts | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Database queries | ||||||||||||||||||||||||||||||||||||||||
| rg "prisma\.\w+\.(find|create|update)" --type ts | ||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ### Configuration Patterns | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||
| # Next.js config | ||||||||||||||||||||||||||||||||||||||||
| rg "module\.exports.*=.*\{" next.config.js | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # TypeScript config | ||||||||||||||||||||||||||||||||||||||||
| rg '"compilerOptions"' tsconfig.json -A 20 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Package scripts | ||||||||||||||||||||||||||||||||||||||||
| rg '"scripts"' package.json -A 10 | ||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ## Tips | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| 1. **Be specific**: More words = better results. "auth" is vague, "JWT token validation middleware" is specific. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| 2. **Use actual code**: Search for code patterns that would appear in files, not descriptions. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| 3. **Filter by language**: Reduces noise significantly. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| 4. **Check popular repos**: Well-maintained repos have better patterns. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| 5. **Look at tests**: Test files often show correct usage patterns. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ## Comparison with gh_grep MCP | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| | Feature | github-search (this) | gh_grep MCP | | ||||||||||||||||||||||||||||||||||||||||
| |---------|---------------------|-------------| | ||||||||||||||||||||||||||||||||||||||||
| | Token cost | 0 (no MCP) | ~600 tokens | | ||||||||||||||||||||||||||||||||||||||||
| | Speed | Fast (local rg) | Network dependent | | ||||||||||||||||||||||||||||||||||||||||
| | Scope | Local + gh CLI | GitHub API | | ||||||||||||||||||||||||||||||||||||||||
| | Regex | Full ripgrep | Limited | | ||||||||||||||||||||||||||||||||||||||||
| | Offline | Partial (local) | No | | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| This subagent provides the same functionality as `gh_grep` MCP without the token overhead. | ||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,10 +41,21 @@ mcp-index-helper.sh status | |
| ``` | ||
|
|
||
| **Why this matters**: | ||
|
|
||
| - MCP tool definitions consume context tokens | ||
| - Loading all MCPs upfront wastes tokens on unused tools | ||
| - On-demand discovery loads only what's needed | ||
|
|
||
| **Disabled MCPs** (enabled via subagents): | ||
|
|
||
| | MCP | Tokens | Subagent | | ||
| |-----|--------|----------| | ||
| | `playwriter` | ~3K | `@playwriter` | | ||
| | `augment-context-engine` | ~1K | `@augment-context-engine` | | ||
| | `gh_grep` | ~600 | `@github-search` (uses rg/bash) | | ||
|
|
||
| **Always enabled**: `osgrep` (primary semantic search, local, no auth) | ||
|
|
||
| <!-- AI-CONTEXT-END --> | ||
|
|
||
| ## Architecture | ||
|
|
@@ -120,18 +131,30 @@ mcp-index-helper.sh list dataforseo | |
|
|
||
| ### Subagent Frontmatter | ||
|
|
||
| Subagents declare which MCPs they need: | ||
| Subagents declare which MCPs they need via the `mcp:` field: | ||
|
|
||
| ```yaml | ||
| --- | ||
| description: SEO keyword research | ||
| description: Browser automation via Chrome extension | ||
| mode: subagent | ||
| tools: | ||
| dataforseo_*: true | ||
| serper_*: true | ||
| read: true | ||
| bash: true | ||
| mcp: | ||
| - playwriter | ||
| --- | ||
| ``` | ||
|
|
||
| When a subagent with `mcp:` is invoked, the agent should: | ||
|
|
||
| 1. Read the subagent file to get instructions | ||
| 2. Note the MCP requirement in the frontmatter | ||
| 3. Use the MCP tools as documented in the subagent | ||
|
|
||
| **Note**: The `mcp:` field is declarative - it documents which MCP the subagent | ||
| requires. The actual enabling happens in `generate-opencode-agents.sh` which | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The doc says the Other Locations
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| configures OpenCode's per-agent tool permissions. | ||
|
Comment on lines
+154
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This note appears to contradict the changes in Could you clarify how the enabling works? If it's a dynamic, runtime process triggered by the |
||
|
|
||
| ### Main Agent Pattern | ||
|
|
||
| Main agents don't enable MCPs directly. They: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments here say
playwriter_*is disabled globally, but later in this scriptconfig['tools']['playwriter_*'] = Trueand the Playwriter MCP is configured as eager-loaded, so it will still load for all agents and likely negate the intended token savings.Other Locations
.agent/scripts/generate-opencode-agents.sh:549.agent/scripts/generate-opencode-agents.sh:566🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.