opencode-toolbox 0.3.0 → 0.4.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/README.md +21 -49
- package/dist/index.js +12 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,17 +7,11 @@ An OpenCode plugin that implements a **tool search tool** pattern, allowing user
|
|
|
7
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
8
|
|
|
9
9
|
opencode-toolbox solves this by:
|
|
10
|
-
- Exposing a
|
|
10
|
+
- Exposing **a few toolbox tools** instead of 50+ MCP tools
|
|
11
11
|
- Search for tools using natural language (BM25) or regex patterns
|
|
12
12
|
- Execute discovered tools through the same interface
|
|
13
13
|
- Tool schemas are returned in search results for accurate LLM usage
|
|
14
14
|
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
bun add opencode-toolbox
|
|
19
|
-
```
|
|
20
|
-
|
|
21
15
|
## Configuration
|
|
22
16
|
|
|
23
17
|
### 1. Add Plugin to OpenCode
|
|
@@ -36,7 +30,7 @@ Create `~/.config/opencode/toolbox.jsonc`:
|
|
|
36
30
|
|
|
37
31
|
```jsonc
|
|
38
32
|
{
|
|
39
|
-
"
|
|
33
|
+
"mcp": {
|
|
40
34
|
"time": {
|
|
41
35
|
"type": "local",
|
|
42
36
|
"command": ["npx", "-y", "@anthropic/mcp-time"]
|
|
@@ -69,38 +63,27 @@ Create `~/.config/opencode/toolbox.jsonc`:
|
|
|
69
63
|
|
|
70
64
|
## Usage
|
|
71
65
|
|
|
72
|
-
The plugin exposes
|
|
66
|
+
The plugin exposes three tools:
|
|
73
67
|
|
|
74
|
-
###
|
|
68
|
+
### toolbox_search_bm25
|
|
75
69
|
|
|
76
|
-
|
|
70
|
+
Search for tools using natural language:
|
|
77
71
|
|
|
78
|
-
```
|
|
79
|
-
{
|
|
80
|
-
"tool": "toolbox",
|
|
81
|
-
"arguments": {
|
|
82
|
-
"action": "search",
|
|
83
|
-
"query": "get current time in timezone"
|
|
84
|
-
}
|
|
85
|
-
}
|
|
72
|
+
```
|
|
73
|
+
toolbox_search_bm25({ text: "get current time in timezone" })
|
|
86
74
|
```
|
|
87
75
|
|
|
88
|
-
|
|
76
|
+
### toolbox_search_regex
|
|
89
77
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
"action": "search",
|
|
95
|
-
"pattern": "^time_.*",
|
|
96
|
-
"limit": 5
|
|
97
|
-
}
|
|
98
|
-
}
|
|
78
|
+
Search for tools using regex patterns on tool names:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
toolbox_search_regex({ pattern: "time_.*", limit: 5 })
|
|
99
82
|
```
|
|
100
83
|
|
|
101
84
|
### Search Results
|
|
102
85
|
|
|
103
|
-
|
|
86
|
+
Both search tools return tool schemas so the LLM knows exact parameters:
|
|
104
87
|
|
|
105
88
|
```json
|
|
106
89
|
{
|
|
@@ -122,23 +105,16 @@ Returns tool schemas so the LLM knows exact parameters:
|
|
|
122
105
|
}
|
|
123
106
|
}
|
|
124
107
|
],
|
|
125
|
-
"usage": "Use
|
|
108
|
+
"usage": "Use toolbox_execute({ name: '<tool_name>', arguments: '<json>' }) to run a discovered tool"
|
|
126
109
|
}
|
|
127
110
|
```
|
|
128
111
|
|
|
129
|
-
###
|
|
112
|
+
### toolbox_execute
|
|
130
113
|
|
|
131
|
-
|
|
114
|
+
Execute a discovered tool with JSON-encoded arguments:
|
|
132
115
|
|
|
133
|
-
```
|
|
134
|
-
{
|
|
135
|
-
"tool": "toolbox",
|
|
136
|
-
"arguments": {
|
|
137
|
-
"action": "execute",
|
|
138
|
-
"toolName": "time_get_current_time",
|
|
139
|
-
"toolArgs": "{\"timezone\": \"Asia/Tokyo\"}"
|
|
140
|
-
}
|
|
141
|
-
}
|
|
116
|
+
```
|
|
117
|
+
toolbox_execute({ name: "time_get_current_time", arguments: '{"timezone": "Asia/Tokyo"}' })
|
|
142
118
|
```
|
|
143
119
|
|
|
144
120
|
## Example Flow
|
|
@@ -147,16 +123,12 @@ Call discovered tools with JSON-encoded arguments:
|
|
|
147
123
|
User: "What time is it in Tokyo?"
|
|
148
124
|
|
|
149
125
|
LLM: I need to find a time-related tool.
|
|
150
|
-
|
|
126
|
+
toolbox_search_bm25({ text: "current time timezone" })
|
|
151
127
|
|
|
152
128
|
Toolbox: Returns time_get_current_time with its schema
|
|
153
129
|
|
|
154
130
|
LLM: Now I know the parameters. Let me call it.
|
|
155
|
-
|
|
156
|
-
action: "execute",
|
|
157
|
-
toolName: "time_get_current_time",
|
|
158
|
-
toolArgs: '{"timezone":"Asia/Tokyo"}'
|
|
159
|
-
})
|
|
131
|
+
toolbox_execute({ name: "time_get_current_time", arguments: '{"timezone":"Asia/Tokyo"}' })
|
|
160
132
|
|
|
161
133
|
Toolbox: { "datetime": "2026-01-07T02:15:00+09:00", "timezone": "Asia/Tokyo" }
|
|
162
134
|
|
|
@@ -217,7 +189,7 @@ bun run build
|
|
|
217
189
|
### Execute fails
|
|
218
190
|
|
|
219
191
|
1. Verify the tool name format: `serverName_toolName`
|
|
220
|
-
2. Check `
|
|
192
|
+
2. Check `arguments` is valid JSON
|
|
221
193
|
3. Ensure underlying MCP server is running
|
|
222
194
|
|
|
223
195
|
## License
|
package/dist/index.js
CHANGED
|
@@ -32817,7 +32817,7 @@ var SettingsConfigSchema = exports_external2.object({
|
|
|
32817
32817
|
defaultLimit: exports_external2.number().min(1).max(20).default(5)
|
|
32818
32818
|
});
|
|
32819
32819
|
var ConfigSchema = exports_external2.object({
|
|
32820
|
-
|
|
32820
|
+
mcp: exports_external2.record(exports_external2.string(), ServerConfigSchema),
|
|
32821
32821
|
settings: SettingsConfigSchema.optional()
|
|
32822
32822
|
});
|
|
32823
32823
|
// node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
@@ -37952,10 +37952,8 @@ var SYSTEM_PROMPT_BASE = `# Extended Toolbox
|
|
|
37952
37952
|
|
|
37953
37953
|
You have access to an extended toolbox with additional capabilities (web search, time utilities, code search, etc.).
|
|
37954
37954
|
|
|
37955
|
-
##
|
|
37956
|
-
|
|
37957
|
-
2. ALWAYS toolbox_search_* if you think that user wants you to use some tools
|
|
37958
|
-
3. ALWAYS toolbox_search_* if you think that user may refer specific tool name which is not exist in the context
|
|
37955
|
+
## Rule
|
|
37956
|
+
ALWAYS search before saying "I cannot do that" or "I don't have access to."
|
|
37959
37957
|
|
|
37960
37958
|
## Workflow
|
|
37961
37959
|
1. Search: toolbox_search_bm25({ text: "what you need" }) or toolbox_search_regex({ pattern: "prefix_.*" })
|
|
@@ -37965,21 +37963,22 @@ function generateSystemPrompt(mcpManager) {
|
|
|
37965
37963
|
if (servers.length === 0) {
|
|
37966
37964
|
return SYSTEM_PROMPT_BASE;
|
|
37967
37965
|
}
|
|
37968
|
-
const
|
|
37966
|
+
const toolboxSchema = {};
|
|
37969
37967
|
for (const server of servers) {
|
|
37970
37968
|
if (server.status === "connected" && server.tools.length > 0) {
|
|
37971
|
-
|
|
37972
|
-
serverLines.push(`- ${server.name}: ${toolNames}`);
|
|
37969
|
+
toolboxSchema[server.name] = server.tools.map((t) => t.idString);
|
|
37973
37970
|
}
|
|
37974
37971
|
}
|
|
37975
|
-
if (
|
|
37972
|
+
if (Object.keys(toolboxSchema).length === 0) {
|
|
37976
37973
|
return SYSTEM_PROMPT_BASE;
|
|
37977
37974
|
}
|
|
37978
37975
|
return `${SYSTEM_PROMPT_BASE}
|
|
37979
37976
|
|
|
37980
|
-
##
|
|
37981
|
-
|
|
37982
|
-
|
|
37977
|
+
## Toolbox Schema
|
|
37978
|
+
Tool names use \`<server>_<tool>\` format. Pass exact names to toolbox_execute().
|
|
37979
|
+
\`\`\`json
|
|
37980
|
+
${JSON.stringify(toolboxSchema, null, 2)}
|
|
37981
|
+
\`\`\``;
|
|
37983
37982
|
}
|
|
37984
37983
|
var ToolboxPlugin = async (ctx) => {
|
|
37985
37984
|
const configPath = process.env.OPENCODE_TOOLBOX_CONFIG || DEFAULT_CONFIG_PATH;
|
|
@@ -37996,7 +37995,7 @@ var ToolboxPlugin = async (ctx) => {
|
|
|
37996
37995
|
if (initialized)
|
|
37997
37996
|
return;
|
|
37998
37997
|
try {
|
|
37999
|
-
await mcpManager.initialize(config3.
|
|
37998
|
+
await mcpManager.initialize(config3.mcp);
|
|
38000
37999
|
const allTools = mcpManager.getAllCatalogTools();
|
|
38001
38000
|
bm25Index.indexTools(allTools);
|
|
38002
38001
|
initialized = true;
|
package/package.json
CHANGED