-
Notifications
You must be signed in to change notification settings - Fork 5
feat: disable on-demand MCPs globally in opencode.json #277
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 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -301,6 +301,58 @@ cleanup_deprecated_mcps() { | |||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Disable MCPs globally that should only be enabled on-demand via subagents | ||||||||||||||||||||||||||||||||||||||
| # This reduces session startup context by ~4.6K tokens | ||||||||||||||||||||||||||||||||||||||
| # - playwriter: ~3K tokens - enable via @playwriter subagent | ||||||||||||||||||||||||||||||||||||||
| # - augment-context-engine: ~1K tokens - enable via @augment-context-engine subagent | ||||||||||||||||||||||||||||||||||||||
| # - gh-grep: ~600 tokens - replaced by @github-search subagent (uses rg/bash) | ||||||||||||||||||||||||||||||||||||||
| disable_ondemand_mcps() { | ||||||||||||||||||||||||||||||||||||||
| local opencode_config="$HOME/.config/opencode/opencode.json" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if [[ ! -f "$opencode_config" ]]; then | ||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if ! command -v jq &> /dev/null; then | ||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # MCPs to disable globally (enabled on-demand via subagents) | ||||||||||||||||||||||||||||||||||||||
| local -a ondemand_mcps=( | ||||||||||||||||||||||||||||||||||||||
| "playwriter" | ||||||||||||||||||||||||||||||||||||||
| "augment-context-engine" | ||||||||||||||||||||||||||||||||||||||
| "gh-grep" | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| local disabled=0 | ||||||||||||||||||||||||||||||||||||||
| local tmp_config | ||||||||||||||||||||||||||||||||||||||
| tmp_config=$(mktemp) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| cp "$opencode_config" "$tmp_config" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| for mcp in "${ondemand_mcps[@]}"; do | ||||||||||||||||||||||||||||||||||||||
| # Check if MCP exists and is currently enabled (or has no enabled field) | ||||||||||||||||||||||||||||||||||||||
| if jq -e ".mcp[\"$mcp\"]" "$tmp_config" > /dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||
| local current_enabled | ||||||||||||||||||||||||||||||||||||||
| current_enabled=$(jq -r ".mcp[\"$mcp\"].enabled // \"true\"" "$tmp_config") | ||||||||||||||||||||||||||||||||||||||
| if [[ "$current_enabled" != "false" ]]; then | ||||||||||||||||||||||||||||||||||||||
| jq ".mcp[\"$mcp\"].enabled = false" "$tmp_config" > "${tmp_config}.new" && mv "${tmp_config}.new" "$tmp_config" | ||||||||||||||||||||||||||||||||||||||
| ((disabled++)) | ||||||||||||||||||||||||||||||||||||||
|
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.
Comment on lines
+333
to
+340
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. Only increment If 🔧 Suggested fix- if [[ "$current_enabled" != "false" ]]; then
- jq ".mcp[\"$mcp\"].enabled = false" "$tmp_config" > "${tmp_config}.new" && mv "${tmp_config}.new" "$tmp_config"
- ((disabled++))
- fi
+ if [[ "$current_enabled" != "false" ]]; then
+ if jq ".mcp[\"$mcp\"].enabled = false" "$tmp_config" > "${tmp_config}.new" && mv "${tmp_config}.new" "$tmp_config"; then
+ ((disabled++))
+ fi
+ fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+335
to
+342
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 change improves the script in two ways:
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if [[ $disabled -gt 0 ]]; then | ||||||||||||||||||||||||||||||||||||||
| create_backup_with_rotation "$opencode_config" "opencode" | ||||||||||||||||||||||||||||||||||||||
| mv "$tmp_config" "$opencode_config" | ||||||||||||||||||||||||||||||||||||||
| print_info "Disabled $disabled MCP(s) globally (use subagents to enable on-demand)" | ||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||
| rm -f "$tmp_config" | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Migrate old config-backups to new per-type backup structure | ||||||||||||||||||||||||||||||||||||||
| # This runs once to clean up the legacy backup directory | ||||||||||||||||||||||||||||||||||||||
| migrate_old_backups() { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -3335,6 +3387,7 @@ main() { | |||||||||||||||||||||||||||||||||||||
| confirm_step "Migrate loop state from .claude/ to .agent/loop-state/" && migrate_loop_state_directories | ||||||||||||||||||||||||||||||||||||||
| confirm_step "Cleanup deprecated agent paths" && cleanup_deprecated_paths | ||||||||||||||||||||||||||||||||||||||
| confirm_step "Cleanup deprecated MCP entries (hetzner, serper, etc.)" && cleanup_deprecated_mcps | ||||||||||||||||||||||||||||||||||||||
| confirm_step "Disable on-demand MCPs globally (playwriter, augment, gh-grep)" && disable_ondemand_mcps | ||||||||||||||||||||||||||||||||||||||
|
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 runs before 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
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 the general structure and locate the functions
git ls-files | grep -E "setup\.sh|generate.*opencode"Repository: marcusquinn/aidevops Length of output: 303 🏁 Script executed: # Look at the context around line 3390 in setup.sh
sed -n '3385,3395p' setup.shRepository: marcusquinn/aidevops Length of output: 1033 🏁 Script executed: # Find the disable_ondemand_mcps function
rg -n "disable_ondemand_mcps" setup.shRepository: marcusquinn/aidevops Length of output: 205 🏁 Script executed: # Find the update_opencode_config function
rg -n "update_opencode_config" setup.shRepository: marcusquinn/aidevops Length of output: 175 🏁 Script executed: # Locate the generator script
fd -name "*generate*opencode*" -o -name "*opencode*generator*"Repository: marcusquinn/aidevops Length of output: 294 🏁 Script executed: # Find generator scripts with correct syntax
find . -name "generate-opencode*.sh"Repository: marcusquinn/aidevops Length of output: 155 🏁 Script executed: # View the order of execution and surrounding context (wider range)
sed -n '3385,3410p' setup.shRepository: marcusquinn/aidevops Length of output: 2181 🏁 Script executed: # Examine disable_ondemand_mcps function
sed -n '309,340p' setup.shRepository: marcusquinn/aidevops Length of output: 1127 🏁 Script executed: # Examine update_opencode_config function
sed -n '2042,2080p' setup.shRepository: marcusquinn/aidevops Length of output: 1644 🏁 Script executed: # Check the generator script for MCP config handling
cat .agent/scripts/generate-opencode-agents.sh | head -100Repository: marcusquinn/aidevops Length of output: 4157 🏁 Script executed: # Get the full generate-opencode-agents.sh script
wc -l .agent/scripts/generate-opencode-agents.shRepository: marcusquinn/aidevops Length of output: 110 🏁 Script executed: # Extract the Python section that handles MCP config
sed -n '/python3/,/PYEOF/p' .agent/scripts/generate-opencode-agents.sh | head -200Repository: marcusquinn/aidevops Length of output: 7855 🏁 Script executed: # Look specifically for how the script handles 'mcp' or 'enabled' in the Python code
rg -A 5 -B 5 '"mcp"|enabled' .agent/scripts/generate-opencode-agents.shRepository: marcusquinn/aidevops Length of output: 9487 Move The generator script enforces an MCP loading policy that sets 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| confirm_step "Extract OpenCode prompts" && extract_opencode_prompts | ||||||||||||||||||||||||||||||||||||||
| confirm_step "Check OpenCode prompt drift" && check_opencode_prompt_drift | ||||||||||||||||||||||||||||||||||||||
| confirm_step "Deploy aidevops agents to ~/.aidevops/agents/" && deploy_aidevops_agents | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
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.
In
ondemand_mcps, the entry usesgh-grep, but other parts of the repo appear to name this MCPgh_grep(underscore). Ifopencode.jsonuses the underscore key, this loop will never match andgh_grepwon’t actually be disabled.🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.