opencode-toolbox 0.2.0 → 0.3.1

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.
Files changed (3) hide show
  1. package/README.md +20 -48
  2. package/dist/index.js +28 -2
  3. 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 **single `toolbox` tool** instead of 50+ MCP tools
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
@@ -69,38 +63,27 @@ Create `~/.config/opencode/toolbox.jsonc`:
69
63
 
70
64
  ## Usage
71
65
 
72
- The plugin exposes a single `toolbox` tool with two actions:
66
+ The plugin exposes three tools:
73
67
 
74
- ### Search Action
68
+ ### toolbox_search_bm25
75
69
 
76
- Find tools using natural language (BM25):
70
+ Search for tools using natural language:
77
71
 
78
- ```json
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
- Or use regex patterns for precise matching:
76
+ ### toolbox_search_regex
89
77
 
90
- ```json
91
- {
92
- "tool": "toolbox",
93
- "arguments": {
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
- Returns tool schemas so the LLM knows exact parameters:
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 toolbox({ action: 'execute', toolName: '<name>', toolArgs: '<json>' }) to call a tool"
108
+ "usage": "Use toolbox_execute({ name: '<tool_name>', arguments: '<json>' }) to run a discovered tool"
126
109
  }
127
110
  ```
128
111
 
129
- ### Execute Action
112
+ ### toolbox_execute
130
113
 
131
- Call discovered tools with JSON-encoded arguments:
114
+ Execute a discovered tool with JSON-encoded arguments:
132
115
 
133
- ```json
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
- toolbox({ action: "search", query: "current time timezone" })
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
- toolbox({
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 `toolArgs` is valid JSON
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
@@ -37948,7 +37948,7 @@ Returns tools with schemas. Use toolbox_execute() to run them.`;
37948
37948
  var EXECUTE_DESC = `Execute a tool discovered via toolbox_search_bm25 or toolbox_search_regex.
37949
37949
 
37950
37950
  Pass arguments as JSON string matching the tool's schema.`;
37951
- var SYSTEM_PROMPT = `# Extended Toolbox
37951
+ 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
 
@@ -37960,6 +37960,27 @@ You have access to an extended toolbox with additional capabilities (web search,
37960
37960
  ## Workflow
37961
37961
  1. Search: toolbox_search_bm25({ text: "what you need" }) or toolbox_search_regex({ pattern: "prefix_.*" })
37962
37962
  2. Execute: toolbox_execute({ name: "tool_name", arguments: '{"key": "value"}' })`;
37963
+ function generateSystemPrompt(mcpManager) {
37964
+ const servers = mcpManager.getAllServers();
37965
+ if (servers.length === 0) {
37966
+ return SYSTEM_PROMPT_BASE;
37967
+ }
37968
+ const serverLines = [];
37969
+ for (const server of servers) {
37970
+ if (server.status === "connected" && server.tools.length > 0) {
37971
+ const toolNames = server.tools.map((t) => t.id.name).join(", ");
37972
+ serverLines.push(`- ${server.name}: ${toolNames}`);
37973
+ }
37974
+ }
37975
+ if (serverLines.length === 0) {
37976
+ return SYSTEM_PROMPT_BASE;
37977
+ }
37978
+ return `${SYSTEM_PROMPT_BASE}
37979
+
37980
+ ## Registered MCP Servers
37981
+ ${serverLines.join(`
37982
+ `)}`;
37983
+ }
37963
37984
  var ToolboxPlugin = async (ctx) => {
37964
37985
  const configPath = process.env.OPENCODE_TOOLBOX_CONFIG || DEFAULT_CONFIG_PATH;
37965
37986
  const configResult = await loadConfig(configPath);
@@ -38083,7 +38104,12 @@ var ToolboxPlugin = async (ctx) => {
38083
38104
  })
38084
38105
  },
38085
38106
  "experimental.chat.system.transform": async (_input, output) => {
38086
- output.system.push(SYSTEM_PROMPT);
38107
+ try {
38108
+ await ensureInitialized();
38109
+ output.system.push(generateSystemPrompt(mcpManager));
38110
+ } catch {
38111
+ output.system.push(SYSTEM_PROMPT_BASE);
38112
+ }
38087
38113
  }
38088
38114
  };
38089
38115
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-toolbox",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Tool Search Tool Plugin for OpenCode - search and execute tools from MCP servers on-demand",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",