dsh-control-mcp 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mrbeandev and contributors
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 CHANGED
@@ -1,3 +1,246 @@
1
- # Temporary Holding Version
1
+ # dsh-control-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Control [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (DSH) **itself** from MCP clients and an opt-in HTTP API.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/dsh-control-mcp.svg)](https://www.npmjs.com/package/dsh-control-mcp)
6
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
7
+ [![DSH](https://img.shields.io/badge/DSH-0.2.0--rc.1%20%E2%86%92%20%3C0.3.0-informational.svg)](#supported-dsh-versions)
8
+ [![Check](https://github.com/mrbeandev/dsh-control-mcp/actions/workflows/check.yml/badge.svg)](https://github.com/mrbeandev/dsh-control-mcp/actions/workflows/check.yml)
9
+
10
+ - **Source code:** [github.com/mrbeandev/dsh-control-mcp](https://github.com/mrbeandev/dsh-control-mcp)
11
+ - **npm package:** [npmjs.com/package/dsh-control-mcp](https://www.npmjs.com/package/dsh-control-mcp)
12
+ - **Issues:** [github.com/mrbeandev/dsh-control-mcp/issues](https://github.com/mrbeandev/dsh-control-mcp/issues)
13
+
14
+ Once you switch it on, an MCP client (Claude Code, Claude Desktop, Codex, Cursor, another DSH…) or your own script can list and create sessions, send prompts and read the replies, and manage workspaces, models, plugins, schedules, goals, terminals and settings. It speaks the same Remote API the DSH web GUI uses, so every call gets the same validation and has the same effect as the matching click in the GUI.
15
+
16
+ - **MCP server**: Streamable HTTP at `/dsh-control-mcp/mcp`, plus a bundled stdio bridge (`npx -y dsh-control-mcp`).
17
+ - **HTTP API**: JSON and Server-Sent Events at `/dsh-control-mcp/api/v1`.
18
+ - **Off by default.** Turn each surface on in **Plugins → dsh-control-mcp**; changes apply at once.
19
+ - **Multiple API keys**, one per client, each with its own token, name, MCP/API switches and optional expiry. Disable, rotate or delete any key without touching the others.
20
+ - **Scoped keys** reach only the workspaces and chats you pick, read only or read and prompt. Everything else is invisible to them, in every list and every call (DSH 0.2.1+).
21
+ - **Read-only mode** and **blocked endpoint patterns** limit what clients may do.
22
+
23
+ ## Supported DSH versions
24
+
25
+ **Supported range: DSH `0.2.0-rc.1` up to (not including) `0.3.0`** (`engines.dsh: ">=0.2.0-0 <0.3.0-0"`, prereleases included). Check yours with `dsh --version`.
26
+
27
+ | DSH version | npm tag (at the time of this release) | Status |
28
+ |---|---|---|
29
+ | `0.2.3-alpha.2` | `alpha` | ✅ Tested |
30
+ | `0.2.2-rc.5` | `latest`, `next` | ✅ Tested |
31
+ | `0.2.2-rc.3` | — | ✅ Tested |
32
+ | `0.2.1-rc.5` | — | ✅ Tested |
33
+ | `0.2.0-rc.2` | — | ✅ Tested |
34
+ | other releases from `0.2.0-rc.1` up to `0.3.0` | — | ⚠️ Untested, expected to work |
35
+ | older than `0.2.0-rc.1` (0.1.x) | — | ❌ Not supported |
36
+ | `0.3.0` and newer (prereleases included) | — | ❌ Refused by DSH until tested |
37
+
38
+ "Tested" means the packed tarball was installed into a disposable DSH home for that exact version, and both the headless-Chrome page test and the live MCP/API test passed (see [LOCAL-SETUP.md](./LOCAL-SETUP.md)).
39
+
40
+ What differs between versions:
41
+
42
+ | Feature | 0.2.0 | 0.2.1 | 0.2.2+ |
43
+ |---|---|---|---|
44
+ | All endpoints, `dsh_call`, `dsh_stream`, HTTP API | ✅ | ✅ | ✅ |
45
+ | `dsh_send_prompt` with `wait` | ✅ polls `session/list` | ✅ polls `session/list` | ✅ native `session/wait` |
46
+ | Calls run as a dedicated peer that never answers approvals | — (runs as the operator) | ✅ | ✅ |
47
+ | Long detail page under Plugins | README only | README only | ✅ |
48
+ | Full-access API keys | ✅ | ✅ | ✅ |
49
+ | Scoped API keys (chosen workspaces and chats) | ❌ refused | ✅ | ✅ |
50
+
51
+ Each harness version exposes its own set of endpoints; `dsh_list_endpoints` always shows what *your* DSH offers.
52
+
53
+ **Node.js:** `^22.19.0` or `>=24.0.0`. The plugin has no runtime dependencies and needs no other community plugin.
54
+
55
+ ## Install
56
+
57
+ ```sh
58
+ dsh plugin --profile web add dsh-control-mcp
59
+ ```
60
+
61
+ Or open **Plugins → Add plugin** in the GUI and enter `dsh-control-mcp`. Restart DSH if the plugin page does not appear.
62
+
63
+ See [Supported DSH versions](#supported-dsh-versions).
64
+
65
+ ## API keys and scopes
66
+
67
+ Open **Plugins → dsh-control-mcp → API keys → New key**. Each key has:
68
+
69
+ | Setting | Choices |
70
+ |---|---|
71
+ | Name | Any label, e.g. "Claude on my phone" |
72
+ | Surfaces | MCP, HTTP API, or both |
73
+ | Access | **Only chosen workspaces and chats**, or **Full access to this harness** |
74
+ | Inside its chats | **Read only** (history, state, replies), or **Read and prompt** (also send messages, stop, rename, start chats in its workspaces) |
75
+ | Workspaces | Each chosen workspace includes its current chats **and chats added to it later** |
76
+ | Chats | Individual chats, from any workspace |
77
+ | Expires | Optional date |
78
+
79
+ The token is shown **once** when you create or rotate a key; the harness stores only its SHA-256 fingerprint. Changes to a key (narrowing its scope, disabling it, expiry) apply to the very next request.
80
+
81
+ ### How scoping is enforced
82
+
83
+ A scoped key does not run as you. It runs as its own principal (`dsh-control-key`), and DSH's own remote-access engine, the one that confines Liveshare viewers, decides every call. Every session and workspace endpoint names the resource it touches, and DSH checks it before the call runs. List and stream endpoints (`session/list`, `session/search`, `session/control`, `workspace/follow`) filter each item, so a scoped key never even learns that other chats exist. The plugin adds a second, earlier check with clear error messages, and it never offers a scoped key a tool it cannot use.
84
+
85
+ What a scoped key can reach:
86
+
87
+ | | Read only | Read and prompt |
88
+ |---|---|---|
89
+ | Model and provider catalogs, agent presets | ✅ | ✅ |
90
+ | Its chats: list, history, state, wait, follow, goals, commands, skills, terminal list | ✅ | ✅ |
91
+ | Its chats: send prompts, steer, stop, rename, choose model, edit queue, upload attachments | — | ✅ |
92
+ | Start new chats inside its workspaces | — | ✅ |
93
+ | Other chats and workspaces | ❌ invisible | ❌ invisible |
94
+ | Plugins, settings, credentials, accounts, schedules, jobs, terminals (create), workspace create/delete | ❌ | ❌ |
95
+
96
+ Use a full-access key for harness-wide administration. On DSH 0.2.0, which has no remote-access engine, scoped keys are refused with a clear error and full-access keys keep working.
97
+
98
+ ### Owner token
99
+
100
+ The plugin page also shows a built-in **owner token** with full access, the token from version 0.1. It keeps working; prefer named keys so you can scope and revoke each client.
101
+
102
+ ## Turn it on
103
+
104
+ 1. Open **Plugins → dsh-control-mcp**.
105
+ 2. Switch on **MCP server** and/or **HTTP API**. Changes apply immediately, without a restart.
106
+ 3. Under **Client setup**, copy the configuration for your client.
107
+
108
+ ### MCP over HTTP (Claude Code, Cursor, Codex, any Streamable HTTP client)
109
+
110
+ ```json
111
+ {
112
+ "mcpServers": {
113
+ "dsh-control": {
114
+ "type": "http",
115
+ "url": "http://127.0.0.1:3080/dsh-control-mcp/mcp",
116
+ "headers": { "Authorization": "Bearer <token>" }
117
+ }
118
+ }
119
+ }
120
+ ```
121
+
122
+ Claude Code: `claude mcp add --transport http dsh-control http://127.0.0.1:3080/dsh-control-mcp/mcp --header "Authorization: Bearer <token>"`.
123
+
124
+ ### MCP over stdio (Claude Desktop and other stdio-only clients)
125
+
126
+ ```json
127
+ {
128
+ "mcpServers": {
129
+ "dsh-control": {
130
+ "command": "npx",
131
+ "args": ["-y", "dsh-control-mcp"],
132
+ "env": {
133
+ "DSH_CONTROL_URL": "http://127.0.0.1:3080/dsh-control-mcp/mcp",
134
+ "DSH_CONTROL_TOKEN": "<token>"
135
+ }
136
+ }
137
+ }
138
+ }
139
+ ```
140
+
141
+ The bridge relays newline-delimited JSON-RPC from stdin to the HTTP endpoint. It uses only Node.js built-ins.
142
+
143
+ Use the address of *your* DSH web server; the plugin page fills it in for you.
144
+
145
+ ## MCP tools
146
+
147
+ | Tool | What it does |
148
+ |---|---|
149
+ | `dsh_overview` | Version, control mode, namespaces and endpoint counts. Start here. |
150
+ | `dsh_list_sessions` | Sessions with id, title, directory and running state. |
151
+ | `dsh_create_session` | New session in a directory or workspace, optionally with an agent preset. |
152
+ | `dsh_send_prompt` | Send a message (`queue` or `steer`); with `wait: true`, return the reply. |
153
+ | `dsh_wait_session` | Wait until a session is idle or needs input. |
154
+ | `dsh_read_session` | Latest messages as role/text pairs (or raw page records). |
155
+ | `dsh_cancel_session` | Stop the running turn. |
156
+ | `dsh_list_workspaces` | Workspaces with ids, paths and sessions. |
157
+ | `dsh_list_models` | Every model the harness can route to. |
158
+ | `dsh_list_plugins` | Plugins and their state. |
159
+ | `dsh_list_endpoints` | Every harness endpoint, filterable, optionally with JSON Schemas. |
160
+ | `dsh_describe_endpoint` | One endpoint's argument schema. |
161
+ | `dsh_call` | Call any unary endpoint, e.g. `pluginManager/setPluginEnabled`. |
162
+ | `dsh_stream` | Read a stream endpoint (e.g. `job/list`) for a bounded time. |
163
+
164
+ **One MCP tool per endpoint** on the plugin page also lists every endpoint (150–220 depending on DSH version and plugins) as its own `dsh__<namespace>__<method>` tool. Many clients handle the 14 tools above better.
165
+
166
+ In read-only mode, write tools are hidden and write calls are refused.
167
+
168
+ ## HTTP API
169
+
170
+ Every request needs `Authorization: Bearer <token>`: an API key enabled for the HTTP API, or the owner token. Responses are `{"ok": true, "value": …}` or `{"ok": false, "error": {"code", "message"}}` with a matching HTTP status.
171
+
172
+ | Method and path | Purpose |
173
+ |---|---|
174
+ | `GET /dsh-control-mcp/api/v1/info` | Harness and plugin versions, mode, endpoint count. |
175
+ | `GET /dsh-control-mcp/api/v1/endpoints?namespace=&q=&schemas=1` | Endpoint catalog. |
176
+ | `GET /dsh-control-mcp/api/v1/endpoints/<ns>/<method>` | One endpoint with argument and result schemas. |
177
+ | `POST /dsh-control-mcp/api/v1/call/<ns>/<method>` | Call a unary endpoint. Body: its named arguments. |
178
+ | `POST /dsh-control-mcp/api/v1/stream/<ns>/<method>` | Body `{"args", "maxItems", "timeoutMs"}`. Returns collected items, or a live SSE relay with `Accept: text/event-stream`. |
179
+ | `GET /dsh-control-mcp/api/v1/tools`, `POST …/tools/<name>` | The curated tools above, over HTTP. |
180
+ | `GET /dsh-control-mcp/status` | Unauthenticated: which surfaces are on. No secrets. |
181
+
182
+ ```sh
183
+ TOKEN=…; BASE=http://127.0.0.1:3080/dsh-control-mcp/api/v1
184
+ curl -s -H "Authorization: Bearer $TOKEN" $BASE/info
185
+ curl -s -X POST -H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' \
186
+ -d '{"_request":{}}' $BASE/call/session/list
187
+ curl -s -X POST -H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' \
188
+ -d '{"sessionId":"<id>","text":"Summarize the README","wait":true}' $BASE/tools/dsh_send_prompt
189
+ curl -N -X POST -H "Authorization: Bearer $TOKEN" -H 'accept: text/event-stream' -H 'content-type: application/json' \
190
+ -d '{"args":{}}' $BASE/stream/workspace/follow
191
+ ```
192
+
193
+ Endpoint arguments are named exactly as the harness declares them. Check `GET …/endpoints/<ns>/<method>`. An argument resolved by the `agent` lookup (for example `agentId`) takes a session id.
194
+
195
+ ## Security
196
+
197
+ - **Full control means full control.** A prompt can run tools and shell commands. Anyone with the token, and network access to DSH, can do what you can do in the GUI. Treat the token like a password, rotate it if it leaks, and prefer read-only mode when a client only needs to look.
198
+ - Both surfaces are off until you turn them on, and turning one off takes effect on the next request.
199
+ - Tokens are 256-bit random values. Key tokens are stored only as SHA-256 fingerprints and shown once; the owner token is compared in constant time. Key management and the owner token are served only to your signed-in DSH browser session from the same origin; bearer tokens, even full-access ones, cannot create or list keys.
200
+ - Scoped keys are confined by DSH's remote-access engine, not only by this plugin. They run as their own principal, never as the owner.
201
+ - Requests with a cross-site `Origin` are refused, so a web page you visit cannot use the API even if it guesses the URL.
202
+ - Calls run as a dedicated in-process owner peer that **never answers approvals or questions**; those still appear in the GUI. (`userQuestions/answer` remains callable explicitly.)
203
+ - DSH binds to loopback by default. For remote clients use an SSH tunnel or DSH's own `trustedHosts`/TLS options. Do not expose it publicly without TLS.
204
+ - The Host side makes no outbound network requests.
205
+
206
+ ## How it works
207
+
208
+ The Host plugin (`index.mjs`) registers one prefix route, `/dsh-control-mcp`, on the DSH web server. Requests are dispatched through `ctx.typertGateway.invoke()` and `ctx.typertGateway.stream()` with an owner `Peer` created by `ctx.connection.createPeer()`. Endpoint discovery and argument schemas come from the live Typert registry (`ctx.typert.local.list()`), so endpoints added by other plugins appear automatically.
209
+
210
+ | Identity | Value |
211
+ |---|---|
212
+ | npm package, bundle, Loader entry id/name, Host plugin name | `dsh-control-mcp` |
213
+ | Client module id and `plugins.bundle.config` key | `dsh-control-mcp` |
214
+ | Web route prefix | `/dsh-control-mcp` |
215
+ | Credential records | `dsh-control-mcp/access-token` (owner token), `dsh-control-mcp/api-keys` (key fingerprints and scopes) |
216
+ | Remote-access principal | `dsh-control-key` (scoped keys), roles `dsh-control-mcp:*` |
217
+ | Config fields (all volatile) | `mcpEnabled`, `apiEnabled`, `readOnly`, `exposeAllEndpoints`, `blockedEndpoints`, `maxResultBytes` |
218
+ | Log prefix | `dsh-control-mcp:` |
219
+ | Injected Host services | `typert`, `typertGateway`, `connection`, `webServer`; optional `credentials`, `connection.authentication` (DSH 0.2.3+) |
220
+ | Injected client packages | `@deepseek-ai/dsh-client-ui-settings`, `@deepseek-ai/dsh-client-ui-plugin-manager` |
221
+
222
+ ### Source layout
223
+
224
+ | Path | Role |
225
+ |---|---|
226
+ | `index.mjs` | Host entry: Config, token store, gateway bridge, route registration. |
227
+ | `lib/core.mjs` | Transport-independent catalog, policy, curated tools and MCP JSON-RPC. |
228
+ | `lib/http.mjs` | HTTP routing, auth, MCP Streamable HTTP, REST and SSE, key management routes. |
229
+ | `lib/access.mjs` | API key registry, scoped roles and the remote-access policy. |
230
+ | `client/index.mjs` | Plugin page source (source of truth). |
231
+ | `lib/client.js` | **Generated** by `npm run build` from `client/index.mjs`. Do not edit. |
232
+ | `bin/dsh-control-mcp.mjs` | stdio bridge. |
233
+
234
+ ## Development
235
+
236
+ ```sh
237
+ npm run verify # build client bundle, unit tests, release gate (metadata, identities, packed files)
238
+ npm pack --dry-run
239
+ scripts/version-matrix.sh ./dsh-control-mcp-X.Y.Z.tgz /path/to/dsh/bin [port] # one DSH version: page, live and scope-isolation tests
240
+ ```
241
+
242
+ `LOCAL-SETUP.md` covers testing against a disposable DSH profile, including the live MCP/API smoke test (`npm run test:live`) and the headless-Chrome page test (`npm run test:e2e`).
243
+
244
+ ## License
245
+
246
+ MIT
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * stdio ⇄ HTTP bridge for MCP clients that only launch stdio servers.
4
+ *
5
+ * DSH_CONTROL_URL=http://127.0.0.1:3080/dsh-control-mcp/mcp \
6
+ * DSH_CONTROL_TOKEN=dshc_… npx -y dsh-control-mcp
7
+ *
8
+ * Reads newline-delimited JSON-RPC from stdin, POSTs each message to the
9
+ * harness's MCP endpoint with the bearer token, and writes the responses to
10
+ * stdout. Diagnostics go to stderr only. Node built-ins only.
11
+ */
12
+ import { createInterface } from 'node:readline';
13
+ import { realpathSync } from 'node:fs';
14
+ import { fileURLToPath } from 'node:url';
15
+
16
+ const DEFAULT_URL = 'http://127.0.0.1:3080/dsh-control-mcp/mcp';
17
+
18
+ export function bridgeConfig(env = process.env, argv = process.argv.slice(2)) {
19
+ const flags = {};
20
+ for (let i = 0; i < argv.length; i += 1) {
21
+ const match = /^--(url|token)(?:=(.*))?$/.exec(argv[i]);
22
+ if (match) flags[match[1]] = match[2] ?? argv[++i];
23
+ else if (argv[i] === '--help' || argv[i] === '-h') flags.help = true;
24
+ }
25
+ return { url: flags.url ?? env.DSH_CONTROL_URL ?? DEFAULT_URL, token: flags.token ?? env.DSH_CONTROL_TOKEN ?? '', help: flags.help === true };
26
+ }
27
+
28
+ function errorResponse(id, message) {
29
+ return { jsonrpc: '2.0', id: id ?? null, error: { code: -32603, message } };
30
+ }
31
+
32
+ export async function forward(message, { url, token, fetchImpl = fetch, protocolVersion }) {
33
+ const response = await fetchImpl(url, {
34
+ method: 'POST',
35
+ headers: {
36
+ 'content-type': 'application/json',
37
+ accept: 'application/json, text/event-stream',
38
+ authorization: `Bearer ${token}`,
39
+ ...(protocolVersion ? { 'mcp-protocol-version': protocolVersion } : {}),
40
+ },
41
+ body: JSON.stringify(message),
42
+ });
43
+ if (response.status === 202) return undefined;
44
+ const text = await response.text();
45
+ if (!response.ok) {
46
+ let detail = text.slice(0, 300);
47
+ try { detail = JSON.parse(text)?.error?.message ?? detail; } catch { /* plain text */ }
48
+ const hint = response.status === 401 ? ' (check DSH_CONTROL_TOKEN)' : response.status === 404 ? ' (is MCP mode on in Plugins → dsh-control-mcp?)' : '';
49
+ throw new Error(`harness answered ${response.status}: ${detail}${hint}`);
50
+ }
51
+ return JSON.parse(text);
52
+ }
53
+
54
+ async function main() {
55
+ const config = bridgeConfig();
56
+ if (config.help) {
57
+ process.stderr.write('Usage: dsh-control-mcp [--url <mcp url>] [--token <token>]\nEnvironment: DSH_CONTROL_URL (default ' + DEFAULT_URL + '), DSH_CONTROL_TOKEN.\n');
58
+ return;
59
+ }
60
+ if (!config.token) process.stderr.write('dsh-control-mcp: DSH_CONTROL_TOKEN is not set; requests will be refused. Copy the token from Plugins → dsh-control-mcp.\n');
61
+ let protocolVersion;
62
+ const write = value => { if (value !== undefined) process.stdout.write(`${JSON.stringify(value)}\n`); };
63
+ let pending = 0;
64
+ let closing = false;
65
+ const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
66
+ lines.on('line', async line => {
67
+ if (line.trim() === '') return;
68
+ let message;
69
+ try { message = JSON.parse(line); } catch { write({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } }); return; }
70
+ pending += 1;
71
+ try {
72
+ const response = await forward(message, { ...config, protocolVersion });
73
+ if (response?.result?.protocolVersion) protocolVersion = response.result.protocolVersion;
74
+ write(response);
75
+ } catch (error) {
76
+ process.stderr.write(`dsh-control-mcp: ${error.message}\n`);
77
+ if (message && typeof message === 'object' && !Array.isArray(message) && 'id' in message && typeof message.method === 'string') write(errorResponse(message.id, error.message));
78
+ } finally {
79
+ pending -= 1;
80
+ if (closing && pending === 0) process.exit(0);
81
+ }
82
+ });
83
+ lines.on('close', () => { closing = true; if (pending === 0) process.exit(0); });
84
+ }
85
+
86
+ function isMain() {
87
+ try { return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url)); } catch { return false; }
88
+ }
89
+
90
+ if (isMain()) {
91
+ main().catch(error => { process.stderr.write(`dsh-control-mcp: ${error.message}\n`); process.exit(1); });
92
+ }