mcp-server-opencode 1.0.0 → 1.1.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.
- package/README.md +122 -37
- package/build/src/index.js +2 -2
- package/build/src/index.js.map +1 -1
- package/build/src/modules/resources/delegate-task-instructions.d.ts +3 -0
- package/build/src/modules/resources/delegate-task-instructions.d.ts.map +1 -0
- package/build/src/modules/resources/delegate-task-instructions.js +53 -0
- package/build/src/modules/resources/delegate-task-instructions.js.map +1 -0
- package/build/src/modules/resources/index.d.ts +3 -0
- package/build/src/modules/resources/index.d.ts.map +1 -0
- package/build/src/modules/resources/index.js +5 -0
- package/build/src/modules/resources/index.js.map +1 -0
- package/build/src/modules/shared/opencode-client.d.ts +17 -1
- package/build/src/modules/shared/opencode-client.d.ts.map +1 -1
- package/build/src/modules/shared/opencode-client.js +44 -2
- package/build/src/modules/shared/opencode-client.js.map +1 -1
- package/build/src/modules/tools/cancel_task.d.ts +3 -0
- package/build/src/modules/tools/cancel_task.d.ts.map +1 -0
- package/build/src/modules/tools/cancel_task.js +33 -0
- package/build/src/modules/tools/cancel_task.js.map +1 -0
- package/build/src/modules/tools/continue_task.d.ts +3 -0
- package/build/src/modules/tools/continue_task.d.ts.map +1 -0
- package/build/src/modules/tools/continue_task.js +71 -0
- package/build/src/modules/tools/continue_task.js.map +1 -0
- package/build/src/modules/tools/get_task_status.d.ts.map +1 -1
- package/build/src/modules/tools/get_task_status.js +8 -2
- package/build/src/modules/tools/get_task_status.js.map +1 -1
- package/build/src/modules/tools/index.d.ts.map +1 -1
- package/build/src/modules/tools/index.js +4 -0
- package/build/src/modules/tools/index.js.map +1 -1
- package/build/src/modules/tools/start_task.d.ts.map +1 -1
- package/build/src/modules/tools/start_task.js +5 -2
- package/build/src/modules/tools/start_task.js.map +1 -1
- package/build/src/modules/tools/wait_for_task.d.ts.map +1 -1
- package/build/src/modules/tools/wait_for_task.js +38 -4
- package/build/src/modules/tools/wait_for_task.js.map +1 -1
- package/build/src/test-utils/fake-mcp-server.d.ts +3 -3
- package/build/src/test-utils/fake-mcp-server.d.ts.map +1 -1
- package/build/src/test-utils/fake-mcp-server.js +12 -12
- package/build/src/test-utils/fake-mcp-server.js.map +1 -1
- package/package.json +17 -4
- package/build/src/modules/prompts/delegate_task.d.ts +0 -3
- package/build/src/modules/prompts/delegate_task.d.ts.map +0 -1
- package/build/src/modules/prompts/delegate_task.js +0 -33
- package/build/src/modules/prompts/delegate_task.js.map +0 -1
- package/build/src/modules/prompts/index.d.ts +0 -3
- package/build/src/modules/prompts/index.d.ts.map +0 -1
- package/build/src/modules/prompts/index.js +0 -5
- package/build/src/modules/prompts/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
# opencode-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/alejandro-technology/opencode-mcp/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/alejandro-technology/opencode-mcp/blob/main/vitest.config.ts)
|
|
5
|
+
[](https://www.npmjs.com/package/mcp-server-opencode)
|
|
6
|
+
|
|
7
|
+
An MCP (Model Context Protocol) server that lets any MCP host — Claude Code, Codex, Cursor, etc. — drive an [OpenCode](https://opencode.ai) instance and delegate work to its subagents — so orchestrator models like Opus or Fable can hand off tasks to the other models OpenCode exposes.
|
|
8
|
+
|
|
9
|
+
## Quick install
|
|
10
|
+
|
|
11
|
+
Requires **Node.js 18+** and **[OpenCode](https://opencode.ai)** installed and configured (`opencode` must be on your `PATH`, with at least one provider/model set up) — this server spawns and drives OpenCode instances.
|
|
12
|
+
|
|
13
|
+
For **Claude Code**:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
claude mcp add opencode -- npx -y mcp-server-opencode
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
For **Codex**:
|
|
20
|
+
```bash
|
|
21
|
+
codex mcp add opencode -- npx -y mcp-server-opencode
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
See [Installation](#installation) for manual config, and from-source options.
|
|
25
|
+
|
|
26
|
+
## Tools
|
|
27
|
+
|
|
28
|
+
| Tool | Description |
|
|
29
|
+
| --------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
30
|
+
| `opencode_start_server` | Start (or attach to) an OpenCode server instance |
|
|
31
|
+
| `opencode_stop_server` | Stop a running OpenCode server instance |
|
|
32
|
+
| `opencode_list_agents` | List agents/models available on a server instance |
|
|
33
|
+
| `opencode_start_task` | Delegate a task to an agent by starting a new session and prompt (optional `agent` / `model` override) |
|
|
34
|
+
| `opencode_continue_task` | Send a follow-up prompt to an existing task's session for iterative back-and-forth with the subagent |
|
|
35
|
+
| `opencode_cancel_task` | Abort a running delegated task by cancelling its session |
|
|
36
|
+
| `opencode_get_task_status` | Poll the status of a delegated task (`pending` / `running` / `completed` / `failed`); optional `include_progress` adds a partial output snippet and the currently running tool while it's still running |
|
|
37
|
+
| `opencode_get_task_result` | Fetch the final result of a completed task |
|
|
38
|
+
| `opencode_wait_for_task` | Long-poll one or more delegated tasks until they finish (`mode: "all"` or `"any"`) or the timeout elapses; optional `include_progress` enriches any still-unfinished tasks in the final result with a partial output snippet and the currently running tool |
|
|
39
|
+
|
|
40
|
+
| Prompt | Description |
|
|
41
|
+
| --------------- | ---------------------------------------------------------------------------------------------------- |
|
|
42
|
+
| `delegate_task` | Guides the host through delegating one or more tasks to OpenCode agents (start/wait/result workflow), including a model selection guide that maps each OpenCode model tier to the task difficulty it should handle |
|
|
43
|
+
|
|
44
|
+
## How it works
|
|
4
45
|
|
|
5
46
|
```
|
|
6
47
|
Claude Code
|
|
@@ -15,31 +56,85 @@ OpenCode SDK / CLI
|
|
|
15
56
|
Subagents
|
|
16
57
|
```
|
|
17
58
|
|
|
18
|
-
|
|
59
|
+
Task delegation is **asynchronous**: starting a task returns immediately with a `task_id` instead of blocking until the subagent finishes. This lets Claude Code fire multiple `opencode_start_task` calls in parallel — each one opens an isolated OpenCode `Session` — without hitting MCP client timeouts on long-running work. Status and results are fetched separately via polling.
|
|
19
60
|
|
|
20
|
-
|
|
61
|
+
## Installation
|
|
21
62
|
|
|
22
|
-
|
|
63
|
+
### Prerequisites
|
|
23
64
|
|
|
24
|
-
|
|
65
|
+
- **Node.js 18+**
|
|
66
|
+
- **[OpenCode](https://opencode.ai)** installed and configured (`opencode` must be on your `PATH`, with at least one provider/model set up) — this server spawns and drives OpenCode instances.
|
|
25
67
|
|
|
26
|
-
|
|
68
|
+
### Option 1 — npm (recommended)
|
|
27
69
|
|
|
28
|
-
|
|
29
|
-
| --- | --- |
|
|
30
|
-
| `opencode_start_server` | Start (or attach to) an OpenCode server instance |
|
|
31
|
-
| `opencode_stop_server` | Stop a running OpenCode server instance |
|
|
32
|
-
| `opencode_list_agents` | List agents/models available on a server instance |
|
|
33
|
-
| `opencode_start_task` | Delegate a task to an agent by starting a new session and prompt |
|
|
34
|
-
| `opencode_get_task_status` | Poll the status of a delegated task (`pending` / `running` / `completed` / `failed`) |
|
|
35
|
-
| `opencode_get_task_result` | Fetch the final result of a completed task |
|
|
36
|
-
| `opencode_wait_for_task` | Long-poll one or more delegated tasks until they finish (`mode: "all"` or `"any"`) or the timeout elapses |
|
|
70
|
+
The package is published as [`mcp-server-opencode`](https://www.npmjs.com/package/mcp-server-opencode). No cloning or building needed — point your MCP host at `npx`:
|
|
37
71
|
|
|
38
|
-
|
|
72
|
+
For **Claude Code**, one command does it:
|
|
39
73
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
74
|
+
```bash
|
|
75
|
+
claude mcp add opencode -- npx -y mcp-server-opencode
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Or manually
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"mcpServers": {
|
|
83
|
+
"opencode": {
|
|
84
|
+
"command": "npx",
|
|
85
|
+
"args": ["-y", "mcp-server-opencode"]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
For **Codex**, add the server to `~/.codex/config.toml`:
|
|
92
|
+
|
|
93
|
+
```toml
|
|
94
|
+
[mcp_servers.opencode]
|
|
95
|
+
command = "npx"
|
|
96
|
+
args = ["-y", "mcp-server-opencode"]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Or install it globally and use the binary directly:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm install -g mcp-server-opencode
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"mcpServers": {
|
|
108
|
+
"opencode": {
|
|
109
|
+
"command": "opencode-mcp"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Option 2 — from source
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
git clone https://github.com/alejandro-technology/opencode-mcp.git
|
|
119
|
+
cd opencode-mcp
|
|
120
|
+
pnpm install
|
|
121
|
+
pnpm build
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Then point your MCP host at the built entrypoint:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"mcpServers": {
|
|
129
|
+
"opencode": {
|
|
130
|
+
"command": "node",
|
|
131
|
+
"args": ["/path/to/opencode-mcp/build/src/index.js"]
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Restart your MCP host after editing the config; the `opencode_*` tools should appear in its tool list.
|
|
43
138
|
|
|
44
139
|
## Configuration
|
|
45
140
|
|
|
@@ -70,7 +165,10 @@ Task delegation is **asynchronous**: starting a task returns immediately with a
|
|
|
70
165
|
"mcpServers": {
|
|
71
166
|
"opencode": {
|
|
72
167
|
"command": "node",
|
|
73
|
-
"args": [
|
|
168
|
+
"args": [
|
|
169
|
+
"/path/to/opencode-mcp/build/src/index.js",
|
|
170
|
+
"MCP_TOOL_TIMEOUT=1200000"
|
|
171
|
+
]
|
|
74
172
|
}
|
|
75
173
|
}
|
|
76
174
|
}
|
|
@@ -78,9 +176,9 @@ Task delegation is **asynchronous**: starting a task returns immediately with a
|
|
|
78
176
|
|
|
79
177
|
If both are present, the **environment variable takes precedence** over the CLI argument. Invalid or non-numeric values fall back to the 300000 ms default.
|
|
80
178
|
|
|
81
|
-
|
|
179
|
+
## Development
|
|
82
180
|
|
|
83
|
-
|
|
181
|
+
### Project structure
|
|
84
182
|
|
|
85
183
|
```
|
|
86
184
|
src/
|
|
@@ -96,9 +194,9 @@ src/
|
|
|
96
194
|
└── mcp-result.ts # jsonResult / jsonError MCP output helpers
|
|
97
195
|
```
|
|
98
196
|
|
|
99
|
-
Each module ships with a
|
|
197
|
+
Each module ships with a `*.test.ts` Vitest suite under the parallel `tests/` tree mirroring `src/`.
|
|
100
198
|
|
|
101
|
-
|
|
199
|
+
### Getting started
|
|
102
200
|
|
|
103
201
|
```bash
|
|
104
202
|
pnpm install
|
|
@@ -114,16 +212,3 @@ pnpm lint # biome check
|
|
|
114
212
|
pnpm lint:write # biome check --write
|
|
115
213
|
pnpm build # clean tsc build to ./build (also the typecheck)
|
|
116
214
|
```
|
|
117
|
-
|
|
118
|
-
To use it from an MCP host, build and point the host at the executable entrypoint:
|
|
119
|
-
|
|
120
|
-
```json
|
|
121
|
-
{
|
|
122
|
-
"mcpServers": {
|
|
123
|
-
"opencode": {
|
|
124
|
-
"command": "node",
|
|
125
|
-
"args": ["/path/to/opencode-mcp/build/src/index.js"]
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
```
|
package/build/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
-
import {
|
|
4
|
+
import { registerResources } from "./modules/resources/index.js";
|
|
5
5
|
import { killAllServers } from "./modules/shared/server-registry.js";
|
|
6
6
|
import { registerTools } from "./modules/tools/index.js";
|
|
7
7
|
// Create server instance
|
|
@@ -22,8 +22,8 @@ process.on("SIGTERM", shutdown);
|
|
|
22
22
|
// Safety net for any other exit path (uncaught exception, process.exit elsewhere).
|
|
23
23
|
process.on("exit", killAllServers);
|
|
24
24
|
async function main() {
|
|
25
|
+
registerResources(server);
|
|
25
26
|
registerTools(server);
|
|
26
|
-
registerPrompts(server);
|
|
27
27
|
const transport = new StdioServerTransport();
|
|
28
28
|
await server.connect(transport);
|
|
29
29
|
console.error("OpenCode MCP Server running on stdio");
|
package/build/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,yBAAyB;AACzB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAC3B,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,OAAO;CACjB,CAAC,CAAC;AAEH,SAAS,QAAQ,CAAC,MAAsB;IACtC,OAAO,CAAC,KAAK,CAAC,YAAY,MAAM,wCAAwC,CAAC,CAAC;IAC1E,cAAc,EAAE,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,yEAAyE;AACzE,kEAAkE;AAClE,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC/B,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAChC,mFAAmF;AACnF,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAEnC,KAAK,UAAU,IAAI;IACjB,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC1B,aAAa,CAAC,MAAM,CAAC,CAAC;IACtB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;AACxD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;IAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegate-task-instructions.d.ts","sourceRoot":"","sources":["../../../../src/modules/resources/delegate-task-instructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAwCzE,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,SAAS,QAoB7D"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const DELEGATE_TASK_INSTRUCTIONS = `You have access to the opencode-mcp server, which lets you delegate work to OpenCode agents. Follow this workflow whenever you delegate tasks:
|
|
2
|
+
|
|
3
|
+
Model selection guide — pick the model per task via the optional "model" input of opencode_start_task ('providerID/modelID'). Match the model tier to the task's difficulty; do not burn a scarce frontier model on work a cheap model handles well. Usage quotas (requests per 5h) are noted as a scarcity signal — lower quota means reserve it for harder work.
|
|
4
|
+
|
|
5
|
+
Frontier tier (scarce — architecture, hard debugging, critical decisions):
|
|
6
|
+
- Grok 4.5 (~80 req/5h): top-end reasoning and coding; reserve for the hardest problems, cross-cutting refactors, and tasks where a wrong answer is expensive.
|
|
7
|
+
- Kimi K3 (~140 req/5h): frontier reasoning with very strong agentic stability and tool calling over long sessions; best for long-horizon multi-step tasks that must not derail.
|
|
8
|
+
|
|
9
|
+
High tier (strong daily drivers — feature implementation, non-trivial debugging, review):
|
|
10
|
+
- GLM-5.2 (~880 req/5h): open-weight leader on coding and agentic-coding benchmarks (SWE-bench Pro ~62%); best default for substantial implementation and refactoring work.
|
|
11
|
+
- Qwen3.7 Max (~950 req/5h): near-tie with GLM-5.2 on real-world software engineering; strong multilingual and long-context work.
|
|
12
|
+
- Kimi K2.7 Code (~1,150 req/5h): coding-specialized; ~30% fewer thinking tokens, excellent precise tool invocation (MCP-heavy pipelines) and 4,000+ tool-call sequences; best for long agentic coding runs.
|
|
13
|
+
|
|
14
|
+
Mid tier (high volume — standard features, tests, medium complexity):
|
|
15
|
+
- MiniMax M3 (~3,200 req/5h): frontier-adjacent coding plus 1M context and native multimodality; best for large-codebase context ingestion or tasks involving images/video.
|
|
16
|
+
- MiMo-V2.5-Pro (~3,250 req/5h): strong general agentic capability and complex software engineering (high SWE-bench Pro rankings); good GLM alternative at higher volume.
|
|
17
|
+
- DeepSeek V4 Pro (~3,450 req/5h): solid all-round flagship; good balance of capability and quota for everyday implementation tasks.
|
|
18
|
+
- Qwen3.7 Plus (~4,300 req/5h): capable mid-range generalist; good for standard features and tests at volume.
|
|
19
|
+
|
|
20
|
+
Fast tier (near-unlimited — mechanical work, boilerplate, formatting, simple fixes, docs, exploration):
|
|
21
|
+
- MiMo-V2.5 (~30,100 req/5h): lightweight reasoning model; better than Flash on agentic tasks, at some latency/token cost.
|
|
22
|
+
- DeepSeek V4 Flash (~31,650 req/5h): cheapest and fastest, non-reasoning; best for mechanical edits, boilerplate, renames, doc updates, and quick lookups where latency matters.
|
|
23
|
+
|
|
24
|
+
Rule of thumb: exploration/mechanical → Fast tier; standard implementation → Mid tier; complex features and long agentic runs → High tier; architecture or hardest debugging → Frontier tier.
|
|
25
|
+
|
|
26
|
+
Workflow:
|
|
27
|
+
1. Ensure an OpenCode server is running. If you don't already have a server_id from a previous opencode_start_server call, call opencode_start_server first.
|
|
28
|
+
2. Call opencode_list_agents with the server_id to discover the available agents (native and custom) and models. Agents may have a pre-assigned model ("provider/model"); you can still override it per task.
|
|
29
|
+
3. For each task, call opencode_start_task with the server_id and the task's prompt. Optionally pass an agent name and/or a model override. Collect the returned task_id for every call.
|
|
30
|
+
4. Wait for completion with opencode_wait_for_task:
|
|
31
|
+
- Single task: mode "all" with the single task_id.
|
|
32
|
+
- Multiple tasks, incremental results: call it repeatedly with mode "any", removing completed task_ids each time.
|
|
33
|
+
- Multiple tasks, all at once: call it once with mode "all" and every task_id.
|
|
34
|
+
5. Once a task is reported finished, call opencode_get_task_result for that task_id to retrieve its output.
|
|
35
|
+
6. Use opencode_get_task_status only for quick, non-blocking checks on a task's progress (e.g. to report status to the user) — it does not replace opencode_wait_for_task or opencode_get_task_result.
|
|
36
|
+
|
|
37
|
+
Do not call opencode_get_task_result before the task has finished, and prefer opencode_wait_for_task over polling opencode_get_task_status in a loop.`;
|
|
38
|
+
export function registerDelegateTaskResource(server) {
|
|
39
|
+
server.registerResource("delegate-task-instructions", "opencode://instructions/delegate-task", {
|
|
40
|
+
title: "Delegate task to OpenCode",
|
|
41
|
+
description: "Instructions for the correct workflow to delegate tasks to OpenCode agents via this MCP server",
|
|
42
|
+
mimeType: "text/plain",
|
|
43
|
+
}, () => ({
|
|
44
|
+
contents: [
|
|
45
|
+
{
|
|
46
|
+
uri: "opencode://instructions/delegate-task",
|
|
47
|
+
text: DELEGATE_TASK_INSTRUCTIONS,
|
|
48
|
+
mimeType: "text/plain",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=delegate-task-instructions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegate-task-instructions.js","sourceRoot":"","sources":["../../../../src/modules/resources/delegate-task-instructions.ts"],"names":[],"mappings":"AAEA,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sJAoCmH,CAAC;AAEvJ,MAAM,UAAU,4BAA4B,CAAC,MAAiB;IAC5D,MAAM,CAAC,gBAAgB,CACrB,4BAA4B,EAC5B,uCAAuC,EACvC;QACE,KAAK,EAAE,2BAA2B;QAClC,WAAW,EACT,gGAAgG;QAClG,QAAQ,EAAE,YAAY;KACvB,EACD,GAAG,EAAE,CAAC,CAAC;QACL,QAAQ,EAAE;YACR;gBACE,GAAG,EAAE,uCAAuC;gBAC5C,IAAI,EAAE,0BAA0B;gBAChC,QAAQ,EAAE,YAAY;aACvB;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/resources/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,QAElD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/resources/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAE/E,MAAM,UAAU,iBAAiB,CAAC,MAAiB;IACjD,4BAA4B,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -13,15 +13,31 @@ export interface AssistantEntry {
|
|
|
13
13
|
/** Fetch the most recent assistant message (with its parts) for a session. */
|
|
14
14
|
export declare function lastAssistantEntry(client: OpencodeClient, sessionId: string): Promise<AssistantEntry | undefined>;
|
|
15
15
|
export type TaskStatus = "pending" | "running" | "completed" | "failed";
|
|
16
|
+
export interface TaskProgress {
|
|
17
|
+
/** Last ~500 chars of concatenated TextPart text from the last assistant message. */
|
|
18
|
+
text_snippet: string;
|
|
19
|
+
/** Count of ToolPart parts whose state.status is "completed". */
|
|
20
|
+
tool_calls_completed: number;
|
|
21
|
+
/** Tool name of the last ToolPart whose state.status is "running" or "pending". */
|
|
22
|
+
current_tool?: string;
|
|
23
|
+
/** state.status of that tool part. */
|
|
24
|
+
current_tool_status?: string;
|
|
25
|
+
}
|
|
16
26
|
export interface TaskStatusResult {
|
|
17
27
|
task_id: string;
|
|
18
28
|
status: TaskStatus;
|
|
19
29
|
error?: string;
|
|
30
|
+
progress?: TaskProgress;
|
|
31
|
+
}
|
|
32
|
+
/** Build a TaskProgress summary from a message's parts. */
|
|
33
|
+
export declare function buildProgress(parts: Part[]): TaskProgress;
|
|
34
|
+
export interface DeriveTaskStatusOptions {
|
|
35
|
+
includeProgress?: boolean;
|
|
20
36
|
}
|
|
21
37
|
/**
|
|
22
38
|
* Derive the current status of a task by inspecting session busy state and
|
|
23
39
|
* the last assistant message. Shared by opencode_get_task_status and
|
|
24
40
|
* opencode_wait_for_task so both use identical status derivation.
|
|
25
41
|
*/
|
|
26
|
-
export declare function deriveTaskStatus(client: OpencodeClient, sessionId: string, taskId: string): Promise<TaskStatusResult>;
|
|
42
|
+
export declare function deriveTaskStatus(client: OpencodeClient, sessionId: string, taskId: string, options?: DeriveTaskStatusOptions): Promise<TaskStatusResult>;
|
|
27
43
|
//# sourceMappingURL=opencode-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opencode-client.d.ts","sourceRoot":"","sources":["../../../../src/modules/shared/opencode-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,cAAc,EACnB,KAAK,IAAI,EACV,MAAM,kBAAkB,CAAC;AAI1B,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAI5E;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,GACb;IAAE,MAAM,EAAE,cAAc,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAM3D;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,8EAA8E;AAC9E,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAUrC;AAED,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"opencode-client.d.ts","sourceRoot":"","sources":["../../../../src/modules/shared/opencode-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,cAAc,EACnB,KAAK,IAAI,EACV,MAAM,kBAAkB,CAAC;AAI1B,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAI5E;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,GACb;IAAE,MAAM,EAAE,cAAc,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAM3D;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,8EAA8E;AAC9E,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAUrC;AAED,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAExE,MAAM,WAAW,YAAY;IAC3B,qFAAqF;IACrF,YAAY,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mFAAmF;IACnF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAID,2DAA2D;AAC3D,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,YAAY,CA2BzD;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,gBAAgB,CAAC,CAkC3B"}
|
|
@@ -30,16 +30,54 @@ export async function lastAssistantEntry(client, sessionId) {
|
|
|
30
30
|
}
|
|
31
31
|
return undefined;
|
|
32
32
|
}
|
|
33
|
+
const TEXT_SNIPPET_MAX_LENGTH = 500;
|
|
34
|
+
/** Build a TaskProgress summary from a message's parts. */
|
|
35
|
+
export function buildProgress(parts) {
|
|
36
|
+
let text = "";
|
|
37
|
+
let toolCallsCompleted = 0;
|
|
38
|
+
let currentTool;
|
|
39
|
+
let currentToolStatus;
|
|
40
|
+
for (const part of parts) {
|
|
41
|
+
if (part.type === "text") {
|
|
42
|
+
text += part.text;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (part.type === "tool") {
|
|
46
|
+
if (part.state.status === "completed") {
|
|
47
|
+
toolCallsCompleted++;
|
|
48
|
+
}
|
|
49
|
+
else if (part.state.status === "running" || part.state.status === "pending") {
|
|
50
|
+
currentTool = part.tool;
|
|
51
|
+
currentToolStatus = part.state.status;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
text_snippet: text.slice(-TEXT_SNIPPET_MAX_LENGTH),
|
|
57
|
+
tool_calls_completed: toolCallsCompleted,
|
|
58
|
+
current_tool: currentTool,
|
|
59
|
+
current_tool_status: currentToolStatus,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
33
62
|
/**
|
|
34
63
|
* Derive the current status of a task by inspecting session busy state and
|
|
35
64
|
* the last assistant message. Shared by opencode_get_task_status and
|
|
36
65
|
* opencode_wait_for_task so both use identical status derivation.
|
|
37
66
|
*/
|
|
38
|
-
export async function deriveTaskStatus(client, sessionId, taskId) {
|
|
67
|
+
export async function deriveTaskStatus(client, sessionId, taskId, options) {
|
|
68
|
+
const includeProgress = options?.includeProgress ?? false;
|
|
39
69
|
// The status map only lists sessions that are actively working.
|
|
40
70
|
const statusRes = await client.session.status();
|
|
41
71
|
const sessionStatus = statusRes.data?.[sessionId];
|
|
42
72
|
if (sessionStatus?.type === "busy" || sessionStatus?.type === "retry") {
|
|
73
|
+
if (includeProgress) {
|
|
74
|
+
const entry = await lastAssistantEntry(client, sessionId);
|
|
75
|
+
return {
|
|
76
|
+
task_id: taskId,
|
|
77
|
+
status: "running",
|
|
78
|
+
progress: entry ? buildProgress(entry.parts) : undefined,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
43
81
|
return { task_id: taskId, status: "running" };
|
|
44
82
|
}
|
|
45
83
|
// Not busy: inspect the last assistant message to tell pending from done.
|
|
@@ -53,6 +91,10 @@ export async function deriveTaskStatus(client, sessionId, taskId) {
|
|
|
53
91
|
if (entry.info.time.completed) {
|
|
54
92
|
return { task_id: taskId, status: "completed" };
|
|
55
93
|
}
|
|
56
|
-
return {
|
|
94
|
+
return {
|
|
95
|
+
task_id: taskId,
|
|
96
|
+
status: "running",
|
|
97
|
+
progress: includeProgress ? buildProgress(entry.parts) : undefined,
|
|
98
|
+
};
|
|
57
99
|
}
|
|
58
100
|
//# sourceMappingURL=opencode-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opencode-client.js","sourceRoot":"","sources":["../../../../src/modules/shared/opencode-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,GAGrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,oFAAoF;AACpF,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,OAAO,oBAAoB,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,aAAa,CAC3B,MAAc;IAEd,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,EA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M,yCAAyC,CAAC;AAKzE,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,SAAS,QAiC3D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { jsonError, jsonResult } from "../shared/mcp-result.js";
|
|
3
|
+
import { clientForTask } from "../shared/opencode-client.js";
|
|
4
|
+
export function registerOpencodeCancelTask(server) {
|
|
5
|
+
server.registerTool("opencode_cancel_task", {
|
|
6
|
+
description: "Cancel a delegated task by aborting its OpenCode session",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
task_id: z.string().describe("Id of the task to cancel"),
|
|
9
|
+
},
|
|
10
|
+
}, async ({ task_id }) => {
|
|
11
|
+
const resolved = clientForTask(task_id);
|
|
12
|
+
if (!resolved) {
|
|
13
|
+
return jsonError({ task_id, status: "task_not_found" });
|
|
14
|
+
}
|
|
15
|
+
const { client, sessionId } = resolved;
|
|
16
|
+
try {
|
|
17
|
+
await client.session.abort({ path: { id: sessionId } });
|
|
18
|
+
return jsonResult({
|
|
19
|
+
task_id,
|
|
20
|
+
session_id: sessionId,
|
|
21
|
+
status: "cancelled",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
return jsonError({
|
|
26
|
+
task_id,
|
|
27
|
+
status: "error",
|
|
28
|
+
message: error instanceof Error ? error.message : String(error),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=cancel_task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancel_task.js","sourceRoot":"","sources":["../../../../src/modules/tools/cancel_task.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,MAAM,UA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7D"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { jsonError, jsonResult } from "../shared/mcp-result.js";
|
|
3
|
+
import { clientForTask } from "../shared/opencode-client.js";
|
|
4
|
+
/** Parse a "providerID/modelID" string into the shape the SDK expects. */
|
|
5
|
+
function parseModel(model) {
|
|
6
|
+
const slash = model.indexOf("/");
|
|
7
|
+
if (slash <= 0 || slash === model.length - 1)
|
|
8
|
+
return undefined;
|
|
9
|
+
return { providerID: model.slice(0, slash), modelID: model.slice(slash + 1) };
|
|
10
|
+
}
|
|
11
|
+
export function registerOpencodeContinueTask(server) {
|
|
12
|
+
server.registerTool("opencode_continue_task", {
|
|
13
|
+
description: "Send a follow-up prompt to an existing delegated task's session",
|
|
14
|
+
inputSchema: {
|
|
15
|
+
task_id: z
|
|
16
|
+
.string()
|
|
17
|
+
.describe("Id of the task whose session should receive the follow-up prompt"),
|
|
18
|
+
prompt: z.string().describe("Follow-up prompt/instructions for the agent"),
|
|
19
|
+
agent: z
|
|
20
|
+
.string()
|
|
21
|
+
.optional()
|
|
22
|
+
.describe("Agent name to delegate to (e.g. 'build', 'plan'). Discover available agents with opencode_list_agents. Omit to use the session's current agent"),
|
|
23
|
+
model: z
|
|
24
|
+
.string()
|
|
25
|
+
.optional()
|
|
26
|
+
.describe("Model override as 'providerID/modelID' (e.g. 'opencode/glm-5.2'). Overrides the agent's pre-assigned model for this follow-up only. Discover available models with opencode_list_agents"),
|
|
27
|
+
},
|
|
28
|
+
}, async ({ task_id, prompt, agent, model }) => {
|
|
29
|
+
const resolved = clientForTask(task_id);
|
|
30
|
+
if (!resolved) {
|
|
31
|
+
return jsonError({ task_id, status: "task_not_found" });
|
|
32
|
+
}
|
|
33
|
+
const { client, sessionId } = resolved;
|
|
34
|
+
let parsedModel;
|
|
35
|
+
if (model !== undefined) {
|
|
36
|
+
parsedModel = parseModel(model);
|
|
37
|
+
if (!parsedModel) {
|
|
38
|
+
return jsonError({
|
|
39
|
+
task_id,
|
|
40
|
+
status: "invalid_model",
|
|
41
|
+
message: "model must be in 'providerID/modelID' format",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
// Fire-and-forget: promptAsync returns as soon as the prompt is accepted,
|
|
47
|
+
// the agent keeps working in the background. Poll with get_task_status.
|
|
48
|
+
await client.session.promptAsync({
|
|
49
|
+
path: { id: sessionId },
|
|
50
|
+
body: {
|
|
51
|
+
parts: [{ type: "text", text: prompt }],
|
|
52
|
+
...(agent ? { agent } : {}),
|
|
53
|
+
...(parsedModel ? { model: parsedModel } : {}),
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return jsonResult({
|
|
57
|
+
task_id,
|
|
58
|
+
session_id: sessionId,
|
|
59
|
+
status: "pending",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return jsonError({
|
|
64
|
+
task_id,
|
|
65
|
+
status: "error",
|
|
66
|
+
message: error instanceof Error ? error.message : String(error),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=continue_task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"continue_task.js","sourceRoot":"","sources":["../../../../src/modules/tools/continue_task.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,0EAA0E;AAC1E,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC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CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,IAAI,CAAC;YACH,0EAA0E;YAC1E,wEAAwE;YACxE,MAAM,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;gBAC/B,IAAI,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE;gBACvB,IAAI,EAAE;oBACJ,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oBACvC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC3B,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC/C;aACF,CAAC,CAAC;YAEH,OAAO,UAAU,CAAC;gBAChB,OAAO;gBACP,UAAU,EAAE,SAAS;gBACrB,MAAM,EAAE,SAAS;aAClB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,SAAS,CAAC;gBACf,OAAO;gBACP,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAChE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get_task_status.d.ts","sourceRoot":"","sources":["../../../../src/modules/tools/get_task_status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"get_task_status.d.ts","sourceRoot":"","sources":["../../../../src/modules/tools/get_task_status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,SAAS,QAoC9D"}
|
|
@@ -6,15 +6,21 @@ export function registerOpencodeGetTaskStatus(server) {
|
|
|
6
6
|
description: "Get the current status of a delegated task",
|
|
7
7
|
inputSchema: {
|
|
8
8
|
task_id: z.string().describe("Id of the task to check"),
|
|
9
|
+
include_progress: z
|
|
10
|
+
.boolean()
|
|
11
|
+
.optional()
|
|
12
|
+
.describe("If true, include a partial output snippet and the currently running tool while the task is still running"),
|
|
9
13
|
},
|
|
10
|
-
}, async ({ task_id }) => {
|
|
14
|
+
}, async ({ task_id, include_progress }) => {
|
|
11
15
|
const resolved = clientForTask(task_id);
|
|
12
16
|
if (!resolved) {
|
|
13
17
|
return jsonError({ task_id, status: "not_found" });
|
|
14
18
|
}
|
|
15
19
|
const { client, sessionId } = resolved;
|
|
16
20
|
try {
|
|
17
|
-
const result = await deriveTaskStatus(client, sessionId, task_id
|
|
21
|
+
const result = await deriveTaskStatus(client, sessionId, task_id, {
|
|
22
|
+
includeProgress: include_progress,
|
|
23
|
+
});
|
|
18
24
|
return jsonResult(result);
|
|
19
25
|
}
|
|
20
26
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get_task_status.js","sourceRoot":"","sources":["../../../../src/modules/tools/get_task_status.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAE/E,MAAM,UAAU,6BAA6B,CAAC,MAAiB;IAC7D,MAAM,CAAC,YAAY,CACjB,0BAA0B,EAC1B;QACE,WAAW,EAAE,4CAA4C;QACzD,WAAW,EAAE;YACX,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,yBAAy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,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAChE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAYzE,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,QAU9C"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// Tools
|
|
2
|
+
import { registerOpencodeCancelTask } from "./cancel_task.js";
|
|
3
|
+
import { registerOpencodeContinueTask } from "./continue_task.js";
|
|
2
4
|
import { registerOpencodeGetTaskResult } from "./get_task_result.js";
|
|
3
5
|
import { registerOpencodeGetTaskStatus } from "./get_task_status.js";
|
|
4
6
|
import { registerOpencodeListAgents } from "./list_agents.js";
|
|
@@ -14,5 +16,7 @@ export function registerTools(server) {
|
|
|
14
16
|
registerOpencodeGetTaskStatus(server);
|
|
15
17
|
registerOpencodeGetTaskResult(server);
|
|
16
18
|
registerOpencodeWaitForTask(server);
|
|
19
|
+
registerOpencodeContinueTask(server);
|
|
20
|
+
registerOpencodeCancelTask(server);
|
|
17
21
|
}
|
|
18
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/tools/index.ts"],"names":[],"mappings":"AACA,QAAQ;AACR,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO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CAAC,MAAM,CAAC,CAAC;IACnC,0BAA0B,CAAC,MAAM,CAAC,CAAC;IACnC,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAClC,6BAA6B,CAAC,MAAM,CAAC,CAAC;IACtC,6BAA6B,CAAC,MAAM,CAAC,CAAC;IACtC,2BAA2B,CAAC,MAAM,CAAC,CAAC;IACpC,4BAA4B,CAAC,MAAM,CAAC,CAAC;IACrC,0BAA0B,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start_task.d.ts","sourceRoot":"","sources":["../../../../src/modules/tools/start_task.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAazE,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"start_task.d.ts","sourceRoot":"","sources":["../../../../src/modules/tools/start_task.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAazE,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,QA6E1D"}
|
|
@@ -16,11 +16,14 @@ export function registerOpencodeStartTask(server) {
|
|
|
16
16
|
inputSchema: {
|
|
17
17
|
server_id: z.string().describe("Id of the server instance to run the task on"),
|
|
18
18
|
prompt: z.string().describe("Prompt/instructions for the agent"),
|
|
19
|
-
agent: z
|
|
19
|
+
agent: z
|
|
20
|
+
.string()
|
|
21
|
+
.optional()
|
|
22
|
+
.describe("Agent name to delegate to (e.g. 'build', 'plan'). Discover available agents with opencode_list_agents. Omit to use the server's default agent"),
|
|
20
23
|
model: z
|
|
21
24
|
.string()
|
|
22
25
|
.optional()
|
|
23
|
-
.describe("Model as 'providerID/modelID' (e.g. '
|
|
26
|
+
.describe("Model override as 'providerID/modelID' (e.g. 'opencode/glm-5.2'). Overrides the agent's pre-assigned model for this task only. Discover available models with opencode_list_agents; see the delegate_task prompt for guidance on matching model tier to task difficulty"),
|
|
24
27
|
},
|
|
25
28
|
}, async ({ server_id, prompt, agent, model }) => {
|
|
26
29
|
const client = clientForServer(server_id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start_task.js","sourceRoot":"","sources":["../../../../src/modules/tools/start_task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,0EAA0E;AAC1E,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAC/D,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,MAAiB;IACzD,MAAM,CAAC,YAAY,CACjB,qBAAqB,EACrB;QACE,WAAW,EACT,8GAA8G;QAChH,WAAW,EAAE;YACX,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8CAA8C,CAAC;YAC9E,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;YAChE,KAAK,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"start_task.js","sourceRoot":"","sources":["../../../../src/modules/tools/start_task.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,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC/C;aACF,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;YAC5B,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;YAEzD,OAAO,UAAU,CAAC;gBAChB,OAAO,EAAE,MAAM;gBACf,SAAS;gBACT,UAAU,EAAE,SAAS;gBACrB,MAAM,EAAE,SAAS;aAClB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,SAAS,CAAC;gBACf,SAAS;gBACT,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAChE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait_for_task.d.ts","sourceRoot":"","sources":["../../../../src/modules/tools/wait_for_task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"wait_for_task.d.ts","sourceRoot":"","sources":["../../../../src/modules/tools/wait_for_task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAwDzE,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,SAAS,QAuG5D"}
|
|
@@ -12,9 +12,33 @@ function isFinished(result) {
|
|
|
12
12
|
function sleep(ms) {
|
|
13
13
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Re-derive status with progress for every task that is not yet finished.
|
|
17
|
+
* Only called once, right before returning a final result, never inside the
|
|
18
|
+
* poll loop. Failures are swallowed per-task so one bad re-derivation doesn't
|
|
19
|
+
* fail the whole call.
|
|
20
|
+
*/
|
|
21
|
+
async function enrichUnfinishedWithProgress(tasks, taskData) {
|
|
22
|
+
const clientByTaskId = new Map(taskData.map((entry) => [entry.task_id, entry.client]));
|
|
23
|
+
return Promise.all(tasks.map(async (task) => {
|
|
24
|
+
if (isFinished(task))
|
|
25
|
+
return task;
|
|
26
|
+
// Every task_id in `tasks` was resolved into taskData before polling started.
|
|
27
|
+
// biome-ignore lint/style/noNonNullAssertion: guaranteed present, see comment above
|
|
28
|
+
const client = clientByTaskId.get(task.task_id);
|
|
29
|
+
try {
|
|
30
|
+
return await deriveTaskStatus(client.client, client.sessionId, task.task_id, {
|
|
31
|
+
includeProgress: true,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return task;
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
15
39
|
export function registerOpencodeWaitForTask(server) {
|
|
16
40
|
server.registerTool("opencode_wait_for_task", {
|
|
17
|
-
description: "Long-poll one or more delegated tasks until they finish or the timeout elapses. Use mode 'all' to wait for all tasks, or 'any' to return as soon as one completes.",
|
|
41
|
+
description: "Long-poll one or more delegated tasks until they finish or the timeout elapses. Use mode 'all' to wait for all tasks, or 'any' to return as soon as one completes. Set include_progress to enrich still-running tasks in the final result with a partial output snippet and the currently running tool.",
|
|
18
42
|
inputSchema: {
|
|
19
43
|
task_ids: z.string().array().min(1).describe("IDs of tasks to wait for"),
|
|
20
44
|
mode: z
|
|
@@ -29,8 +53,12 @@ export function registerOpencodeWaitForTask(server) {
|
|
|
29
53
|
.number()
|
|
30
54
|
.optional()
|
|
31
55
|
.describe(`Time between status checks in milliseconds (default ${DEFAULT_POLL_INTERVAL_MS})`),
|
|
56
|
+
include_progress: z
|
|
57
|
+
.boolean()
|
|
58
|
+
.optional()
|
|
59
|
+
.describe("If true, enrich tasks that are still not finished in the returned result with a partial output snippet and the currently running tool (not used during polling, only on the final result)"),
|
|
32
60
|
},
|
|
33
|
-
}, async ({ task_ids, mode = "all", timeout_ms, poll_interval_ms }) => {
|
|
61
|
+
}, async ({ task_ids, mode = "all", timeout_ms, poll_interval_ms, include_progress }) => {
|
|
34
62
|
// Fail-fast: check for unknown task IDs before polling starts
|
|
35
63
|
const unknownIds = [];
|
|
36
64
|
const taskData = [];
|
|
@@ -74,10 +102,16 @@ export function registerOpencodeWaitForTask(server) {
|
|
|
74
102
|
return jsonResult({ mode, tasks, timed_out: false });
|
|
75
103
|
}
|
|
76
104
|
if (mode === "any" && tasks.some(isFinished)) {
|
|
77
|
-
|
|
105
|
+
const enriched = include_progress
|
|
106
|
+
? await enrichUnfinishedWithProgress(tasks, taskData)
|
|
107
|
+
: tasks;
|
|
108
|
+
return jsonResult({ mode, tasks: enriched, timed_out: false });
|
|
78
109
|
}
|
|
79
110
|
if (Date.now() >= deadline) {
|
|
80
|
-
|
|
111
|
+
const enriched = include_progress
|
|
112
|
+
? await enrichUnfinishedWithProgress(tasks, taskData)
|
|
113
|
+
: tasks;
|
|
114
|
+
return jsonResult({ mode, tasks: enriched, timed_out: true });
|
|
81
115
|
}
|
|
82
116
|
await sleep(pollInterval);
|
|
83
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait_for_task.js","sourceRoot":"","sources":["../../../../src/modules/tools/wait_for_task.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,aAAa,EACb,gBAAgB,GAEjB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AACnC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AACvC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAKj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C,MAAM,QAAQ,GAAG,gBAAgB;oBAC/B,CAAC,CAAC,MAAM,4BAA4B,CAAC,KAAK,EAAE,QAAQ,CAAC;oBACrD,CAAC,CAAC,KAAK,CAAC;gBACV,OAAO,UAAU,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;YACjE,CAAC;YAED,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ,EAAE,CAAC;gBAC3B,MAAM,QAAQ,GAAG,gBAAgB;oBAC/B,CAAC,CAAC,MAAM,4BAA4B,CAAC,KAAK,EAAE,QAAQ,CAAC;oBACrD,CAAC,CAAC,KAAK,CAAC;gBACV,OAAO,UAAU,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAChE,CAAC;YAED,MAAM,KAAK,CAAC,YAAY,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
/** Minimal stand-in for McpServer that captures the registered tool/
|
|
2
|
+
/** Minimal stand-in for McpServer that captures the registered tool/resource handlers. */
|
|
3
3
|
export declare function createFakeMcpServer(): {
|
|
4
4
|
server: McpServer;
|
|
5
5
|
registerTool: import("vitest").Mock<(_name: string, _config: unknown, handler: ((...args: any[]) => unknown) | undefined) => void>;
|
|
6
|
-
|
|
6
|
+
registerResource: import("vitest").Mock<(_name: string, _uriOrTemplate: string, _config: unknown, handler: ((...args: any[]) => unknown) | undefined) => void>;
|
|
7
7
|
getHandler: <T extends (...args: any[]) => unknown>() => T;
|
|
8
|
-
|
|
8
|
+
getResourceHandler: <T extends (...args: any[]) => unknown>() => T;
|
|
9
9
|
};
|
|
10
10
|
//# sourceMappingURL=fake-mcp-server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-mcp-server.d.ts","sourceRoot":"","sources":["../../../src/test-utils/fake-mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,
|
|
1
|
+
{"version":3,"file":"fake-mcp-server.d.ts","sourceRoot":"","sources":["../../../src/test-utils/fake-mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,0FAA0F;AAC1F,wBAAgB,mBAAmB;;gDAGE,MAAM,WAAW,OAAO,sBAD3B,GAAG,EAAE,KAAK,OAAO;oDAStC,MAAM,kBACG,MAAM,WACb,OAAO,sBALoB,GAAG,EAAE,KAAK,OAAO;iBAmB1C,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,OAEtB,CAAC;yBAGR,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,OAEtB,CAAC;EAGxC"}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { vi } from "vitest";
|
|
2
|
-
/** Minimal stand-in for McpServer that captures the registered tool/
|
|
2
|
+
/** Minimal stand-in for McpServer that captures the registered tool/resource handlers. */
|
|
3
3
|
export function createFakeMcpServer() {
|
|
4
4
|
// biome-ignore lint/suspicious/noExplicitAny: handler signature varies per tool
|
|
5
5
|
let capturedHandler;
|
|
6
6
|
const registerTool = vi.fn((_name, _config, handler) => {
|
|
7
7
|
capturedHandler = handler;
|
|
8
8
|
});
|
|
9
|
-
// biome-ignore lint/suspicious/noExplicitAny: handler signature varies per
|
|
10
|
-
let
|
|
11
|
-
const
|
|
12
|
-
|
|
9
|
+
// biome-ignore lint/suspicious/noExplicitAny: handler signature varies per resource
|
|
10
|
+
let capturedResourceHandler;
|
|
11
|
+
const registerResource = vi.fn((_name, _uriOrTemplate, _config, handler) => {
|
|
12
|
+
capturedResourceHandler = handler;
|
|
13
13
|
});
|
|
14
|
-
const server = { registerTool,
|
|
14
|
+
const server = { registerTool, registerResource };
|
|
15
15
|
return {
|
|
16
16
|
server,
|
|
17
17
|
registerTool,
|
|
18
|
-
|
|
18
|
+
registerResource,
|
|
19
19
|
// biome-ignore lint/suspicious/noExplicitAny: input shape varies per tool
|
|
20
20
|
getHandler: () => {
|
|
21
21
|
if (!capturedHandler)
|
|
22
22
|
throw new Error("registerTool was not called");
|
|
23
23
|
return capturedHandler;
|
|
24
24
|
},
|
|
25
|
-
// biome-ignore lint/suspicious/noExplicitAny: input shape varies per
|
|
26
|
-
|
|
27
|
-
if (!
|
|
28
|
-
throw new Error("
|
|
29
|
-
return
|
|
25
|
+
// biome-ignore lint/suspicious/noExplicitAny: input shape varies per resource
|
|
26
|
+
getResourceHandler: () => {
|
|
27
|
+
if (!capturedResourceHandler)
|
|
28
|
+
throw new Error("registerResource was not called");
|
|
29
|
+
return capturedResourceHandler;
|
|
30
30
|
},
|
|
31
31
|
};
|
|
32
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-mcp-server.js","sourceRoot":"","sources":["../../../src/test-utils/fake-mcp-server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,
|
|
1
|
+
{"version":3,"file":"fake-mcp-server.js","sourceRoot":"","sources":["../../../src/test-utils/fake-mcp-server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,0FAA0F;AAC1F,MAAM,UAAU,mBAAmB;IACjC,gFAAgF;IAChF,IAAI,eAA0D,CAAC;IAC/D,MAAM,YAAY,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,KAAa,EAAE,OAAgB,EAAE,OAA+B,EAAE,EAAE;QAC9F,eAAe,GAAG,OAAO,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,oFAAoF;IACpF,IAAI,uBAAkE,CAAC;IACvE,MAAM,gBAAgB,GAAG,EAAE,CAAC,EAAE,CAC5B,CACE,KAAa,EACb,cAAsB,EACtB,OAAgB,EAChB,OAAuC,EACvC,EAAE;QACF,uBAAuB,GAAG,OAAO,CAAC;IACpC,CAAC,CACF,CAAC;IAEF,MAAM,MAAM,GAAG,EAAE,YAAY,EAAE,gBAAgB,EAA0B,CAAC;IAE1E,OAAO;QACL,MAAM;QACN,YAAY;QACZ,gBAAgB;QAChB,0EAA0E;QAC1E,UAAU,EAAE,GAA0C,EAAE;YACtD,IAAI,CAAC,eAAe;gBAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;YACrE,OAAO,eAAoB,CAAC;QAC9B,CAAC;QACD,8EAA8E;QAC9E,kBAAkB,EAAE,GAA0C,EAAE;YAC9D,IAAI,CAAC,uBAAuB;gBAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;YACjF,OAAO,uBAA4B,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-server-opencode",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "MCP server that lets any MCP host (Claude Code, Codex CLI, Cursor, etc.) drive OpenCode and delegate tasks asynchronously to its agents",
|
|
5
5
|
"main": "./build/src/index.js",
|
|
6
6
|
"types": "./build/src/index.d.ts",
|
|
7
|
-
"keywords": [
|
|
7
|
+
"keywords": [
|
|
8
|
+
"mcp",
|
|
9
|
+
"mcp-server",
|
|
10
|
+
"model-context-protocol",
|
|
11
|
+
"opencode",
|
|
12
|
+
"agent",
|
|
13
|
+
"subagent",
|
|
14
|
+
"delegation",
|
|
15
|
+
"async",
|
|
16
|
+
"orchestration",
|
|
17
|
+
"claude-code",
|
|
18
|
+
"codex",
|
|
19
|
+
"ai-agents"
|
|
20
|
+
],
|
|
8
21
|
"author": "alejandro-technology",
|
|
9
22
|
"license": "MIT",
|
|
10
23
|
"repository": {
|
|
@@ -14,7 +27,7 @@
|
|
|
14
27
|
"bugs": {
|
|
15
28
|
"url": "https://github.com/alejandro-technology/opencode-mcp/issues"
|
|
16
29
|
},
|
|
17
|
-
"homepage": "https://
|
|
30
|
+
"homepage": "https://opencode-mcp.alejandrotechnology.com",
|
|
18
31
|
"publishConfig": {
|
|
19
32
|
"access": "public"
|
|
20
33
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegate_task.d.ts","sourceRoot":"","sources":["../../../../src/modules/prompts/delegate_task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAmBzE,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,SAAS,QAoB3D"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const DELEGATE_TASK_INSTRUCTIONS = `You have access to the opencode-mcp server, which lets you delegate work to OpenCode agents. Follow this workflow whenever you delegate tasks:
|
|
2
|
-
|
|
3
|
-
Recommended models: run delegated tasks with Fable 5, Opus 4.8, or GPT 5.6 Sol. When overriding an agent's model via opencode_start_task, prefer one of these.
|
|
4
|
-
|
|
5
|
-
Workflow:
|
|
6
|
-
1. Ensure an OpenCode server is running. If you don't already have a server_id from a previous opencode_start_server call, call opencode_start_server first.
|
|
7
|
-
2. Call opencode_list_agents with the server_id to discover the available agents (native and custom) and models. Agents may have a pre-assigned model ("provider/model"); you can still override it per task.
|
|
8
|
-
3. For each task, call opencode_start_task with the server_id and the task's prompt. Optionally pass an agent name and/or a model override. Collect the returned task_id for every call.
|
|
9
|
-
4. Wait for completion with opencode_wait_for_task:
|
|
10
|
-
- Single task: mode "all" with the single task_id.
|
|
11
|
-
- Multiple tasks, incremental results: call it repeatedly with mode "any", removing completed task_ids each time.
|
|
12
|
-
- Multiple tasks, all at once: call it once with mode "all" and every task_id.
|
|
13
|
-
5. Once a task is reported finished, call opencode_get_task_result for that task_id to retrieve its output.
|
|
14
|
-
6. Use opencode_get_task_status only for quick, non-blocking checks on a task's progress (e.g. to report status to the user) — it does not replace opencode_wait_for_task or opencode_get_task_result.
|
|
15
|
-
|
|
16
|
-
Do not call opencode_get_task_result before the task has finished, and prefer opencode_wait_for_task over polling opencode_get_task_status in a loop.`;
|
|
17
|
-
export function registerDelegateTaskPrompt(server) {
|
|
18
|
-
server.registerPrompt("delegate_task", {
|
|
19
|
-
title: "Delegate task to OpenCode",
|
|
20
|
-
description: "Instructions for the correct workflow to delegate tasks to OpenCode agents via this MCP server",
|
|
21
|
-
}, () => ({
|
|
22
|
-
messages: [
|
|
23
|
-
{
|
|
24
|
-
role: "user",
|
|
25
|
-
content: {
|
|
26
|
-
type: "text",
|
|
27
|
-
text: DELEGATE_TASK_INSTRUCTIONS,
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=delegate_task.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegate_task.js","sourceRoot":"","sources":["../../../../src/modules/prompts/delegate_task.ts"],"names":[],"mappings":"AAEA,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;;sJAemH,CAAC;AAEvJ,MAAM,UAAU,0BAA0B,CAAC,MAAiB;IAC1D,MAAM,CAAC,cAAc,CACnB,eAAe,EACf;QACE,KAAK,EAAE,2BAA2B;QAClC,WAAW,EACT,gGAAgG;KACnG,EACD,GAAG,EAAE,CAAC,CAAC;QACL,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE;oBACP,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,0BAA0B;iBACjC;aACF;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/prompts/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,QAEhD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/prompts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhE,MAAM,UAAU,eAAe,CAAC,MAAiB;IAC/C,0BAA0B,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC"}
|