opencode-mcp-triage 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/commands/mcp-triage.md +4 -0
- package/.opencode/commands/triage.md +5 -0
- package/.opencode/plugins/opencode-mcp-triage.ts +1 -0
- package/README.md +242 -0
- package/bin/opencode-mcp-triage.cjs +764 -0
- package/package.json +60 -0
- package/postinstall.cjs +27 -0
- package/src/config.ts +245 -0
- package/src/index.ts +425 -0
- package/src/lock.ts +42 -0
- package/src/triage.ts +121 -0
- package/src/types.ts +63 -0
- package/src/writer.ts +468 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { server } from "../../src/index.js"
|
package/README.md
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# opencode-mcp-triage
|
|
2
|
+
|
|
3
|
+
> opencode-mcp-triage strips MCP tool definitions from the main prompt and routes them to dedicated subagents. Instead of loading every server's tools into every message, it uses keyword matching to activate only what you need. Cuts prompt token costs by eliminating MCP tool bloat — no LLM overhead, no extra API calls, zero setup.
|
|
4
|
+
|
|
5
|
+
## What It Does
|
|
6
|
+
|
|
7
|
+
Normally all MCP servers load their tools into the system prompt and burn tokens on every message — even when irrelevant. Triage disables all MCP tools globally and routes work to scoped subagents that carry only the tools they need.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
Without triage: [supabase tools] [github tools] [render tools] ... ← always burning tokens
|
|
11
|
+
With triage: triage_mcp({ query }) → @github → github tools only
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
By default, each subagent carries one MCP server's tools. The main session carries zero. Token savings are **static per MCP server** — the same for every user with the same servers installed.
|
|
15
|
+
|
|
16
|
+
This plugin is OpenCode-only — it has no effect on Claude Desktop, Cursor, Windsurf, or any other tool using the same MCP config. Your MCP servers remain fully functional everywhere else.
|
|
17
|
+
|
|
18
|
+
## Token Savings
|
|
19
|
+
|
|
20
|
+
Real data from this project's 6 MCP servers (measured with `opencode-mcp-triage measure`):
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
TOKENS SAVED PER TURN (by routing MCPs to subagents)
|
|
24
|
+
|
|
25
|
+
supabase 29 tools 19255 chars ~ 4814 tokens
|
|
26
|
+
netlify 9 tools 12322 chars ~ 3081 tokens
|
|
27
|
+
render 24 tools 28244 chars ~ 7061 tokens
|
|
28
|
+
clickup 51 tools 121319 chars ~30330 tokens
|
|
29
|
+
context7 2 tools 4605 chars ~ 1151 tokens
|
|
30
|
+
github 26 tools 15827 chars ~ 3957 tokens
|
|
31
|
+
----------------------------------------------------
|
|
32
|
+
TOTAL 141 tools 201572 chars ~ 50394 tokens
|
|
33
|
+
|
|
34
|
+
Each user turn saves ~50.394 tokens
|
|
35
|
+
that would otherwise be sent with every prompt.
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Tool definitions are static per MCP server — same savings for every user with the same servers installed. Run `opencode-mcp-triage measure` for live numbers based on your MCP inventory.
|
|
39
|
+
|
|
40
|
+
## How It Works
|
|
41
|
+
|
|
42
|
+
The LLM calls `triage_mcp()` when it encounters a task that needs MCP tools. The plugin scores all subagents against the query using keyword matching and returns the best match.
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
User: "manage GitHub issues"
|
|
46
|
+
│
|
|
47
|
+
▼
|
|
48
|
+
LLM: triage_mcp({ query: "manage GitHub issues" })
|
|
49
|
+
│
|
|
50
|
+
▼
|
|
51
|
+
Plugin: scores subagents → returns best match
|
|
52
|
+
@github score=75 (matched: github ×3, issues in description ×1)
|
|
53
|
+
@clickup score=0
|
|
54
|
+
gap=75 ≥ threshold(30) → HIGH CONFIDENCE
|
|
55
|
+
│
|
|
56
|
+
▼
|
|
57
|
+
LLM: invokes @github subagent → carries only github tools
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
No LLM reasoning overhead. No extra API calls. Just fast deterministic matching.
|
|
61
|
+
|
|
62
|
+
### Scoring Engine
|
|
63
|
+
|
|
64
|
+
- **Subagent name** matches: weight ×3
|
|
65
|
+
- **MCP server name** matches: weight ×3
|
|
66
|
+
- **Description** matches: weight ×1
|
|
67
|
+
|
|
68
|
+
Clear winner (gap ≥ 30): auto-routes. Too close: shows top 5 options. No matches: lists all available subagents.
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm install -g opencode-mcp-triage
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Restart OpenCode. The plugin auto-disables all MCP tools and auto-creates one subagent per MCP server. No manual config needed. Type `/mcp-triage status` to verify.
|
|
77
|
+
|
|
78
|
+
## Install
|
|
79
|
+
|
|
80
|
+
### Global (recommended)
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm install -g opencode-mcp-triage
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Restart OpenCode. `/mcp-triage` is available in **every** project.
|
|
87
|
+
|
|
88
|
+
### Per-project
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm install opencode-mcp-triage
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Restart OpenCode. `/mcp-triage` is available only in this project.
|
|
95
|
+
|
|
96
|
+
### Dev / local
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
git clone https://github.com/cascharly/opencode-mcp-triage.git
|
|
100
|
+
cd opencode-mcp-triage
|
|
101
|
+
npm install
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Add to your opencode config:
|
|
105
|
+
|
|
106
|
+
```jsonc
|
|
107
|
+
{ "plugin": ["file:/path/to/opencode-mcp-triage"] }
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## LLM Quick-Install
|
|
111
|
+
|
|
112
|
+
Copy-paste this into any LLM:
|
|
113
|
+
|
|
114
|
+
```text
|
|
115
|
+
Install opencode-mcp-triage (https://github.com/cascharly/opencode-mcp-triage) — a deterministic MCP subagent router for OpenCode.
|
|
116
|
+
|
|
117
|
+
1. Run: npm install -g opencode-mcp-triage
|
|
118
|
+
2. If any errors occur, visit the repo link above and resolve them.
|
|
119
|
+
3. Tell me to restart OpenCode.
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Configuration
|
|
123
|
+
|
|
124
|
+
The plugin handles everything automatically — no manual editing required. This section shows what gets generated and how to customize it if needed.
|
|
125
|
+
|
|
126
|
+
### Auto-generated config
|
|
127
|
+
|
|
128
|
+
On first run, the plugin writes tool disable entries and auto-creates one subagent per MCP server:
|
|
129
|
+
|
|
130
|
+
```jsonc
|
|
131
|
+
{
|
|
132
|
+
"tools": {
|
|
133
|
+
"github_*": false,
|
|
134
|
+
"render_*": false
|
|
135
|
+
},
|
|
136
|
+
"agent": {
|
|
137
|
+
"github": {
|
|
138
|
+
"description": "GitHub issue/PR management",
|
|
139
|
+
"mode": "subagent",
|
|
140
|
+
"tools": { "github_*": true }
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Commands
|
|
147
|
+
|
|
148
|
+
### Plugin Tools
|
|
149
|
+
|
|
150
|
+
| Tool | What it does |
|
|
151
|
+
|---|---|
|
|
152
|
+
| `triage_mcp` | Route a task to the right MCP subagent using keyword matching |
|
|
153
|
+
| `mcp_stats` | Show routing status, subagent-to-server map, and coverage |
|
|
154
|
+
|
|
155
|
+
### CLI Commands (available in terminal AND as `/mcp-triage <command>`)
|
|
156
|
+
|
|
157
|
+
| Command | What it does |
|
|
158
|
+
|---|---|
|
|
159
|
+
| `status` | Show MCP server status, hidden/exposed tools, subagent routing |
|
|
160
|
+
| `list` | List all configured MCP servers and subagents |
|
|
161
|
+
| `measure` | Connect to each MCP server and measure token savings per turn |
|
|
162
|
+
| `help` | Show available commands |
|
|
163
|
+
|
|
164
|
+
### Flags
|
|
165
|
+
|
|
166
|
+
| Flag | Where | What it does |
|
|
167
|
+
|---|---|---|
|
|
168
|
+
| `--json` | All commands | Machine-readable JSON output |
|
|
169
|
+
| `--verbose` | `measure` | Show error diagnostics (HTTP codes, spawn errors, timeouts) |
|
|
170
|
+
| `--timeout=N` | `measure` | Per-server timeout in seconds (default: 60) |
|
|
171
|
+
|
|
172
|
+
All CLI commands can be run directly in your terminal via `npx opencode-mcp-triage <command>` (e.g., `npx opencode-mcp-triage measure --verbose`). No OpenCode session needed.
|
|
173
|
+
|
|
174
|
+
## Under the Hood
|
|
175
|
+
|
|
176
|
+
### Plugin Activation
|
|
177
|
+
|
|
178
|
+
`opencode-mcp-triage` is a standard opencode plugin registered in the `"plugin"` array of `opencode.jsonc` (both `~/.config/opencode/opencode.jsonc` globally and `.opencode/opencode.jsonc` per-project). On startup, opencode loads all listed plugins, making their tools and commands available. The plugin registers `triage_mcp` and `mcp_stats` in the system prompt alongside `read`, `write`, `bash`, etc.
|
|
179
|
+
|
|
180
|
+
### How Tool Disabling Works
|
|
181
|
+
|
|
182
|
+
The plugin writes `"servername_*": false` entries to the `"tools"` block of your project config. OpenCode uses glob patterns to match tools — `"github_*": false` disables all tools from the github MCP server in the main session.
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
Main session tools:
|
|
186
|
+
github_*: false ← disabled, 0 tokens
|
|
187
|
+
supabase_*: false ← disabled, 0 tokens
|
|
188
|
+
render_*: false ← disabled, 0 tokens
|
|
189
|
+
|
|
190
|
+
@github subagent tools:
|
|
191
|
+
github_*: true ← enabled, ~4K tokens in subagent sessions only
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
MCP tool definitions are never loaded in the main session — they stay isolated in subagent contexts.
|
|
195
|
+
|
|
196
|
+
### Auto-Created Subagents
|
|
197
|
+
|
|
198
|
+
On first run, the plugin creates one subagent per MCP server that doesn't already have one. The subagent name matches the server name, and its description comes from the server's `description` field.
|
|
199
|
+
|
|
200
|
+
**Behavior:**
|
|
201
|
+
- Already-covered MCP servers are skipped — existing user-defined subagents are never touched
|
|
202
|
+
- Deleting an auto-created subagent is respected — tracked via `.opencode/mcp-triage.json`
|
|
203
|
+
- Adding a new MCP server later auto-creates its subagent on reload (`triage_mcp query: "reload"`)
|
|
204
|
+
- Power users can delete auto-created entries and define grouped subagents if desired, though separate subagents save more tokens per query
|
|
205
|
+
|
|
206
|
+
### Config Caching
|
|
207
|
+
|
|
208
|
+
MCP server and subagent config reads are cached with a 5-second TTL. CLI toggles (add/remove MCP servers, change subagents) are picked up within 5 seconds without restarting OpenCode. Reload manually with `triage_mcp query: "reload"`.
|
|
209
|
+
|
|
210
|
+
## Uninstall
|
|
211
|
+
|
|
212
|
+
1. Remove `"opencode-mcp-triage"` from the `"plugin"` array in your config
|
|
213
|
+
2. Remove the auto-generated `"servername_*": false` entries from `"tools"`
|
|
214
|
+
3. (Optional) Remove any auto-created subagents from `"agent"`
|
|
215
|
+
4. (Optional) Delete the lock file at `.opencode/mcp-triage.json`
|
|
216
|
+
5. Delete the slash command:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# macOS / Linux
|
|
220
|
+
rm ~/.config/opencode/commands/mcp-triage.md
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
```cmd
|
|
224
|
+
:: Windows (cmd)
|
|
225
|
+
del %USERPROFILE%\.config\opencode\commands\mcp-triage.md
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Restart OpenCode. Clean.
|
|
229
|
+
|
|
230
|
+
## Compatibility
|
|
231
|
+
|
|
232
|
+
- OpenCode 1.14+
|
|
233
|
+
- Node.js 18+ (for CLI)
|
|
234
|
+
- TypeScript 6+ (for development)
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
MIT
|
|
239
|
+
|
|
240
|
+
## Author
|
|
241
|
+
|
|
242
|
+
Carlos Spagnoletti
|