opencode-toolbox 0.2.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/LICENSE +21 -0
- package/README.md +225 -0
- package/dist/index.js +38093 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sercan Sagman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# opencode-toolbox (Tool Search Tool)
|
|
2
|
+
|
|
3
|
+
An OpenCode plugin that implements a **tool search tool** pattern, allowing users to keep only a tiny set of tools in LLM context while accessing a larger MCP catalog on-demand.
|
|
4
|
+
|
|
5
|
+
## Motivation
|
|
6
|
+
|
|
7
|
+
OpenCode's MCP servers add tool schemas to LLM context at session start. With many MCPs, this can front-load tens of thousands of tokens, reducing "smart zone" capacity and degrading speed/accuracy.
|
|
8
|
+
|
|
9
|
+
opencode-toolbox solves this by:
|
|
10
|
+
- Exposing a **single `toolbox` tool** instead of 50+ MCP tools
|
|
11
|
+
- Search for tools using natural language (BM25) or regex patterns
|
|
12
|
+
- Execute discovered tools through the same interface
|
|
13
|
+
- Tool schemas are returned in search results for accurate LLM usage
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add opencode-toolbox
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
### 1. Add Plugin to OpenCode
|
|
24
|
+
|
|
25
|
+
Add `opencode-toolbox` to your `~/.config/opencode/opencode.jsonc`:
|
|
26
|
+
|
|
27
|
+
```jsonc
|
|
28
|
+
{
|
|
29
|
+
"plugin": ["opencode-toolbox"]
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Configure Toolbox
|
|
34
|
+
|
|
35
|
+
Create `~/.config/opencode/toolbox.jsonc`:
|
|
36
|
+
|
|
37
|
+
```jsonc
|
|
38
|
+
{
|
|
39
|
+
"servers": {
|
|
40
|
+
"time": {
|
|
41
|
+
"type": "local",
|
|
42
|
+
"command": ["npx", "-y", "@anthropic/mcp-time"]
|
|
43
|
+
},
|
|
44
|
+
"github": {
|
|
45
|
+
"type": "local",
|
|
46
|
+
"command": ["npx", "-y", "@anthropic/mcp-github"],
|
|
47
|
+
"environment": {
|
|
48
|
+
"GITHUB_TOKEN": "{env:GITHUB_TOKEN}"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"weather": {
|
|
52
|
+
"type": "remote",
|
|
53
|
+
"url": "https://mcp.example.com/weather",
|
|
54
|
+
"headers": {
|
|
55
|
+
"Authorization": "Bearer {env:WEATHER_API_KEY}"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"settings": {
|
|
60
|
+
"defaultLimit": 5
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Environment Variables
|
|
66
|
+
|
|
67
|
+
- `OPENCODE_TOOLBOX_CONFIG`: Path to config file (default: `~/.config/opencode/toolbox.jsonc`)
|
|
68
|
+
- Environment variable interpolation: Use `{env:VAR_NAME}` in config values
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
The plugin exposes a single `toolbox` tool with two actions:
|
|
73
|
+
|
|
74
|
+
### Search Action
|
|
75
|
+
|
|
76
|
+
Find tools using natural language (BM25):
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"tool": "toolbox",
|
|
81
|
+
"arguments": {
|
|
82
|
+
"action": "search",
|
|
83
|
+
"query": "get current time in timezone"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Or use regex patterns for precise matching:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"tool": "toolbox",
|
|
93
|
+
"arguments": {
|
|
94
|
+
"action": "search",
|
|
95
|
+
"pattern": "^time_.*",
|
|
96
|
+
"limit": 5
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Search Results
|
|
102
|
+
|
|
103
|
+
Returns tool schemas so the LLM knows exact parameters:
|
|
104
|
+
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"count": 1,
|
|
108
|
+
"tools": [
|
|
109
|
+
{
|
|
110
|
+
"name": "time_get_current_time",
|
|
111
|
+
"description": "Get current time in a specific timezone",
|
|
112
|
+
"score": 0.87,
|
|
113
|
+
"schema": {
|
|
114
|
+
"type": "object",
|
|
115
|
+
"properties": {
|
|
116
|
+
"timezone": {
|
|
117
|
+
"type": "string",
|
|
118
|
+
"description": "IANA timezone name (e.g., 'America/New_York')"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"required": ["timezone"]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
"usage": "Use toolbox({ action: 'execute', toolName: '<name>', toolArgs: '<json>' }) to call a tool"
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Execute Action
|
|
130
|
+
|
|
131
|
+
Call discovered tools with JSON-encoded arguments:
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"tool": "toolbox",
|
|
136
|
+
"arguments": {
|
|
137
|
+
"action": "execute",
|
|
138
|
+
"toolName": "time_get_current_time",
|
|
139
|
+
"toolArgs": "{\"timezone\": \"Asia/Tokyo\"}"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Example Flow
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
User: "What time is it in Tokyo?"
|
|
148
|
+
|
|
149
|
+
LLM: I need to find a time-related tool.
|
|
150
|
+
toolbox({ action: "search", query: "current time timezone" })
|
|
151
|
+
|
|
152
|
+
Toolbox: Returns time_get_current_time with its schema
|
|
153
|
+
|
|
154
|
+
LLM: Now I know the parameters. Let me call it.
|
|
155
|
+
toolbox({
|
|
156
|
+
action: "execute",
|
|
157
|
+
toolName: "time_get_current_time",
|
|
158
|
+
toolArgs: '{"timezone":"Asia/Tokyo"}'
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
Toolbox: { "datetime": "2026-01-07T02:15:00+09:00", "timezone": "Asia/Tokyo" }
|
|
162
|
+
|
|
163
|
+
LLM: "The current time in Tokyo is 2:15 AM on January 7, 2026."
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Search Modes
|
|
167
|
+
|
|
168
|
+
### BM25 (Natural Language)
|
|
169
|
+
- Best for semantic queries: "search the web", "get current time"
|
|
170
|
+
- Uses TF-IDF based ranking
|
|
171
|
+
- Searches tool name, description, and parameter info
|
|
172
|
+
|
|
173
|
+
### Regex (Pattern Matching)
|
|
174
|
+
- Best for precise matches: `^time_.*`, `github_`
|
|
175
|
+
- Supports `(?i)` prefix for case-insensitive matching
|
|
176
|
+
- Limited to 200 characters for safety
|
|
177
|
+
|
|
178
|
+
## Architecture
|
|
179
|
+
|
|
180
|
+
See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for detailed diagrams and flow explanations.
|
|
181
|
+
|
|
182
|
+
## Development
|
|
183
|
+
|
|
184
|
+
### Setup
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
bun install
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Tests
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
bun test # Run all tests
|
|
194
|
+
bun test --coverage # Run with coverage
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Build
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
bun run build
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Troubleshooting
|
|
204
|
+
|
|
205
|
+
### Plugin not loading
|
|
206
|
+
|
|
207
|
+
1. Check OpenCode logs for plugin errors
|
|
208
|
+
2. Verify `opencode-toolbox` is in the `plugin` array in `opencode.jsonc`
|
|
209
|
+
3. Ensure `toolbox.jsonc` exists and is valid JSON
|
|
210
|
+
|
|
211
|
+
### Search finds no tools
|
|
212
|
+
|
|
213
|
+
1. Verify underlying MCP servers are configured in `toolbox.jsonc`
|
|
214
|
+
2. Check tool descriptions for relevant keywords
|
|
215
|
+
3. Try broader search terms or regex patterns
|
|
216
|
+
|
|
217
|
+
### Execute fails
|
|
218
|
+
|
|
219
|
+
1. Verify the tool name format: `serverName_toolName`
|
|
220
|
+
2. Check `toolArgs` is valid JSON
|
|
221
|
+
3. Ensure underlying MCP server is running
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
MIT
|