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 +21 -0
- package/README.md +245 -2
- package/bin/dsh-control-mcp.mjs +92 -0
- package/client/index.mjs +467 -0
- package/cordis.patch.yml +5 -0
- package/docs/DETAIL.md +43 -0
- package/icon.svg +17 -0
- package/index.mjs +332 -0
- package/lib/access.mjs +324 -0
- package/lib/client.js +460 -0
- package/lib/core.mjs +885 -0
- package/lib/http.mjs +357 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +94 -4
package/client/index.mjs
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained factory: scripts/build-client.mjs embeds it in lib/client.js
|
|
3
|
+
* without bundling another React.
|
|
4
|
+
*
|
|
5
|
+
* Registers this plugin's page in the Plugins view (`plugins.bundle.config`,
|
|
6
|
+
* keyed by the package name): MCP and HTTP API switches, read-only mode,
|
|
7
|
+
* per-endpoint tools, blocked endpoints, the access token (show, copy,
|
|
8
|
+
* rotate) and ready-to-paste client configuration. Settings live in the Host
|
|
9
|
+
* entry's volatile Config, edited through the `configForms` service. The
|
|
10
|
+
* token is read from the Host's owner-only `/dsh-control-mcp/token` route.
|
|
11
|
+
*/
|
|
12
|
+
export function createClientPlugin(require) {
|
|
13
|
+
const React = require('react');
|
|
14
|
+
const { createElement: h, useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } = React;
|
|
15
|
+
const PACKAGE = 'dsh-control-mcp';
|
|
16
|
+
const ENTRY_ID = 'dsh-control-mcp';
|
|
17
|
+
const ROUTE = '/dsh-control-mcp';
|
|
18
|
+
const inject = ['slots'];
|
|
19
|
+
const SAVE_ERROR = 'Could not save this setting. It may have changed elsewhere; review the current value and try again.';
|
|
20
|
+
const SWITCHES = [
|
|
21
|
+
{ field: 'mcpEnabled', label: 'MCP server', hint: 'Serve the MCP endpoint so MCP clients (Claude, Codex, Cursor, another DSH…) can control this harness.' },
|
|
22
|
+
{ field: 'apiEnabled', label: 'HTTP API', hint: 'Serve a JSON and Server-Sent Events API for scripts and other programs.' },
|
|
23
|
+
{ field: 'readOnly', label: 'Read-only mode', hint: 'Allow only calls that read. Prompts, creating sessions, plugin changes and every other change are refused.' },
|
|
24
|
+
{ field: 'exposeAllEndpoints', label: 'One MCP tool per endpoint', hint: 'Also list every harness endpoint as its own MCP tool (about 200). The curated tools and dsh_call already reach all of them.' },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
function isRecord(value) {
|
|
28
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Settings namespace of this plugin's Host entry among the served ones. */
|
|
32
|
+
function findEntryNamespace(namespaces) {
|
|
33
|
+
const ids = (Array.isArray(namespaces) ? namespaces : []).map(view => view?.ns).filter(id => typeof id === 'string');
|
|
34
|
+
return ids.find(id => id === `include:${ENTRY_ID}`)
|
|
35
|
+
?? ids.find(id => id === ENTRY_ID)
|
|
36
|
+
?? ids.find(id => id.endsWith(`:${ENTRY_ID}`));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Parse the blocked-endpoints textarea: one pattern per line or comma. */
|
|
40
|
+
function parseBlocked(text) {
|
|
41
|
+
const items = String(text ?? '').split(/[\n,]/).map(item => item.trim()).filter(Boolean);
|
|
42
|
+
const invalid = items.filter(item => !/^[A-Za-z0-9_*-]+\/[A-Za-z0-9_*-]+$/.test(item));
|
|
43
|
+
return { items: [...new Set(items)], invalid };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function originUrl(path) {
|
|
47
|
+
try {
|
|
48
|
+
return new URL(path, window.location.href).toString();
|
|
49
|
+
} catch {
|
|
50
|
+
return path;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function mcpJsonConfig(url, token) {
|
|
55
|
+
return JSON.stringify({ mcpServers: { 'dsh-control': { type: 'http', url, headers: { Authorization: `Bearer ${token}` } } } }, null, 2);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function stdioConfig(url, token) {
|
|
59
|
+
return JSON.stringify({ mcpServers: { 'dsh-control': { command: 'npx', args: ['-y', 'dsh-control-mcp'], env: { DSH_CONTROL_URL: url, DSH_CONTROL_TOKEN: token } } } }, null, 2);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function tokenRequest(path, method) {
|
|
63
|
+
const response = await fetch(`${ROUTE}${path}`, { method, credentials: 'same-origin', headers: { accept: 'application/json' } });
|
|
64
|
+
const body = await response.json().catch(() => undefined);
|
|
65
|
+
if (!response.ok || body?.ok !== true || typeof body?.value?.token !== 'string') throw new Error('token request failed');
|
|
66
|
+
return body.value.token;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Owner-only management call to this plugin's own same-origin routes. */
|
|
70
|
+
async function manage(path, method = 'GET', body) {
|
|
71
|
+
const response = await fetch(`${ROUTE}${path}`, {
|
|
72
|
+
method, credentials: 'same-origin',
|
|
73
|
+
headers: { accept: 'application/json', ...(body === undefined ? {} : { 'content-type': 'application/json' }) },
|
|
74
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
75
|
+
});
|
|
76
|
+
const json = await response.json().catch(() => undefined);
|
|
77
|
+
if (!response.ok || json?.ok !== true) throw new Error(typeof json?.error?.message === 'string' ? json.error.message : 'The request failed.');
|
|
78
|
+
return json.value;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function scopeSummary(key, options) {
|
|
82
|
+
if (key.mode === 'full') return 'Full access';
|
|
83
|
+
const ws = key.workspaces.map(id => options.workspaces.find(w => w.id === id)?.title ?? 'missing workspace');
|
|
84
|
+
const ss = key.sessions.length;
|
|
85
|
+
const parts = [];
|
|
86
|
+
if (ws.length) parts.push(`${ws.length === 1 ? 'Workspace' : `${ws.length} workspaces`}: ${ws.slice(0, 2).join(', ')}${ws.length > 2 ? '…' : ''}`);
|
|
87
|
+
if (ss) parts.push(`${ss} chat${ss === 1 ? '' : 's'}`);
|
|
88
|
+
return `${key.access === 'prompt' ? 'Read and prompt' : 'Read only'} · ${parts.join(' · ') || 'nothing selected'}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function relativeTime(iso) {
|
|
92
|
+
if (!iso) return 'never';
|
|
93
|
+
const diff = Date.now() - Date.parse(iso);
|
|
94
|
+
if (!Number.isFinite(diff)) return 'never';
|
|
95
|
+
if (diff < 60000) return 'just now';
|
|
96
|
+
if (diff < 3600000) return `${Math.round(diff / 60000)} min ago`;
|
|
97
|
+
if (diff < 86400000) return `${Math.round(diff / 3600000)} h ago`;
|
|
98
|
+
return `${Math.round(diff / 86400000)} d ago`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const styles = {
|
|
102
|
+
page: { display: 'flex', flexDirection: 'column', gap: '16px', minWidth: 0, fontSize: '13px', lineHeight: '20px', color: 'var(--dsw-alias-label-primary)' },
|
|
103
|
+
head: { display: 'flex', flexDirection: 'column', gap: '4px' },
|
|
104
|
+
title: { margin: 0, fontSize: '14px', fontWeight: 500, lineHeight: '20px' },
|
|
105
|
+
lead: { margin: 0, color: 'var(--dsw-alias-label-secondary)' },
|
|
106
|
+
card: { display: 'flex', flexDirection: 'column', borderRadius: 'var(--dsw-radius-md, 8px)', border: '.5px solid var(--dsw-alias-border-l3)', background: 'var(--dsw-alias-bg-layer-1)' },
|
|
107
|
+
row: { display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: '16px', padding: '12px 14px', borderBottom: '.5px solid var(--dsw-alias-border-l2)' },
|
|
108
|
+
rowLast: { borderBottom: 0 },
|
|
109
|
+
rowText: { display: 'flex', flexDirection: 'column', gap: '2px', minWidth: 0 },
|
|
110
|
+
label: { fontSize: '13.5px', fontWeight: 500 },
|
|
111
|
+
hint: { margin: 0, fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-label-tertiary)' },
|
|
112
|
+
section: { display: 'flex', flexDirection: 'column', gap: '8px' },
|
|
113
|
+
sectionTitle: { margin: 0, fontSize: '13px', fontWeight: 500 },
|
|
114
|
+
status: { margin: 0, color: 'var(--dsw-alias-label-tertiary)' },
|
|
115
|
+
error: { margin: 0, color: 'var(--dsw-alias-state-error-primary)', overflowWrap: 'anywhere' },
|
|
116
|
+
ok: { margin: 0, color: 'var(--dsw-alias-state-success-primary, #39a869)' },
|
|
117
|
+
warn: { margin: 0, padding: '8px 12px', borderRadius: 'var(--dsw-radius-md, 8px)', background: 'color-mix(in srgb, var(--dsw-alias-state-warning-primary, #d08a00) 12%, transparent)', color: 'var(--dsw-alias-label-secondary)', fontSize: '12px', lineHeight: '18px' },
|
|
118
|
+
code: { margin: 0, padding: '8px 10px', borderRadius: 'var(--dsw-radius-md, 8px)', background: 'var(--dsw-alias-bg-layer-3)', border: '.5px solid var(--dsw-alias-border-l3)', fontFamily: 'var(--dsw-font-mono, ui-monospace, monospace)', fontSize: '12px', lineHeight: '18px', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' },
|
|
119
|
+
inline: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap' },
|
|
120
|
+
input: { flex: 1, minWidth: '220px', height: '30px', padding: '0 10px', boxSizing: 'border-box', borderRadius: 'var(--dsw-radius-md, 8px)', border: '.5px solid var(--dsw-alias-border-l4)', background: 'var(--dsw-alias-bg-layer-3)', color: 'inherit', font: 'inherit', fontFamily: 'var(--dsw-font-mono, ui-monospace, monospace)', fontSize: '12px' },
|
|
121
|
+
textarea: { width: '100%', minHeight: '64px', padding: '8px 10px', boxSizing: 'border-box', borderRadius: 'var(--dsw-radius-md, 8px)', border: '.5px solid var(--dsw-alias-border-l4)', background: 'var(--dsw-alias-bg-layer-3)', color: 'inherit', font: 'inherit', fontFamily: 'var(--dsw-font-mono, ui-monospace, monospace)', fontSize: '12px', resize: 'vertical' },
|
|
122
|
+
button: { height: '28px', padding: '0 12px', borderRadius: 'var(--dsw-radius-md, 8px)', border: '.5px solid var(--dsw-alias-border-l4)', background: 'var(--dsw-alias-bg-layer-3)', color: 'inherit', font: 'inherit', fontSize: '12.5px', cursor: 'pointer' },
|
|
123
|
+
primary: { background: 'var(--dsw-alias-brand-primary)', borderColor: 'transparent', color: 'var(--dsw-alias-label-on-brand, #fff)' },
|
|
124
|
+
disabled: { opacity: 0.5, cursor: 'not-allowed' },
|
|
125
|
+
tabs: { display: 'flex', gap: '6px', flexWrap: 'wrap' },
|
|
126
|
+
keyRow: { display: 'flex', alignItems: 'center', gap: '12px', padding: '10px 14px', borderBottom: '.5px solid var(--dsw-alias-border-l2)', minWidth: 0 },
|
|
127
|
+
keyMain: { display: 'flex', flexDirection: 'column', gap: '2px', minWidth: 0, flex: 1 },
|
|
128
|
+
badgeMuted: { flex: 'none', padding: '0 8px', borderRadius: '999px', fontSize: '11px', lineHeight: '18px', background: 'var(--dsw-alias-bg-layer-3)', color: 'var(--dsw-alias-label-secondary)', border: '.5px solid var(--dsw-alias-border-l3)' },
|
|
129
|
+
editor: { display: 'flex', flexDirection: 'column', gap: '12px', padding: '14px', borderRadius: 'var(--dsw-radius-md, 8px)', border: '.5px solid var(--dsw-alias-border-l3)', background: 'var(--dsw-alias-bg-layer-1)' },
|
|
130
|
+
fieldRow: { display: 'flex', flexDirection: 'column', gap: '4px' },
|
|
131
|
+
radioRow: { display: 'flex', gap: '16px', flexWrap: 'wrap' },
|
|
132
|
+
pick: { display: 'flex', flexDirection: 'column', maxHeight: '220px', overflow: 'auto', border: '.5px solid var(--dsw-alias-border-l3)', borderRadius: 'var(--dsw-radius-md, 8px)', padding: '4px' },
|
|
133
|
+
pickItem: { display: 'flex', alignItems: 'flex-start', gap: '8px', padding: '5px 8px', borderRadius: '6px', cursor: 'pointer', minWidth: 0 },
|
|
134
|
+
textInput: { height: '30px', padding: '0 10px', boxSizing: 'border-box', borderRadius: 'var(--dsw-radius-md, 8px)', border: '.5px solid var(--dsw-alias-border-l4)', background: 'var(--dsw-alias-bg-layer-3)', color: 'inherit', font: 'inherit', fontSize: '12.5px', width: '100%' },
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
function buttonStyle(primary, disabled) {
|
|
138
|
+
return { ...styles.button, ...primary ? styles.primary : {}, ...disabled ? styles.disabled : {} };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const emptyMirror = { view: undefined };
|
|
142
|
+
const unavailableSnapshot = { status: 'unavailable', value: undefined, revision: undefined, writable: false };
|
|
143
|
+
const noForm = { getSnapshot: () => unavailableSnapshot, subscribe: () => () => {}, mutate: async () => false };
|
|
144
|
+
|
|
145
|
+
function useStore(store, fallback) {
|
|
146
|
+
const subscribe = useCallback(listener => (store ? store.subscribe(listener) : () => {}), [store]);
|
|
147
|
+
const getSnapshot = useCallback(() => (store ? store.getSnapshot() : fallback), [store, fallback]);
|
|
148
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function Switch({ id, checked, disabled, label, onChange }) {
|
|
152
|
+
return h('input', {
|
|
153
|
+
id, type: 'checkbox', role: 'switch', checked, disabled, 'aria-label': label,
|
|
154
|
+
style: { width: '18px', height: '18px', flex: 'none', marginTop: '2px', cursor: disabled ? 'not-allowed' : 'pointer' },
|
|
155
|
+
onChange: event => onChange(event.target.checked),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function CopyButton({ text, label = 'Copy', disabled }) {
|
|
160
|
+
const [copied, setCopied] = useState(false);
|
|
161
|
+
useEffect(() => { if (!copied) return undefined; const timer = setTimeout(() => setCopied(false), 1500); return () => clearTimeout(timer); }, [copied]);
|
|
162
|
+
return h('button', {
|
|
163
|
+
type: 'button', style: buttonStyle(false, disabled), disabled,
|
|
164
|
+
onClick: async () => { try { await navigator.clipboard.writeText(text); setCopied(true); } catch { /* clipboard blocked; text stays selectable */ } },
|
|
165
|
+
}, copied ? 'Copied' : label);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function TokenSection({ enabled }) {
|
|
169
|
+
const [token, setToken] = useState('');
|
|
170
|
+
const [state, setState] = useState('idle');
|
|
171
|
+
const [visible, setVisible] = useState(false);
|
|
172
|
+
const [tab, setTab] = useState('http');
|
|
173
|
+
const mounted = useRef(true);
|
|
174
|
+
useEffect(() => () => { mounted.current = false; }, []);
|
|
175
|
+
|
|
176
|
+
const load = useCallback(async () => {
|
|
177
|
+
setState('loading');
|
|
178
|
+
try {
|
|
179
|
+
const value = await tokenRequest('/token', 'GET');
|
|
180
|
+
if (mounted.current) { setToken(value); setState('ready'); }
|
|
181
|
+
} catch {
|
|
182
|
+
if (mounted.current) setState('error');
|
|
183
|
+
}
|
|
184
|
+
}, []);
|
|
185
|
+
useEffect(() => { if (enabled) void load(); }, [enabled, load]);
|
|
186
|
+
|
|
187
|
+
const rotate = async () => {
|
|
188
|
+
if (!window.confirm('Rotate the access token? Every MCP and API client using the current token stops working until you update it.')) return;
|
|
189
|
+
setState('loading');
|
|
190
|
+
try {
|
|
191
|
+
const value = await tokenRequest('/token/rotate', 'POST');
|
|
192
|
+
if (mounted.current) { setToken(value); setVisible(true); setState('rotated'); }
|
|
193
|
+
} catch {
|
|
194
|
+
if (mounted.current) setState('error');
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
if (!enabled) return h('p', { style: styles.status }, 'Turn on the MCP server or the HTTP API to see the access token and client setup.');
|
|
199
|
+
const mcpUrl = originUrl(`${ROUTE}/mcp`);
|
|
200
|
+
const apiUrl = originUrl(`${ROUTE}/api/v1`);
|
|
201
|
+
const shown = visible ? token : token.replace(/^(dshc_.{4}).*$/, '$1••••••••••••••••••••••');
|
|
202
|
+
const snippetsFor = value => ({
|
|
203
|
+
http: { label: 'MCP over HTTP', text: mcpJsonConfig(mcpUrl, value) },
|
|
204
|
+
stdio: { label: 'MCP over stdio', text: stdioConfig(mcpUrl, value) },
|
|
205
|
+
curl: { label: 'HTTP API', text: `curl -s -H 'Authorization: Bearer ${value}' ${apiUrl}/info\ncurl -s -X POST -H 'Authorization: Bearer ${value}' -H 'content-type: application/json' \\\n -d '{"_request":{}}' ${apiUrl}/call/session/list` },
|
|
206
|
+
});
|
|
207
|
+
// Displayed text follows the Show/Hide state; copying always uses the real token.
|
|
208
|
+
const snippets = snippetsFor(token);
|
|
209
|
+
const displayed = snippetsFor(shown);
|
|
210
|
+
return h('div', { style: styles.section },
|
|
211
|
+
h('h5', { style: styles.sectionTitle }, 'Owner token'),
|
|
212
|
+
h('p', { style: styles.hint }, 'The built-in full-access token, sent as "Authorization: Bearer <token>". It controls the whole harness (or reads it in read-only mode). Prefer a named API key per client above, so you can scope and revoke each one.'),
|
|
213
|
+
state === 'error' ? h('p', { role: 'alert', style: styles.error }, 'Could not read the token. Reload this page from the DSH web GUI you are signed in to.') : null,
|
|
214
|
+
h('div', { style: styles.inline },
|
|
215
|
+
h('input', { readOnly: true, value: state === 'loading' && !token ? 'Loading…' : shown, style: styles.input, 'aria-label': 'Access token', onFocus: event => event.target.select() }),
|
|
216
|
+
h('button', { type: 'button', style: buttonStyle(false, !token), disabled: !token, onClick: () => setVisible(!visible) }, visible ? 'Hide' : 'Show'),
|
|
217
|
+
h(CopyButton, { text: token, disabled: !token }),
|
|
218
|
+
h('button', { type: 'button', style: buttonStyle(false, state === 'loading'), disabled: state === 'loading', onClick: () => { void rotate(); } }, 'Rotate')),
|
|
219
|
+
state === 'rotated' ? h('p', { role: 'status', style: styles.ok }, 'New token issued. The old one no longer works.') : null,
|
|
220
|
+
h('h5', { style: { ...styles.sectionTitle, marginTop: '8px' } }, 'Client setup'),
|
|
221
|
+
h('div', { style: styles.tabs, role: 'tablist' }, Object.entries(snippets).map(([key, snippet]) => h('button', {
|
|
222
|
+
key, type: 'button', role: 'tab', 'aria-selected': tab === key, style: buttonStyle(tab === key, false), onClick: () => setTab(key),
|
|
223
|
+
}, snippet.label))),
|
|
224
|
+
h('pre', { style: styles.code, 'data-dsh-control-mcp-snippet': tab }, token ? displayed[tab].text : '…'),
|
|
225
|
+
h('div', { style: styles.inline }, h(CopyButton, { text: snippets[tab].text, label: 'Copy configuration', disabled: !token })),
|
|
226
|
+
h('p', { style: styles.hint }, `MCP endpoint: ${mcpUrl} · API base: ${apiUrl}. DSH listens on this machine only unless you started it with a trusted host; remote clients need a tunnel or a trusted host.`));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function Picker({ label, items, selected, onToggle, empty, describe }) {
|
|
230
|
+
const [query, setQuery] = useState('');
|
|
231
|
+
const needle = query.trim().toLowerCase();
|
|
232
|
+
const shown = needle ? items.filter(item => `${item.title} ${describe(item)}`.toLowerCase().includes(needle)) : items;
|
|
233
|
+
return h('div', { style: styles.fieldRow },
|
|
234
|
+
h('span', { style: styles.label }, `${label} (${selected.length} selected)`),
|
|
235
|
+
items.length > 6 ? h('input', { type: 'search', placeholder: `Search ${label.toLowerCase()}…`, value: query, style: styles.textInput, 'aria-label': `Search ${label.toLowerCase()}`, onChange: event => setQuery(event.target.value) }) : null,
|
|
236
|
+
h('div', { style: styles.pick, role: 'group', 'aria-label': label },
|
|
237
|
+
items.length === 0 ? h('p', { style: { ...styles.hint, padding: '6px 8px' } }, empty) : null,
|
|
238
|
+
shown.map(item => h('label', { key: item.id, style: styles.pickItem },
|
|
239
|
+
h('input', { type: 'checkbox', checked: selected.includes(item.id), onChange: () => onToggle(item.id), style: { marginTop: '3px', flex: 'none' } }),
|
|
240
|
+
h('span', { style: { display: 'flex', flexDirection: 'column', minWidth: 0 } },
|
|
241
|
+
h('span', { style: { overflowWrap: 'anywhere' } }, item.title),
|
|
242
|
+
h('span', { style: { ...styles.hint, overflowWrap: 'anywhere' } }, describe(item)))))));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const EMPTY_KEY = { name: '', mode: 'scoped', access: 'read', workspaces: [], sessions: [], mcp: true, api: true, expiresAt: null, disabled: false };
|
|
246
|
+
|
|
247
|
+
function KeyEditor({ initial, options, scopedSupported, onCancel, onSave, busy }) {
|
|
248
|
+
const [draft, setDraft] = useState(() => ({ ...EMPTY_KEY, ...initial, expiresAt: initial?.expiresAt ? initial.expiresAt.slice(0, 10) : '' }));
|
|
249
|
+
const set = patch => setDraft(previous => ({ ...previous, ...patch }));
|
|
250
|
+
const toggle = (field, id) => set({ [field]: draft[field].includes(id) ? draft[field].filter(item => item !== id) : [...draft[field], id] });
|
|
251
|
+
const workspaceTitle = id => options.workspaces.find(w => w.id === id)?.title;
|
|
252
|
+
const coveredByWorkspace = session => options.workspaces.some(w => draft.workspaces.includes(w.id) && w.sessionIds.includes(session.id));
|
|
253
|
+
const problems = [];
|
|
254
|
+
if (draft.name.trim() === '') problems.push('Give the key a name.');
|
|
255
|
+
if (!draft.mcp && !draft.api) problems.push('Enable MCP, the HTTP API, or both.');
|
|
256
|
+
if (draft.mode === 'scoped' && draft.workspaces.length === 0 && draft.sessions.length === 0) problems.push('Choose at least one workspace or chat, or make it a full-access key.');
|
|
257
|
+
if (draft.mode === 'scoped' && !scopedSupported) problems.push('Scoped keys need DSH 0.2.1 or later.');
|
|
258
|
+
const submit = () => onSave({
|
|
259
|
+
name: draft.name.trim(), mode: draft.mode, access: draft.access, mcp: draft.mcp, api: draft.api,
|
|
260
|
+
workspaces: draft.mode === 'scoped' ? draft.workspaces : [], sessions: draft.mode === 'scoped' ? draft.sessions : [],
|
|
261
|
+
expiresAt: draft.expiresAt ? new Date(`${draft.expiresAt}T23:59:59`).toISOString() : null,
|
|
262
|
+
});
|
|
263
|
+
return h('div', { style: styles.editor, 'data-dsh-control-mcp-key-editor': '' },
|
|
264
|
+
h('div', { style: styles.fieldRow },
|
|
265
|
+
h('label', { htmlFor: 'dsh-control-mcp-key-name', style: styles.label }, 'Name'),
|
|
266
|
+
h('input', { id: 'dsh-control-mcp-key-name', style: styles.textInput, maxLength: 80, value: draft.name, placeholder: 'e.g. Claude on my phone, CI bot, Release notes chat', onChange: event => set({ name: event.target.value }) })),
|
|
267
|
+
h('div', { style: styles.radioRow },
|
|
268
|
+
h('label', { style: styles.inline }, h('input', { type: 'checkbox', checked: draft.mcp, onChange: event => set({ mcp: event.target.checked }) }), 'MCP'),
|
|
269
|
+
h('label', { style: styles.inline }, h('input', { type: 'checkbox', checked: draft.api, onChange: event => set({ api: event.target.checked }) }), 'HTTP API')),
|
|
270
|
+
h('div', { style: styles.fieldRow, role: 'radiogroup', 'aria-label': 'Access' },
|
|
271
|
+
h('span', { style: styles.label }, 'Access'),
|
|
272
|
+
h('label', { style: styles.inline }, h('input', { type: 'radio', name: 'dsh-control-mcp-mode', checked: draft.mode === 'scoped', onChange: () => set({ mode: 'scoped' }) }), 'Only chosen workspaces and chats'),
|
|
273
|
+
h('label', { style: styles.inline }, h('input', { type: 'radio', name: 'dsh-control-mcp-mode', checked: draft.mode === 'full', onChange: () => set({ mode: 'full' }) }), 'Full access to this harness'),
|
|
274
|
+
draft.mode === 'full' ? h('p', { style: styles.warn }, 'A full-access key can do anything you can: every chat, plugins, settings and installs.') : null),
|
|
275
|
+
draft.mode === 'scoped' ? h(React.Fragment, null,
|
|
276
|
+
h('div', { style: styles.fieldRow, role: 'radiogroup', 'aria-label': 'Inside its chats' },
|
|
277
|
+
h('span', { style: styles.label }, 'Inside its chats'),
|
|
278
|
+
h('label', { style: styles.inline }, h('input', { type: 'radio', name: 'dsh-control-mcp-access', checked: draft.access === 'read', onChange: () => set({ access: 'read' }) }), 'Read only: history, state and replies'),
|
|
279
|
+
h('label', { style: styles.inline }, h('input', { type: 'radio', name: 'dsh-control-mcp-access', checked: draft.access === 'prompt', onChange: () => set({ access: 'prompt' }) }), 'Read and prompt: also send messages, stop, rename, and start chats in its workspaces')),
|
|
280
|
+
h(Picker, {
|
|
281
|
+
label: 'Workspaces', items: options.workspaces, selected: draft.workspaces, onToggle: id => toggle('workspaces', id),
|
|
282
|
+
empty: 'No workspaces yet.', describe: w => `${w.path} · ${w.sessionIds.length} chat${w.sessionIds.length === 1 ? '' : 's'} · includes chats added later`,
|
|
283
|
+
}),
|
|
284
|
+
h(Picker, {
|
|
285
|
+
label: 'Chats', items: options.sessions, selected: draft.sessions, onToggle: id => toggle('sessions', id),
|
|
286
|
+
empty: 'No chats yet.',
|
|
287
|
+
describe: session => [coveredByWorkspace(session) ? 'already covered by a chosen workspace' : null, options.workspaces.find(w => w.sessionIds.includes(session.id)) ? `in ${workspaceTitle(options.workspaces.find(w => w.sessionIds.includes(session.id)).id)}` : session.cwd, session.blank ? 'not started' : session.running ? 'running' : null].filter(Boolean).join(' · '),
|
|
288
|
+
})) : null,
|
|
289
|
+
h('div', { style: styles.fieldRow },
|
|
290
|
+
h('label', { htmlFor: 'dsh-control-mcp-key-expiry', style: styles.label }, 'Expires (optional)'),
|
|
291
|
+
h('input', { id: 'dsh-control-mcp-key-expiry', type: 'date', style: { ...styles.textInput, width: '180px' }, value: draft.expiresAt, onChange: event => set({ expiresAt: event.target.value }) })),
|
|
292
|
+
problems.length ? h('p', { role: 'alert', style: styles.error }, problems[0]) : null,
|
|
293
|
+
h('div', { style: styles.inline },
|
|
294
|
+
h('button', { type: 'button', style: buttonStyle(true, busy || problems.length > 0), disabled: busy || problems.length > 0, onClick: submit }, busy ? 'Saving…' : initial?.id ? 'Save key' : 'Create key'),
|
|
295
|
+
h('button', { type: 'button', style: buttonStyle(false, busy), disabled: busy, onClick: onCancel }, 'Cancel')));
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function NewToken({ reveal, onDone }) {
|
|
299
|
+
const [tab, setTab] = useState('http');
|
|
300
|
+
const mcpUrl = originUrl(`${ROUTE}/mcp`);
|
|
301
|
+
const apiUrl = originUrl(`${ROUTE}/api/v1`);
|
|
302
|
+
const snippets = {
|
|
303
|
+
http: { label: 'MCP over HTTP', text: mcpJsonConfig(mcpUrl, reveal.token) },
|
|
304
|
+
stdio: { label: 'MCP over stdio', text: stdioConfig(mcpUrl, reveal.token) },
|
|
305
|
+
curl: { label: 'HTTP API', text: `curl -s -X POST -H 'Authorization: Bearer ${reveal.token}' -H 'content-type: application/json' \\\n -d '{"_request":{}}' ${apiUrl}/call/session/list` },
|
|
306
|
+
};
|
|
307
|
+
return h('div', { style: { ...styles.editor, borderColor: 'var(--dsw-alias-brand-primary)' }, role: 'status', 'data-dsh-control-mcp-new-token': '' },
|
|
308
|
+
h('span', { style: styles.label }, `Token for "${reveal.key.name}"`),
|
|
309
|
+
h('p', { style: styles.warn }, 'Copy it now. It is shown only once; the harness keeps only a fingerprint. Rotate the key if you lose it.'),
|
|
310
|
+
h('div', { style: styles.inline },
|
|
311
|
+
h('input', { readOnly: true, value: reveal.token, style: styles.input, 'aria-label': 'New key token', onFocus: event => event.target.select() }),
|
|
312
|
+
h(CopyButton, { text: reveal.token })),
|
|
313
|
+
h('div', { style: styles.tabs, role: 'tablist' }, Object.entries(snippets).map(([key, snippet]) => h('button', { key, type: 'button', role: 'tab', 'aria-selected': tab === key, style: buttonStyle(tab === key, false), onClick: () => setTab(key) }, snippet.label))),
|
|
314
|
+
h('pre', { style: styles.code }, snippets[tab].text),
|
|
315
|
+
h('div', { style: styles.inline }, h(CopyButton, { text: snippets[tab].text, label: 'Copy configuration' }), h('button', { type: 'button', style: buttonStyle(false, false), onClick: onDone }, 'Done')));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function KeysSection({ enabled }) {
|
|
319
|
+
const [state, setState] = useState({ status: 'loading', keys: [], options: { workspaces: [], sessions: [] }, scopedSupported: true, error: '' });
|
|
320
|
+
const [editing, setEditing] = useState(undefined);
|
|
321
|
+
const [reveal, setReveal] = useState(undefined);
|
|
322
|
+
const [busy, setBusy] = useState(false);
|
|
323
|
+
const [failure, setFailure] = useState('');
|
|
324
|
+
const mounted = useRef(true);
|
|
325
|
+
useEffect(() => () => { mounted.current = false; }, []);
|
|
326
|
+
|
|
327
|
+
const load = useCallback(async () => {
|
|
328
|
+
try {
|
|
329
|
+
const [list, options] = await Promise.all([manage('/keys'), manage('/scope-options')]);
|
|
330
|
+
if (mounted.current) setState({ status: 'ready', keys: list.keys, options: { workspaces: options.workspaces, sessions: options.sessions }, scopedSupported: list.scopedSupported !== false, error: '' });
|
|
331
|
+
} catch (error) {
|
|
332
|
+
if (mounted.current) setState(previous => ({ ...previous, status: 'error', error: error.message }));
|
|
333
|
+
}
|
|
334
|
+
}, []);
|
|
335
|
+
useEffect(() => { void load(); }, [load]);
|
|
336
|
+
|
|
337
|
+
const run = async (action, after) => {
|
|
338
|
+
setBusy(true); setFailure('');
|
|
339
|
+
try { const value = await action(); after?.(value); await load(); } catch (error) { setFailure(error.message || 'The change was not saved.'); } finally { if (mounted.current) setBusy(false); }
|
|
340
|
+
};
|
|
341
|
+
const save = fields => run(
|
|
342
|
+
() => (editing?.id ? manage(`/keys/${editing.id}`, 'PATCH', fields) : manage('/keys', 'POST', fields)),
|
|
343
|
+
value => { setEditing(undefined); if (value?.token) setReveal(value); },
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
return h('div', { style: styles.section, 'data-dsh-control-mcp-keys': '' },
|
|
347
|
+
h('h5', { style: styles.sectionTitle }, 'API keys'),
|
|
348
|
+
h('p', { style: styles.hint }, 'Give each client its own key. A key can reach the whole harness, or only the workspaces and chats you choose: everything else stays invisible to it, in every list and every call.'),
|
|
349
|
+
!enabled ? h('p', { style: styles.status }, 'Keys work once the MCP server or the HTTP API is on.') : null,
|
|
350
|
+
!state.scopedSupported ? h('p', { style: styles.warn }, 'This DSH version cannot confine keys; scoped keys need DSH 0.2.1 or later. Full-access keys work.') : null,
|
|
351
|
+
state.status === 'error' ? h('div', { style: styles.inline }, h('p', { role: 'alert', style: styles.error }, `Could not load keys: ${state.error}`), h('button', { type: 'button', style: buttonStyle(false, false), onClick: () => { void load(); } }, 'Retry')) : null,
|
|
352
|
+
failure ? h('p', { role: 'alert', style: styles.error }, failure) : null,
|
|
353
|
+
reveal ? h(NewToken, { reveal, onDone: () => setReveal(undefined) }) : null,
|
|
354
|
+
state.status === 'loading' ? h('p', { style: styles.status }, 'Loading keys…') : null,
|
|
355
|
+
state.status === 'ready' && state.keys.length === 0 && editing === undefined ? h('p', { style: styles.status }, 'No keys yet.') : null,
|
|
356
|
+
state.keys.length > 0 ? h('div', { style: styles.card, role: 'list', 'aria-label': 'API keys' }, state.keys.map((key, index) => h('div', { key: key.id, role: 'listitem', style: { ...styles.keyRow, ...index === state.keys.length - 1 ? styles.rowLast : {} }, 'data-key-name': key.name },
|
|
357
|
+
h('div', { style: styles.keyMain },
|
|
358
|
+
h('span', { style: { ...styles.label, overflowWrap: 'anywhere' } }, key.name),
|
|
359
|
+
h('span', { style: { ...styles.hint, overflowWrap: 'anywhere' } }, `${scopeSummary(key, state.options)} · ${[key.mcp ? 'MCP' : null, key.api ? 'API' : null].filter(Boolean).join(' + ')} · ${key.prefix}… · used ${relativeTime(key.lastUsedAt)}${key.expiresAt ? ` · expires ${key.expiresAt.slice(0, 10)}` : ''}`)),
|
|
360
|
+
key.disabled ? h('span', { style: styles.badgeMuted }, 'Disabled') : key.expired ? h('span', { style: styles.badgeMuted }, 'Expired') : null,
|
|
361
|
+
h('button', { type: 'button', style: buttonStyle(false, busy), disabled: busy, onClick: () => { setReveal(undefined); setEditing(key); } }, 'Edit'),
|
|
362
|
+
h('button', { type: 'button', style: buttonStyle(false, busy), disabled: busy, onClick: () => run(() => manage(`/keys/${key.id}`, 'PATCH', { disabled: !key.disabled })) }, key.disabled ? 'Enable' : 'Disable'),
|
|
363
|
+
h('button', { type: 'button', style: buttonStyle(false, busy), disabled: busy, onClick: () => { if (window.confirm(`Rotate "${key.name}"? Clients using its current token stop working.`)) void run(() => manage(`/keys/${key.id}/rotate`, 'POST'), value => setReveal(value)); } }, 'Rotate'),
|
|
364
|
+
h('button', { type: 'button', style: buttonStyle(false, busy), disabled: busy, onClick: () => { if (window.confirm(`Delete "${key.name}"? Clients using it stop working at once.`)) void run(() => manage(`/keys/${key.id}`, 'DELETE')); } }, 'Delete')))) : null,
|
|
365
|
+
editing !== undefined
|
|
366
|
+
? h(KeyEditor, { key: editing?.id ?? 'new', initial: editing, options: state.options, scopedSupported: state.scopedSupported, busy, onCancel: () => setEditing(undefined), onSave: save })
|
|
367
|
+
: h('div', { style: styles.inline }, h('button', { type: 'button', style: buttonStyle(true, busy || state.status !== 'ready'), disabled: busy || state.status !== 'ready', onClick: () => { setReveal(undefined); setEditing(null); } }, 'New key'), h('button', { type: 'button', style: buttonStyle(false, false), onClick: () => { void load(); } }, 'Refresh chats')));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function ControlPage({ source }) {
|
|
371
|
+
const mirrorSnapshot = useStore(source.describe, emptyMirror);
|
|
372
|
+
const namespaces = mirrorSnapshot?.view?.namespaces ?? [];
|
|
373
|
+
const form = source.formFor(namespaces);
|
|
374
|
+
const snapshot = useStore(form ?? noForm, unavailableSnapshot);
|
|
375
|
+
const [pending, setPending] = useState('');
|
|
376
|
+
const [failure, setFailure] = useState('');
|
|
377
|
+
const [blockedDraft, setBlockedDraft] = useState(undefined);
|
|
378
|
+
const busy = useRef(false);
|
|
379
|
+
|
|
380
|
+
useEffect(() => { try { void source.describe?.ensure?.(); } catch { /* the mirror reports its own failure */ } }, [source]);
|
|
381
|
+
|
|
382
|
+
const value = isRecord(snapshot.value) ? snapshot.value : {};
|
|
383
|
+
const writable = snapshot.status === 'ready' && snapshot.writable === true && (snapshot.mode === undefined || snapshot.mode === 'host');
|
|
384
|
+
const storedBlocked = useMemo(() => (Array.isArray(value.blockedEndpoints) ? value.blockedEndpoints : []).join('\n'), [snapshot.value]);
|
|
385
|
+
const blockedText = blockedDraft ?? storedBlocked;
|
|
386
|
+
const blocked = parseBlocked(blockedText);
|
|
387
|
+
|
|
388
|
+
async function write(field, next) {
|
|
389
|
+
if (!writable || busy.current || form === undefined) return;
|
|
390
|
+
busy.current = true;
|
|
391
|
+
setPending(field);
|
|
392
|
+
setFailure('');
|
|
393
|
+
try {
|
|
394
|
+
await form.mutate([{ op: 'set', path: [field], value: next }], snapshot.revision);
|
|
395
|
+
const settled = form.getSnapshot();
|
|
396
|
+
if (settled.status !== 'ready' || JSON.stringify(settled.value?.[field]) !== JSON.stringify(next)) throw new Error('not confirmed');
|
|
397
|
+
if (field === 'blockedEndpoints') setBlockedDraft(undefined);
|
|
398
|
+
} catch {
|
|
399
|
+
setFailure(SAVE_ERROR);
|
|
400
|
+
} finally {
|
|
401
|
+
busy.current = false;
|
|
402
|
+
setPending('');
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
let status = null;
|
|
407
|
+
if (mirrorSnapshot?.view === undefined && form === undefined) status = 'Loading settings…';
|
|
408
|
+
else if (form === undefined || snapshot.status === 'unavailable') status = 'The dsh-control-mcp host plugin is not running, so these settings cannot be changed. Check the dsh startup output.';
|
|
409
|
+
else if (snapshot.status === 'loading') status = 'Loading settings…';
|
|
410
|
+
else if (!writable) status = 'These settings are read-only in this browser.';
|
|
411
|
+
|
|
412
|
+
const anyEnabled = value.mcpEnabled === true || value.apiEnabled === true;
|
|
413
|
+
return h('section', { style: styles.page, 'data-dsh-control-mcp': '' },
|
|
414
|
+
h('div', { style: styles.head },
|
|
415
|
+
h('h4', { style: styles.title }, 'Harness control'),
|
|
416
|
+
h('p', { style: styles.lead }, 'Let MCP clients and programs drive this harness through the same API the web GUI uses: sessions and prompts, workspaces, models, plugins, schedules, goals, terminals and settings. Both surfaces are off until you turn them on.')),
|
|
417
|
+
status === null ? null : h('p', { role: 'status', style: styles.status }, status),
|
|
418
|
+
h('div', { style: styles.card }, SWITCHES.map((item, index) => h('div', { key: item.field, style: { ...styles.row, ...index === SWITCHES.length - 1 ? styles.rowLast : {} } },
|
|
419
|
+
h('label', { htmlFor: `dsh-control-mcp-${item.field}`, style: styles.rowText },
|
|
420
|
+
h('span', { style: styles.label }, item.label),
|
|
421
|
+
h('span', { style: styles.hint }, item.hint)),
|
|
422
|
+
h(Switch, {
|
|
423
|
+
id: `dsh-control-mcp-${item.field}`, label: item.label, checked: value[item.field] === true,
|
|
424
|
+
disabled: !writable || pending !== '',
|
|
425
|
+
onChange: checked => { void write(item.field, checked); },
|
|
426
|
+
})))),
|
|
427
|
+
anyEnabled && value.readOnly !== true ? h('p', { style: styles.warn, role: 'note' }, 'Full control is on: a client with the token can run prompts (which run tools and shell commands), change plugins and settings, and read every session. Use read-only mode or blocked endpoints to narrow it.') : null,
|
|
428
|
+
failure ? h('p', { role: 'alert', style: styles.error }, failure) : null,
|
|
429
|
+
h('div', { style: styles.section },
|
|
430
|
+
h('label', { htmlFor: 'dsh-control-mcp-blocked', style: styles.sectionTitle }, 'Blocked endpoints'),
|
|
431
|
+
h('p', { style: styles.hint }, 'One pattern per line, "*" matches anything: account/*, pluginManager/removeBundle, */delete. Blocked endpoints are hidden and refused.'),
|
|
432
|
+
h('textarea', { id: 'dsh-control-mcp-blocked', style: styles.textarea, value: blockedText, disabled: !writable, spellCheck: false, onChange: event => setBlockedDraft(event.target.value) }),
|
|
433
|
+
blocked.invalid.length > 0 ? h('p', { role: 'alert', style: styles.error }, `Not a "namespace/method" pattern: ${blocked.invalid.join(', ')}`) : null,
|
|
434
|
+
h('div', { style: styles.inline },
|
|
435
|
+
h('button', {
|
|
436
|
+
type: 'button', style: buttonStyle(true, !writable || blockedDraft === undefined || blocked.invalid.length > 0 || pending !== ''),
|
|
437
|
+
disabled: !writable || blockedDraft === undefined || blocked.invalid.length > 0 || pending !== '',
|
|
438
|
+
onClick: () => { void write('blockedEndpoints', blocked.items); },
|
|
439
|
+
}, pending === 'blockedEndpoints' ? 'Saving…' : 'Save'),
|
|
440
|
+
blockedDraft !== undefined ? h('button', { type: 'button', style: buttonStyle(false, false), onClick: () => setBlockedDraft(undefined) }, 'Discard') : null)),
|
|
441
|
+
h(KeysSection, { enabled: anyEnabled }),
|
|
442
|
+
h(TokenSection, { enabled: anyEnabled }));
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function apply(ctx) {
|
|
446
|
+
ctx.inject(['configForms'], child => {
|
|
447
|
+
const forms = child.configForms;
|
|
448
|
+
let cached;
|
|
449
|
+
const source = {
|
|
450
|
+
describe: forms.describe(),
|
|
451
|
+
formFor(namespaces) {
|
|
452
|
+
const ns = findEntryNamespace(namespaces);
|
|
453
|
+
if (ns === undefined) return undefined;
|
|
454
|
+
if (cached?.ns !== ns) cached = { ns, form: forms.get(ns) };
|
|
455
|
+
return cached.form;
|
|
456
|
+
},
|
|
457
|
+
};
|
|
458
|
+
child.slots.inject('plugins.bundle.config', () => child.slots.register({
|
|
459
|
+
name: 'plugins.bundle.config',
|
|
460
|
+
key: PACKAGE,
|
|
461
|
+
inject: () => ({ source }),
|
|
462
|
+
}, ControlPage));
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return { inject, apply, findEntryNamespace, parseBlocked, mcpJsonConfig, stdioConfig, scopeSummary };
|
|
467
|
+
}
|
package/cordis.patch.yml
ADDED
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Harness control (MCP and API)
|
|
2
|
+
|
|
3
|
+
Lets MCP clients and other programs drive this DeepSeek Harness through the same API the web GUI uses.
|
|
4
|
+
|
|
5
|
+
## What you can do
|
|
6
|
+
|
|
7
|
+
- List, create and cancel sessions; send prompts and wait for the reply; read session history.
|
|
8
|
+
- List workspaces, models and plugins; enable or disable plugins.
|
|
9
|
+
- Reach every other harness action (schedules, goals, terminals, jobs, settings, plugin installs, …) through `dsh_call` and `dsh_stream`, or through the HTTP API.
|
|
10
|
+
|
|
11
|
+
## Turn it on
|
|
12
|
+
|
|
13
|
+
1. Open **Plugins → dsh-control-mcp**.
|
|
14
|
+
2. Switch on **MCP server**, **HTTP API**, or both. Both start off.
|
|
15
|
+
3. Copy the access token and a ready-made client configuration from the same page.
|
|
16
|
+
|
|
17
|
+
| Surface | Address |
|
|
18
|
+
|---|---|
|
|
19
|
+
| MCP (Streamable HTTP) | `<harness URL>/dsh-control-mcp/mcp` |
|
|
20
|
+
| HTTP API | `<harness URL>/dsh-control-mcp/api/v1` |
|
|
21
|
+
| MCP over stdio | `npx -y dsh-control-mcp` with `DSH_CONTROL_URL` and `DSH_CONTROL_TOKEN` |
|
|
22
|
+
|
|
23
|
+
Every call needs `Authorization: Bearer <token>`. **Rotate** issues a new token and invalidates the old one.
|
|
24
|
+
|
|
25
|
+
## API keys and scopes
|
|
26
|
+
|
|
27
|
+
Create one key per client under **API keys → New key**. A key has a name, MCP and/or HTTP API access, an optional expiry, and either:
|
|
28
|
+
|
|
29
|
+
- **Full access** to this harness, or
|
|
30
|
+
- **Only chosen workspaces and chats**: a workspace includes its current chats and chats added later. Pick **Read only** or **Read and prompt**.
|
|
31
|
+
|
|
32
|
+
A scoped key cannot see, list or touch any other chat, and cannot reach plugins, settings, credentials or other harness-wide actions. DSH's own access control enforces this (DSH 0.2.1 or later). The token is shown once; disable, rotate or delete a key at any time.
|
|
33
|
+
|
|
34
|
+
## Limit what clients may do
|
|
35
|
+
|
|
36
|
+
- **Read-only mode** refuses every call that changes harness state.
|
|
37
|
+
- **Blocked endpoints** hide and refuse endpoints by pattern, for example `account/*` or `pluginManager/removeBundle`.
|
|
38
|
+
|
|
39
|
+
## Limitations
|
|
40
|
+
|
|
41
|
+
- With full control on, a client holding the token can run prompts, and prompts can run tools and shell commands. Treat the token like a password.
|
|
42
|
+
- DSH listens on this machine only unless it was started with a trusted host; remote clients need a tunnel or a trusted-host setup.
|
|
43
|
+
- Calls never answer approvals or questions on your behalf; those still appear in the GUI.
|
package/icon.svg
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" role="img" aria-label="Harness control">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="dshc-bg" x1="0" y1="0" x2="1" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#4d6bfe"/>
|
|
5
|
+
<stop offset="1" stop-color="#2a3fb8"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<rect x="2" y="2" width="60" height="60" rx="14" fill="url(#dshc-bg)"/>
|
|
9
|
+
<!-- console window -->
|
|
10
|
+
<rect x="12" y="15" width="40" height="30" rx="5" fill="none" stroke="#ffffff" stroke-width="3"/>
|
|
11
|
+
<path d="M19 25l6 5-6 5" fill="none" stroke="#ffffff" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
|
|
12
|
+
<path d="M29 35h10" stroke="#ffffff" stroke-width="3" stroke-linecap="round"/>
|
|
13
|
+
<!-- connector plug: the remote client -->
|
|
14
|
+
<path d="M32 45v5" stroke="#ffffff" stroke-width="3" stroke-linecap="round"/>
|
|
15
|
+
<circle cx="32" cy="52" r="3.2" fill="#9fe3ff"/>
|
|
16
|
+
<path d="M20 52h8M36 52h8" stroke="#9fe3ff" stroke-width="2.5" stroke-linecap="round"/>
|
|
17
|
+
</svg>
|