@hearsay-tools/squawk 0.19.0-dev.8640 → 0.19.0-dev.8648
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/dist/automations/tools.d.ts +8 -8
- package/dist/boot.js +2 -0
- package/dist/boot.js.map +1 -1
- package/dist/contract/index.js +1 -1
- package/dist/core/agent-env.js +2 -0
- package/dist/core/agent-env.js.map +1 -1
- package/dist/core/http-route-registry.d.ts +37 -0
- package/dist/core/http-route-registry.js +47 -0
- package/dist/core/http-route-registry.js.map +1 -0
- package/dist/core/product-env.d.ts +2 -0
- package/dist/core/product-env.js +4 -0
- package/dist/core/product-env.js.map +1 -1
- package/dist/core/secret-redaction.d.ts +10 -4
- package/dist/core/secret-redaction.js +37 -0
- package/dist/core/secret-redaction.js.map +1 -1
- package/dist/features/mcp/cli.d.ts +4 -0
- package/dist/features/mcp/cli.js +19 -4
- package/dist/features/mcp/cli.js.map +1 -1
- package/dist/features/mcp/http.d.ts +23 -0
- package/dist/features/mcp/http.js +236 -0
- package/dist/features/mcp/http.js.map +1 -0
- package/dist/features/mcp/index.d.ts +6 -4
- package/dist/features/mcp/index.js +16 -4
- package/dist/features/mcp/index.js.map +1 -1
- package/dist/features/mcp/token-cli.d.ts +9 -0
- package/dist/features/mcp/token-cli.js +188 -0
- package/dist/features/mcp/token-cli.js.map +1 -0
- package/dist/features/mcp/tools.d.ts +4 -0
- package/dist/features/mcp/tools.js +24 -3
- package/dist/features/mcp/tools.js.map +1 -1
- package/dist/home/entry-authorization.js +1 -1
- package/dist/home/entry-authorization.js.map +1 -1
- package/dist/home/home.d.ts +2 -0
- package/dist/home/home.js +1 -0
- package/dist/home/home.js.map +1 -1
- package/dist/home/legacy-source.js +1 -1
- package/dist/home/legacy-source.js.map +1 -1
- package/dist/home/migration-plan.js +4 -4
- package/dist/home/migration-plan.js.map +1 -1
- package/dist/home/recovery-watch.js +2 -2
- package/dist/home/recovery-watch.js.map +1 -1
- package/dist/home/recovery.js +1 -1
- package/dist/home/recovery.js.map +1 -1
- package/dist/home/store.js +3 -3
- package/dist/home/store.js.map +1 -1
- package/dist/mcp-tokens.d.ts +85 -0
- package/dist/mcp-tokens.js +356 -0
- package/dist/mcp-tokens.js.map +1 -0
- package/dist/plugin/api.d.ts +3 -0
- package/dist/plugin/api.js +20 -1
- package/dist/plugin/api.js.map +1 -1
- package/dist/plugin/cli.js +1 -1
- package/dist/plugin/cli.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -0
- package/dist/plugin/index.js.map +1 -1
- package/dist/runs/record-write-rules.js +2 -2
- package/dist/runs/record-write-rules.js.map +1 -1
- package/dist/runs/run-redaction.d.ts +1 -0
- package/dist/runs/run-redaction.js +18 -7
- package/dist/runs/run-redaction.js.map +1 -1
- package/dist/server/home-recovery-routes.js +7 -4
- package/dist/server/home-recovery-routes.js.map +1 -1
- package/dist/server/live-routes.d.ts +6 -6
- package/dist/server/plugin-http-routes.d.ts +21 -0
- package/dist/server/plugin-http-routes.js +52 -0
- package/dist/server/plugin-http-routes.js.map +1 -0
- package/dist/server/provider-sign-in-routes.d.ts +2 -2
- package/dist/server/repo-routes.d.ts +13 -13
- package/dist/server/runs-routes.d.ts +291 -291
- package/dist/server/server.d.ts +452 -449
- package/dist/server/server.js +15 -3
- package/dist/server/server.js.map +1 -1
- package/dist/server/workspace-live-routes.d.ts +6 -6
- package/dist/server-install/engine.js +25 -1
- package/dist/server-install/engine.js.map +1 -1
- package/dist/server-install/platforms/ubuntu-vps-nginx.d.ts +14 -0
- package/dist/server-install/platforms/ubuntu-vps-nginx.js +85 -0
- package/dist/server-install/platforms/ubuntu-vps-nginx.js.map +1 -0
- package/dist/server-install/platforms/ubuntu-vps.d.ts +2 -11
- package/dist/server-install/platforms/ubuntu-vps.js +2 -67
- package/dist/server-install/platforms/ubuntu-vps.js.map +1 -1
- package/package.json +4 -4
- package/web/dist/assets/{accounts-section-D7EK3_7b.js → accounts-section-RDVTJfi7.js} +1 -1
- package/web/dist/assets/{activity-motion-2BQBW4lA.js → activity-motion-B7km8QVK.js} +1 -1
- package/web/dist/assets/{activity-route-Ct06t8Y9.js → activity-route-CjE0yxn0.js} +1 -1
- package/web/dist/assets/{agent-config-section-D6Lcc7c5.js → agent-config-section-DQ1RaVK2.js} +1 -1
- package/web/dist/assets/{agent-defaults-section-BnDBbzuG.js → agent-defaults-section-Dzm7jIza.js} +1 -1
- package/web/dist/assets/{appearance-CM6ahUyy.js → appearance-DQLHHfI4.js} +1 -1
- package/web/dist/assets/{automations-route-7B_DF4O1.js → automations-route-BcdL5f0K.js} +1 -1
- package/web/dist/assets/{commit-list-O4ugJ12w.js → commit-list-CN1zX-0X.js} +1 -1
- package/web/dist/assets/{diff-controls-BpTFu29H.js → diff-controls-BRa3141W.js} +1 -1
- package/web/dist/assets/{diff-DKZvZQ2G.js → diff-hxqBOfZH.js} +2 -2
- package/web/dist/assets/{diff-view-D4yXb2w7.js → diff-view-CwlKCj5V.js} +1 -1
- package/web/dist/assets/{file-preview-CUhut4J9.js → file-preview-VvCzp02k.js} +1 -1
- package/web/dist/assets/{git-toolbar-po0QJciG.js → git-toolbar-BulcGzsv.js} +1 -1
- package/web/dist/assets/{github-TgLTixC7.js → github-By3yOcFH.js} +1 -1
- package/web/dist/assets/{global-activity-route-OHCmn0ZO.js → global-activity-route-C4-bmfh_.js} +1 -1
- package/web/dist/assets/{image-preview-Sisptm3b.js → image-preview-Pgf8bnzY.js} +1 -1
- package/web/dist/assets/{index-CvVmG4Yu.js → index-DNQcTHxV.js} +5 -5
- package/web/dist/assets/{markdown-jle_P0a2.js → markdown-9L65ixU6.js} +1 -1
- package/web/dist/assets/{notifications-section-Bhqr3yOz.js → notifications-section-QWmuj2j2.js} +1 -1
- package/web/dist/assets/{preview-pane-connected-CBt_nlmX.js → preview-pane-connected-DAM2Snwh.js} +1 -1
- package/web/dist/assets/{projects-section-DnGSWHZJ.js → projects-section-DxubjpZI.js} +1 -1
- package/web/dist/assets/{prompt-templates-section-8kBTviSw.js → prompt-templates-section-CkQneT1G.js} +1 -1
- package/web/dist/assets/{remote-settings-notice-D7G8cXSx.js → remote-settings-notice-COojb6XK.js} +1 -1
- package/web/dist/assets/{repo-git-DqBUjQMh.js → repo-git-Mgk4Qcmo.js} +1 -1
- package/web/dist/assets/{report-reader-DtSBGt0O.js → report-reader-zWwalJDN.js} +1 -1
- package/web/dist/assets/{reports-ea3-iuBm.js → reports-BCHWt3zy.js} +1 -1
- package/web/dist/assets/{resources-section-CpXFFHXl.js → resources-section-Cb2WIqNv.js} +1 -1
- package/web/dist/assets/{run-header-BWTrj0_2.js → run-header-DeprqSP7.js} +1 -1
- package/web/dist/assets/{select-aiSr0uTB.js → select-y3oRuA2s.js} +1 -1
- package/web/dist/assets/{session-context-section-BRaZbxVO.js → session-context-section-CiPNMiL7.js} +1 -1
- package/web/dist/assets/{settings-agent-picker-DMIqQhkC.js → settings-agent-picker-CJJJncuA.js} +1 -1
- package/web/dist/assets/{settings-shell-DwMbZhxp.js → settings-shell-CLToW28f.js} +1 -1
- package/web/dist/assets/{sidebar-section-ClrORHpO.js → sidebar-section-VOYJarPd.js} +1 -1
- package/web/dist/assets/{skills-B97qjJ7j.js → skills-BySF3yBA.js} +1 -1
- package/web/dist/assets/{task-changes-BEfLx9dF.js → task-changes-NUwvUglx.js} +1 -1
- package/web/dist/assets/{task-commits-6f0GpNF7.js → task-commits-CpV1Hz9L.js} +1 -1
- package/web/dist/assets/{task-files-CA2xTRaM.js → task-files-Bu-L_NRW.js} +1 -1
- package/web/dist/assets/{task-github-item-BWapcDJr.js → task-github-item-DhiTqCjk.js} +1 -1
- package/web/dist/assets/{task-thread-0rKVutjQ.js → task-thread-CKkTeQdi.js} +1 -1
- package/web/dist/assets/{thread-state-C3eDWXYs.js → thread-state-B_ZqjjRr.js} +1 -1
- package/web/dist/assets/{use-hand-to-agent-state-DrAmCxn8.js → use-hand-to-agent-state-K864D69i.js} +1 -1
- package/web/dist/assets/{workflows-CW-1K6tq.js → workflows-DlTkuM0J.js} +1 -1
- package/web/dist/assets/{workspace-tools-BzDQrP3y.js → workspace-tools-BRK7f1Hk.js} +1 -1
- package/web/dist/assets/{worktrees-section-ay1jJn_w.js → worktrees-section-BXI0-7HH.js} +1 -1
- package/web/dist/index.html +1 -1
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateless Streamable HTTP MCP endpoint (`/api/v1/mcp`, hearsay-tools/squawk#4402).
|
|
3
|
+
*
|
|
4
|
+
* Security invariants (after the global `/api/*` loopback-Host check in local mode; skips global
|
|
5
|
+
* 32 MiB `bodyLimit` buffering via `managesBodyLimit: true`):
|
|
6
|
+
* 1. Reject any request carrying an `Origin` header (`403`) before reading the body.
|
|
7
|
+
* 2. Fail closed (`404`) when no MCP bearer token is configured for this port or env.
|
|
8
|
+
* 3. Require `Authorization: Bearer <token>` verified via SHA-256 + `crypto.timingSafeEqual`
|
|
9
|
+
* (`401` + `WWW-Authenticate: Bearer` on missing, invalid, or Basic auth) before reading the body.
|
|
10
|
+
* 4. Allow `POST` only (`405` + `Allow: POST` on `GET`/`DELETE`/other methods).
|
|
11
|
+
* 5. Enforce a 1 MiB streaming request body limit (`413`) on authenticated `POST`s.
|
|
12
|
+
*/
|
|
13
|
+
import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
|
|
14
|
+
import { registerRuntimeSecret } from '../../core/secret-redaction.js';
|
|
15
|
+
import { authenticateMcpRequest } from '../../mcp-tokens.js';
|
|
16
|
+
import { createOrchestratorMcpServer } from './tools.js';
|
|
17
|
+
export const MCP_HTTP_ROUTE_ID = 'mcp';
|
|
18
|
+
export const MCP_HTTP_PATH = '/api/v1/mcp';
|
|
19
|
+
export const MCP_MAX_BODY_BYTES = 1024 * 1024; // 1 MiB
|
|
20
|
+
export const MCP_KEEP_ALIVE_MS = 15_000;
|
|
21
|
+
/** Parse `Authorization: Bearer <token>`. Rejects missing, Basic, empty, or multi-word headers. */
|
|
22
|
+
export function parseBearerHeader(header) {
|
|
23
|
+
if (!header)
|
|
24
|
+
return null;
|
|
25
|
+
const match = /^Bearer\s+(\S+)$/i.exec(header.trim());
|
|
26
|
+
return match?.[1] ?? null;
|
|
27
|
+
}
|
|
28
|
+
/** Read a request body up to `maxBytes`. Returns `null` when the payload exceeds the cap. */
|
|
29
|
+
async function readBoundedBody(request, maxBytes) {
|
|
30
|
+
const declared = request.headers.get('content-length');
|
|
31
|
+
if (declared !== null) {
|
|
32
|
+
const length = Number(declared);
|
|
33
|
+
if (Number.isFinite(length) && length > maxBytes) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const reader = request.body?.getReader();
|
|
38
|
+
if (!reader)
|
|
39
|
+
return new Uint8Array(0);
|
|
40
|
+
let total = 0;
|
|
41
|
+
const chunks = [];
|
|
42
|
+
try {
|
|
43
|
+
for (;;) {
|
|
44
|
+
const next = await reader.read();
|
|
45
|
+
if (next.done)
|
|
46
|
+
break;
|
|
47
|
+
total += next.value.byteLength;
|
|
48
|
+
if (total > maxBytes) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
chunks.push(next.value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
reader.releaseLock();
|
|
56
|
+
}
|
|
57
|
+
const combined = new Uint8Array(new ArrayBuffer(total));
|
|
58
|
+
let offset = 0;
|
|
59
|
+
for (const chunk of chunks) {
|
|
60
|
+
combined.set(chunk, offset);
|
|
61
|
+
offset += chunk.byteLength;
|
|
62
|
+
}
|
|
63
|
+
return combined;
|
|
64
|
+
}
|
|
65
|
+
function wrapStreamCleanup(body, onDone) {
|
|
66
|
+
let finished = false;
|
|
67
|
+
const finish = () => {
|
|
68
|
+
if (finished)
|
|
69
|
+
return;
|
|
70
|
+
finished = true;
|
|
71
|
+
onDone();
|
|
72
|
+
};
|
|
73
|
+
const reader = body.getReader();
|
|
74
|
+
return new ReadableStream({
|
|
75
|
+
async pull(controller) {
|
|
76
|
+
try {
|
|
77
|
+
const next = await reader.read();
|
|
78
|
+
if (next.done) {
|
|
79
|
+
controller.close();
|
|
80
|
+
finish();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
controller.enqueue(next.value);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
controller.error(error);
|
|
87
|
+
finish();
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
async cancel(reason) {
|
|
91
|
+
try {
|
|
92
|
+
await reader.cancel(reason);
|
|
93
|
+
}
|
|
94
|
+
catch { /* stream already closed */ }
|
|
95
|
+
finish();
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function firstHeaderToken(value) {
|
|
100
|
+
if (!value)
|
|
101
|
+
return null;
|
|
102
|
+
const first = value.split(',')[0]?.trim();
|
|
103
|
+
return first ? first : null;
|
|
104
|
+
}
|
|
105
|
+
function parseRequestUrl(url) {
|
|
106
|
+
try {
|
|
107
|
+
return new URL(url);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function parseOriginAuthority(proto, rawHost) {
|
|
114
|
+
if (!rawHost || /[\s/@\\]/.test(rawHost))
|
|
115
|
+
return null;
|
|
116
|
+
const parsed = parseRequestUrl(`${proto}://${rawHost}`);
|
|
117
|
+
if (!parsed)
|
|
118
|
+
return null;
|
|
119
|
+
const hasExtras = Boolean(parsed.username || parsed.password || parsed.search || parsed.hash);
|
|
120
|
+
return hasExtras || parsed.pathname !== '/' ? null : parsed.origin;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Resolve the cockpit origin returned in MCP task URLs. Behind a hosted reverse proxy, honor
|
|
124
|
+
* `X-Forwarded-Proto` and `X-Forwarded-Host` (falling back to `Host`); in local mode, ignore
|
|
125
|
+
* forwarded headers and use the loopback request host. Invalid authorities fall back safely.
|
|
126
|
+
*/
|
|
127
|
+
export function resolvePublicOrigin(request, context, loopbackOrigin) {
|
|
128
|
+
const requestUrl = parseRequestUrl(request.url);
|
|
129
|
+
const hosted = context.isHostedMode();
|
|
130
|
+
const forwardedProto = hosted ? firstHeaderToken(request.headers.get('x-forwarded-proto'))?.toLowerCase() : undefined;
|
|
131
|
+
const proto = forwardedProto === 'http' || forwardedProto === 'https'
|
|
132
|
+
? forwardedProto
|
|
133
|
+
: requestUrl?.protocol === 'https:' ? 'https' : 'http';
|
|
134
|
+
const rawHost = (hosted ? firstHeaderToken(request.headers.get('x-forwarded-host')) : null)
|
|
135
|
+
?? firstHeaderToken(request.headers.get('host'))
|
|
136
|
+
?? requestUrl?.host
|
|
137
|
+
?? null;
|
|
138
|
+
return parseOriginAuthority(proto, rawHost) ?? loopbackOrigin;
|
|
139
|
+
}
|
|
140
|
+
function unauthorizedResponse() {
|
|
141
|
+
return Response.json({ error: 'unauthorized: valid Bearer token required' }, { status: 401, headers: { 'WWW-Authenticate': 'Bearer' } });
|
|
142
|
+
}
|
|
143
|
+
/** Handle one HTTP request to `/api/v1/mcp`. */
|
|
144
|
+
export async function handleMcpHttpRequest(request, context, options = {}) {
|
|
145
|
+
if (request.headers.get('origin') !== null) {
|
|
146
|
+
return Response.json({ error: 'forbidden: Origin header is not allowed on /api/v1/mcp' }, { status: 403 });
|
|
147
|
+
}
|
|
148
|
+
const env = options.env ?? process.env;
|
|
149
|
+
const port = context.squawkPort();
|
|
150
|
+
const rawToken = parseBearerHeader(request.headers.get('authorization'));
|
|
151
|
+
const auth = authenticateMcpRequest(rawToken, env, port, context.home);
|
|
152
|
+
if (auth.status === 'unconfigured') {
|
|
153
|
+
return Response.json({ error: 'not found' }, { status: 404 });
|
|
154
|
+
}
|
|
155
|
+
if (auth.status === 'unauthorized') {
|
|
156
|
+
return unauthorizedResponse();
|
|
157
|
+
}
|
|
158
|
+
const verified = auth.verified;
|
|
159
|
+
if (rawToken)
|
|
160
|
+
registerRuntimeSecret(rawToken);
|
|
161
|
+
if (request.method !== 'POST') {
|
|
162
|
+
return Response.json({ error: 'method not allowed: use POST /api/v1/mcp' }, { status: 405, headers: { Allow: 'POST' } });
|
|
163
|
+
}
|
|
164
|
+
const bodyBytes = await readBoundedBody(request, MCP_MAX_BODY_BYTES);
|
|
165
|
+
if (bodyBytes === null) {
|
|
166
|
+
return Response.json({ error: 'request body exceeds 1 MiB limit' }, { status: 413 });
|
|
167
|
+
}
|
|
168
|
+
const abortController = new AbortController();
|
|
169
|
+
const onRequestAbort = () => abortController.abort(request.signal.reason);
|
|
170
|
+
if (request.signal.aborted)
|
|
171
|
+
onRequestAbort();
|
|
172
|
+
else
|
|
173
|
+
request.signal.addEventListener('abort', onRequestAbort, { once: true });
|
|
174
|
+
const loopbackOrigin = port !== undefined ? `http://127.0.0.1:${port}` : 'http://127.0.0.1';
|
|
175
|
+
const publicOrigin = resolvePublicOrigin(request, context, loopbackOrigin);
|
|
176
|
+
const inProcessFetch = (input, init) => {
|
|
177
|
+
const rawUrl = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
178
|
+
const target = new URL(rawUrl, loopbackOrigin);
|
|
179
|
+
const internalUrl = `${loopbackOrigin}${target.pathname}${target.search}`;
|
|
180
|
+
return context.fetchApp(new Request(internalUrl, init));
|
|
181
|
+
};
|
|
182
|
+
const server = createOrchestratorMcpServer({
|
|
183
|
+
origin: publicOrigin,
|
|
184
|
+
version: context.version,
|
|
185
|
+
fetch: inProcessFetch,
|
|
186
|
+
allowedProject: verified.project,
|
|
187
|
+
requestSignal: abortController.signal,
|
|
188
|
+
pollMs: options.pollMs,
|
|
189
|
+
heartbeatMs: options.heartbeatMs,
|
|
190
|
+
});
|
|
191
|
+
// Stateless mode: omit sessionIdGenerator so no Mcp-Session-Id is issued.
|
|
192
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
193
|
+
keepAliveMs: options.keepAliveMs ?? MCP_KEEP_ALIVE_MS,
|
|
194
|
+
});
|
|
195
|
+
const cleanup = () => {
|
|
196
|
+
request.signal.removeEventListener('abort', onRequestAbort);
|
|
197
|
+
if (!abortController.signal.aborted)
|
|
198
|
+
abortController.abort();
|
|
199
|
+
void transport.close().catch(() => { });
|
|
200
|
+
void server.close().catch(() => { });
|
|
201
|
+
};
|
|
202
|
+
try {
|
|
203
|
+
await server.connect(transport);
|
|
204
|
+
const forwarded = new Request(request.url, {
|
|
205
|
+
method: 'POST',
|
|
206
|
+
headers: request.headers,
|
|
207
|
+
body: bodyBytes ?? new Uint8Array(0),
|
|
208
|
+
});
|
|
209
|
+
const response = await transport.handleRequest(forwarded);
|
|
210
|
+
const isSse = (response.headers.get('content-type') ?? '').includes('text/event-stream');
|
|
211
|
+
if (isSse && response.body) {
|
|
212
|
+
return new Response(wrapStreamCleanup(response.body, cleanup), {
|
|
213
|
+
status: response.status,
|
|
214
|
+
statusText: response.statusText,
|
|
215
|
+
headers: response.headers,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
cleanup();
|
|
219
|
+
return response;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
cleanup();
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export function createMcpHttpRoute(options = {}) {
|
|
227
|
+
return {
|
|
228
|
+
id: MCP_HTTP_ROUTE_ID,
|
|
229
|
+
method: 'ALL',
|
|
230
|
+
path: MCP_HTTP_PATH,
|
|
231
|
+
managesBodyLimit: true,
|
|
232
|
+
handle: (request, context) => handleMcpHttpRequest(request, context, options),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
export const mcpHttpRoute = createMcpHttpRoute();
|
|
236
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/features/mcp/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,wCAAwC,EAAE,MA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server,
|
|
3
|
-
* hearsay-tools/squawk#4401): registers `hsq mcp`
|
|
4
|
-
* Nothing outside this folder imports it.
|
|
3
|
+
* hearsay-tools/squawk#4401 and hearsay-tools/squawk#4402): registers `hsq mcp` and
|
|
4
|
+
* `POST /api/v1/mcp` through the plugin API only. Nothing outside this folder imports it.
|
|
5
5
|
*/
|
|
6
|
-
import type { CliCommandDefinition, SquawkPluginApi } from '../../plugin/index.ts';
|
|
7
|
-
/** `hsq mcp`:
|
|
6
|
+
import type { CliCommandDefinition, HttpRouteDefinition, SquawkPluginApi } from '../../plugin/index.ts';
|
|
7
|
+
/** `hsq mcp`: stdio MCP server and host-CLI bearer token management (`hsq mcp token`). */
|
|
8
8
|
export declare const mcpCliCommand: CliCommandDefinition;
|
|
9
|
+
/** Stateless Streamable HTTP MCP route (`/api/v1/mcp`), loaded lazily on first request. */
|
|
10
|
+
export declare const mcpHttpRoute: HttpRouteDefinition;
|
|
9
11
|
export default function setup(api: SquawkPluginApi): void;
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
/** `hsq mcp`:
|
|
1
|
+
/** `hsq mcp`: stdio MCP server and host-CLI bearer token management (`hsq mcp token`). */
|
|
2
2
|
export const mcpCliCommand = {
|
|
3
3
|
name: 'mcp',
|
|
4
|
-
usage: [
|
|
4
|
+
usage: [
|
|
5
|
+
' cez mcp [--url <origin>] [--repo <dir>] serve Squawk task tools over MCP stdio (see: mcp --help)',
|
|
6
|
+
' cez mcp token <create|list|revoke> manage bearer tokens for POST /api/v1/mcp',
|
|
7
|
+
],
|
|
5
8
|
parseMode: 'subcommand',
|
|
6
|
-
homeMode: '
|
|
9
|
+
homeMode: 'conditional',
|
|
7
10
|
runtimeMode: 'none',
|
|
8
|
-
load: async () => (await import('./cli.js')).runMcpCommand,
|
|
11
|
+
load: async (home) => async (argv, env) => (await import('./cli.js')).runMcpCommand(argv, env, { home: () => home(env) }),
|
|
12
|
+
};
|
|
13
|
+
/** Stateless Streamable HTTP MCP route (`/api/v1/mcp`), loaded lazily on first request. */
|
|
14
|
+
export const mcpHttpRoute = {
|
|
15
|
+
id: 'mcp',
|
|
16
|
+
method: 'ALL',
|
|
17
|
+
path: '/api/v1/mcp',
|
|
18
|
+
managesBodyLimit: true,
|
|
19
|
+
handle: async (request, context) => (await import('./http.js')).handleMcpHttpRequest(request, context),
|
|
9
20
|
};
|
|
10
21
|
export default function setup(api) {
|
|
11
22
|
api.registerCliCommand(mcpCliCommand);
|
|
23
|
+
api.registerHttpRoute(mcpHttpRoute);
|
|
12
24
|
}
|
|
13
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/features/mcp/index.ts"],"names":[],"mappings":"AAOA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/features/mcp/index.ts"],"names":[],"mappings":"AAOA,0FAA0F;AAC1F,MAAM,CAAC,MAAM,aAAa,GAAyB;IACjD,IAAI,EAAE,KAAK;IACX,KAAK,EAAE;QACL,qGAAqG;QACrG,sFAAsF;KACvF;IACD,SAAS,EAAE,YAAY;IACvB,QAAQ,EAAE,aAAa;IACvB,WAAW,EAAE,MAAM;IACnB,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,CACxC,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;CACjF,CAAC;AAEF,2FAA2F;AAC3F,MAAM,CAAC,MAAM,YAAY,GAAwB;IAC/C,EAAE,EAAE,KAAK;IACT,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,aAAa;IACnB,gBAAgB,EAAE,IAAI;IACtB,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC;CACvG,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,GAAoB;IAChD,GAAG,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC;IACtC,GAAG,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Home } from '../../home/home.ts';
|
|
2
|
+
export declare const MCP_TOKEN_USAGE: string;
|
|
3
|
+
export interface McpTokenCliIo {
|
|
4
|
+
stdout(line: string): void;
|
|
5
|
+
/** Running loopback cockpit ports on this host; tests replace the port scan. */
|
|
6
|
+
runningPorts?: () => Promise<number[]>;
|
|
7
|
+
}
|
|
8
|
+
export declare function scanRunningCockpitPorts(): Promise<number[]>;
|
|
9
|
+
export declare function runMcpTokenCommand(argv: string[], home: Home, io?: McpTokenCliIo): Promise<number>;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hsq mcp token create | list | revoke` (hearsay-tools/squawk#4402): host-CLI management of
|
|
3
|
+
* per-port hashed bearer tokens for `/api/v1/mcp`, mirroring `remote-settings-cli.ts` (ADR 0055).
|
|
4
|
+
* Prints one JSON object per invocation; exit 0 ok, 2 refused, 64 invalid input.
|
|
5
|
+
*/
|
|
6
|
+
import { parseArgs } from 'node:util';
|
|
7
|
+
import { commandText } from '../../home/command.js';
|
|
8
|
+
import { createMcpToken, listMcpTokens, McpTokenRevokeError, revokeMcpToken, } from '../../mcp-tokens.js';
|
|
9
|
+
import { COCKPIT_PORTS } from '../../task-cli/discovery.js';
|
|
10
|
+
export const MCP_TOKEN_USAGE = commandText(`cez mcp token — manage per-port bearer tokens for POST /api/v1/mcp.
|
|
11
|
+
One JSON object per invocation; exit 0 ok, 2 refused, 64 usage.
|
|
12
|
+
|
|
13
|
+
create [--name <label>] [--port <n>] [--project <id>]
|
|
14
|
+
create a bearer token for that cockpit port and print the raw token once.
|
|
15
|
+
Without --port, targets the only cockpit running on 127.0.0.1:4321–4370.
|
|
16
|
+
list [--port <n>] list stored token metadata (never hashes or raw tokens) for one or all ports.
|
|
17
|
+
revoke [<id>] [--port <n>] [--all]
|
|
18
|
+
revoke one token by id (resolving across ports when --port is omitted),
|
|
19
|
+
or revoke all tokens for --port <n> with --all.
|
|
20
|
+
|
|
21
|
+
Takes effect on the next request; no restart. Run on the host as the cockpit user.`);
|
|
22
|
+
const PROBE_TIMEOUT_MS = 800; // bound: one loopback health check per port; a silent port is not a cockpit
|
|
23
|
+
class TokenCliRefusal extends Error {
|
|
24
|
+
exitCode;
|
|
25
|
+
body;
|
|
26
|
+
constructor(exitCode, body) {
|
|
27
|
+
super(String(body.error));
|
|
28
|
+
this.exitCode = exitCode;
|
|
29
|
+
this.body = body;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function probeLoopbackCockpit(port) {
|
|
33
|
+
try {
|
|
34
|
+
const res = await fetch(`http://127.0.0.1:${port}/api/v1/health`, {
|
|
35
|
+
redirect: 'error',
|
|
36
|
+
signal: AbortSignal.timeout(PROBE_TIMEOUT_MS),
|
|
37
|
+
});
|
|
38
|
+
if (!res.ok)
|
|
39
|
+
return null;
|
|
40
|
+
const data = await res.json();
|
|
41
|
+
return typeof data?.version === 'string' ? port : null;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export async function scanRunningCockpitPorts() {
|
|
48
|
+
const found = await Promise.all(COCKPIT_PORTS.map(probeLoopbackCockpit));
|
|
49
|
+
return found.filter((port) => port !== null).sort((a, b) => a - b);
|
|
50
|
+
}
|
|
51
|
+
function parsePort(value) {
|
|
52
|
+
if (value === undefined)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (!/^[1-9]\d{0,4}$/.test(value) || Number(value) > 65_535) {
|
|
55
|
+
throw new TokenCliRefusal(64, {
|
|
56
|
+
ok: false,
|
|
57
|
+
code: 'invalid_input',
|
|
58
|
+
error: `--port must be a port number (1–65535), not "${value}"`,
|
|
59
|
+
usage: MCP_TOKEN_USAGE,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return Number(value);
|
|
63
|
+
}
|
|
64
|
+
async function resolveCreatePort(port, io) {
|
|
65
|
+
if (port !== undefined)
|
|
66
|
+
return port;
|
|
67
|
+
const ports = await (io.runningPorts ?? scanRunningCockpitPorts)();
|
|
68
|
+
if (ports.length === 1)
|
|
69
|
+
return ports[0];
|
|
70
|
+
const error = ports.length === 0
|
|
71
|
+
? 'no cockpit answers on 127.0.0.1 ports 4321–4370; pass --port <n> with its listen port'
|
|
72
|
+
: `several cockpits run on this machine (ports ${ports.join(', ')}); pass --port <n> to choose one`;
|
|
73
|
+
throw new TokenCliRefusal(2, { ok: false, code: 'choose_cockpit', error, ports });
|
|
74
|
+
}
|
|
75
|
+
function parseTokenArgs(argv) {
|
|
76
|
+
try {
|
|
77
|
+
return parseArgs({
|
|
78
|
+
args: argv,
|
|
79
|
+
options: {
|
|
80
|
+
port: { type: 'string' },
|
|
81
|
+
name: { type: 'string' },
|
|
82
|
+
project: { type: 'string' },
|
|
83
|
+
all: { type: 'boolean', default: false },
|
|
84
|
+
help: { type: 'boolean', short: 'h', default: false },
|
|
85
|
+
},
|
|
86
|
+
allowPositionals: true,
|
|
87
|
+
strict: true,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new TokenCliRefusal(64, {
|
|
92
|
+
ok: false,
|
|
93
|
+
code: 'invalid_input',
|
|
94
|
+
error: error instanceof Error ? error.message : 'invalid arguments',
|
|
95
|
+
usage: MCP_TOKEN_USAGE,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function invalidInput(message) {
|
|
100
|
+
throw new TokenCliRefusal(64, { ok: false, code: 'invalid_input', error: message, usage: MCP_TOKEN_USAGE });
|
|
101
|
+
}
|
|
102
|
+
async function runCreateAction(rest, values, port, home, io) {
|
|
103
|
+
if (rest.length > 0)
|
|
104
|
+
invalidInput(`unexpected argument '${rest[0]}'`);
|
|
105
|
+
if (values.all)
|
|
106
|
+
invalidInput('create takes no --all');
|
|
107
|
+
if (values.project !== undefined) {
|
|
108
|
+
const trimmedProject = values.project.trim();
|
|
109
|
+
if (!trimmedProject)
|
|
110
|
+
invalidInput('--project must not be empty');
|
|
111
|
+
if (trimmedProject === 'all')
|
|
112
|
+
invalidInput('--project cannot be "all" (reserved for cross-project listing)');
|
|
113
|
+
}
|
|
114
|
+
const targetPort = await resolveCreatePort(port, io);
|
|
115
|
+
const created = createMcpToken({ port: targetPort, home, name: values.name, project: values.project });
|
|
116
|
+
return {
|
|
117
|
+
ok: true,
|
|
118
|
+
id: created.id,
|
|
119
|
+
name: created.name,
|
|
120
|
+
port: created.port,
|
|
121
|
+
createdAt: created.createdAt,
|
|
122
|
+
...(created.project !== undefined ? { project: created.project } : {}),
|
|
123
|
+
token: created.token,
|
|
124
|
+
path: created.path,
|
|
125
|
+
note: 'Save this token now — only its SHA-256 hash is stored on disk.',
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function runListAction(rest, values, port, home) {
|
|
129
|
+
if (rest.length > 0)
|
|
130
|
+
invalidInput(`unexpected argument '${rest[0]}'`);
|
|
131
|
+
if (values.name !== undefined || values.project !== undefined || values.all) {
|
|
132
|
+
invalidInput('list accepts only --port <n>');
|
|
133
|
+
}
|
|
134
|
+
return { ok: true, ...listMcpTokens(home, port) };
|
|
135
|
+
}
|
|
136
|
+
function runRevokeAction(rest, values, port, home) {
|
|
137
|
+
if (values.name !== undefined || values.project !== undefined) {
|
|
138
|
+
invalidInput('revoke accepts only <id>, --port <n>, and --all');
|
|
139
|
+
}
|
|
140
|
+
if (values.all) {
|
|
141
|
+
if (rest.length > 0)
|
|
142
|
+
invalidInput('revoke --all takes no token id');
|
|
143
|
+
if (port === undefined)
|
|
144
|
+
invalidInput('revoke --all requires --port <n>');
|
|
145
|
+
return { ok: true, ...revokeMcpToken({ home, port, all: true }) };
|
|
146
|
+
}
|
|
147
|
+
if (rest.length !== 1)
|
|
148
|
+
invalidInput('revoke requires a token <id> (or --all --port <n>)');
|
|
149
|
+
return { ok: true, ...revokeMcpToken({ home, id: rest[0], port }) };
|
|
150
|
+
}
|
|
151
|
+
async function runTokenSubcommand(argv, home, io) {
|
|
152
|
+
const { positionals, values } = parseTokenArgs(argv);
|
|
153
|
+
const [action, ...rest] = positionals;
|
|
154
|
+
const port = parsePort(values.port);
|
|
155
|
+
if (action === 'create')
|
|
156
|
+
return runCreateAction(rest, values, port, home, io);
|
|
157
|
+
if (action === 'list')
|
|
158
|
+
return runListAction(rest, values, port, home);
|
|
159
|
+
if (action === 'revoke')
|
|
160
|
+
return runRevokeAction(rest, values, port, home);
|
|
161
|
+
invalidInput(action === undefined ? 'missing command (create, list, revoke)' : `unknown command '${action}'`);
|
|
162
|
+
}
|
|
163
|
+
export async function runMcpTokenCommand(argv, home, io = { stdout: (line) => console.log(line) }) {
|
|
164
|
+
if (argv.length === 0 || ['help', '--help', '-h'].includes(argv[0] ?? '') || argv.includes('--help') || argv.includes('-h')) {
|
|
165
|
+
io.stdout(MCP_TOKEN_USAGE);
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
io.stdout(JSON.stringify(await runTokenSubcommand(argv, home, io), null, 2));
|
|
170
|
+
return 0;
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
if (error instanceof McpTokenRevokeError) {
|
|
174
|
+
io.stdout(JSON.stringify({
|
|
175
|
+
ok: false,
|
|
176
|
+
code: error.code,
|
|
177
|
+
error: error.message,
|
|
178
|
+
...(error.ports ? { ports: error.ports } : {}),
|
|
179
|
+
}, null, 2));
|
|
180
|
+
return 2;
|
|
181
|
+
}
|
|
182
|
+
if (!(error instanceof TokenCliRefusal))
|
|
183
|
+
throw error;
|
|
184
|
+
io.stdout(JSON.stringify(error.body, null, 2));
|
|
185
|
+
return error.exitCode;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=token-cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-cli.js","sourceRoot":"","sources":["../../../src/features/mcp/token-cli.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EACL,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,cAAc,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC;;;;;;;;;;;mFAWwC,CAAC,CAAC;AAErF,MAAM,gBAAgB,GAAG,GAAG,CAAC,CAAC,4EAA4E;AAQ1G,MAAM,eAAgB,SAAQ,KAAK;IACxB,QAAQ,CAAS;IACjB,IAAI,CAA0B;IAEvC,YAAY,QAAgB,EAAE,IAA6B;QACzD,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,KAAK,UAAU,oBAAoB,CAAC,IAAY;IAC9C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,oBAAoB,IAAI,gBAAgB,EAAE;YAChE,QAAQ,EAAE,OAAO;YACjB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,gBAAgB,CAAC;SAC9C,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QACzB,MAAM,I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,IAAI,CAAC,EAAE,CAAC;QAC5H,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC3B,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,CAAC;QACH,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7E,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,mBAAmB,EAAE,CAAC;YACzC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;gBACvB,EAAE,EAAE,KAAK;gBACT,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,KAAK,EAAE,KAAK,CAAC,OAAO;gBACpB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC/C,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACb,OAAO,CAAC,CAAC;QACX,CAAC;QACD,IAAI,CAAC,CAAC,KAAK,YAAY,eAAe,CAAC;YAAE,MAAM,KAAK,CAAC;QACrD,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC,QAAQ,CAAC;IACxB,CAAC;AACH,CAAC"}
|
|
@@ -8,6 +8,10 @@ export interface OrchestratorMcpOptions {
|
|
|
8
8
|
fetch?: FetchFn | undefined;
|
|
9
9
|
pollMs?: number | undefined;
|
|
10
10
|
heartbeatMs?: number | undefined;
|
|
11
|
+
/** When set (project-scoped bearer token), restricts `project_list` and rejects all other projects. */
|
|
12
|
+
allowedProject?: string | undefined;
|
|
13
|
+
/** Optional external abort signal (such as HTTP client disconnect) combined with MCP `extra.signal`. */
|
|
14
|
+
requestSignal?: AbortSignal | undefined;
|
|
11
15
|
}
|
|
12
16
|
export declare function formatMcpToolError(error: unknown): {
|
|
13
17
|
isError: true;
|
|
@@ -97,10 +97,19 @@ function parseStatusFilter(value) {
|
|
|
97
97
|
}
|
|
98
98
|
return new Set(entries);
|
|
99
99
|
}
|
|
100
|
+
function assertAllowedProject(project, ctx) {
|
|
101
|
+
if (ctx.allowedProject !== undefined && (project === 'all' || project !== ctx.allowedProject)) {
|
|
102
|
+
throw new TaskCliError(2, {
|
|
103
|
+
code: 'forbidden',
|
|
104
|
+
error: `bearer token is scoped to project '${ctx.allowedProject}' and cannot access '${project}'`,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
100
108
|
const PROJECT_PROP = { type: 'string', minLength: 1, description: 'Registered project ID from project_list (required; no default project).' };
|
|
101
109
|
const TASK_ID_PROP = { type: 'string', minLength: 1, description: 'Task run ID.' };
|
|
102
110
|
async function invokeTaskStart(rawArgs, ctx) {
|
|
103
111
|
const args = taskStartInputSchema.parse(rawArgs ?? {});
|
|
112
|
+
assertAllowedProject(args.project, ctx);
|
|
104
113
|
const cockpit = await resolveProjectCockpit(ctx.origin, args.project, { fetch: ctx.fetch, signal: ctx.signal });
|
|
105
114
|
const started = await startTask(cockpit, {
|
|
106
115
|
task: args.task,
|
|
@@ -143,6 +152,7 @@ function idActionTool(name, description, run) {
|
|
|
143
152
|
},
|
|
144
153
|
invoke: async (rawArgs, ctx) => {
|
|
145
154
|
const args = taskIdInputSchema.parse(rawArgs ?? {});
|
|
155
|
+
assertAllowedProject(args.project, ctx);
|
|
146
156
|
const cockpit = await resolveProjectCockpit(ctx.origin, args.project, { fetch: ctx.fetch, signal: ctx.signal });
|
|
147
157
|
const result = await run(cockpit, args.id, ctx.signal);
|
|
148
158
|
return { project: cockpit.projectId, ...result };
|
|
@@ -158,7 +168,10 @@ const TOOLS = [
|
|
|
158
168
|
},
|
|
159
169
|
invoke: async (rawArgs, ctx) => {
|
|
160
170
|
projectListInputSchema.parse(rawArgs ?? {});
|
|
161
|
-
|
|
171
|
+
const listed = await listProjects(ctx.origin, { fetch: ctx.fetch, signal: ctx.signal });
|
|
172
|
+
if (ctx.allowedProject === undefined)
|
|
173
|
+
return listed;
|
|
174
|
+
return { projects: listed.projects.filter((entry) => entry.id === ctx.allowedProject) };
|
|
162
175
|
},
|
|
163
176
|
},
|
|
164
177
|
{
|
|
@@ -207,6 +220,7 @@ const TOOLS = [
|
|
|
207
220
|
},
|
|
208
221
|
invoke: async (rawArgs, ctx) => {
|
|
209
222
|
const args = taskSendInputSchema.parse(rawArgs ?? {});
|
|
223
|
+
assertAllowedProject(args.project, ctx);
|
|
210
224
|
const cockpit = await resolveProjectCockpit(ctx.origin, args.project, { fetch: ctx.fetch, signal: ctx.signal });
|
|
211
225
|
const result = await sendTaskMessage(cockpit, {
|
|
212
226
|
id: args.id,
|
|
@@ -242,6 +256,7 @@ const TOOLS = [
|
|
|
242
256
|
},
|
|
243
257
|
invoke: async (rawArgs, ctx) => {
|
|
244
258
|
const args = taskStatusInputSchema.parse(rawArgs ?? {});
|
|
259
|
+
assertAllowedProject(args.project, ctx);
|
|
245
260
|
const cockpit = await resolveProjectCockpit(ctx.origin, args.project, { fetch: ctx.fetch, signal: ctx.signal });
|
|
246
261
|
const status = await getTaskStatus(cockpit, {
|
|
247
262
|
id: args.id,
|
|
@@ -271,6 +286,7 @@ const TOOLS = [
|
|
|
271
286
|
},
|
|
272
287
|
invoke: async (rawArgs, ctx) => {
|
|
273
288
|
const args = taskLogInputSchema.parse(rawArgs ?? {});
|
|
289
|
+
assertAllowedProject(args.project, ctx);
|
|
274
290
|
const cockpit = await resolveProjectCockpit(ctx.origin, args.project, { fetch: ctx.fetch, signal: ctx.signal });
|
|
275
291
|
const snapshot = await getTaskLog(cockpit, {
|
|
276
292
|
id: args.id,
|
|
@@ -305,6 +321,7 @@ const TOOLS = [
|
|
|
305
321
|
},
|
|
306
322
|
invoke: async (rawArgs, ctx) => {
|
|
307
323
|
const args = taskDiffInputSchema.parse(rawArgs ?? {});
|
|
324
|
+
assertAllowedProject(args.project, ctx);
|
|
308
325
|
const cockpit = await resolveProjectCockpit(ctx.origin, args.project, { fetch: ctx.fetch, signal: ctx.signal });
|
|
309
326
|
const result = await getTaskDiff(cockpit, {
|
|
310
327
|
id: args.id,
|
|
@@ -334,6 +351,7 @@ const TOOLS = [
|
|
|
334
351
|
},
|
|
335
352
|
invoke: async (rawArgs, ctx) => {
|
|
336
353
|
const args = taskWaitInputSchema.parse(rawArgs ?? {});
|
|
354
|
+
assertAllowedProject(args.project, ctx);
|
|
337
355
|
const cockpit = await resolveProjectCockpit(ctx.origin, args.project, { fetch: ctx.fetch, signal: ctx.signal });
|
|
338
356
|
const mode = args.mode ?? 'any';
|
|
339
357
|
const until = args.until ?? 'attention';
|
|
@@ -381,9 +399,10 @@ const TOOLS = [
|
|
|
381
399
|
},
|
|
382
400
|
invoke: async (rawArgs, ctx) => {
|
|
383
401
|
const args = taskListInputSchema.parse(rawArgs ?? {});
|
|
402
|
+
assertAllowedProject(args.project, ctx);
|
|
384
403
|
const statuses = parseStatusFilter(args.status);
|
|
385
404
|
const limit = args.limit ?? 20;
|
|
386
|
-
if (args.project === 'all') {
|
|
405
|
+
if (args.project === 'all' && ctx.allowedProject === undefined) {
|
|
387
406
|
return listAllProjectsTasks(ctx.origin, {
|
|
388
407
|
statuses,
|
|
389
408
|
limit,
|
|
@@ -456,13 +475,15 @@ export function createOrchestratorMcpServer(options) {
|
|
|
456
475
|
});
|
|
457
476
|
}
|
|
458
477
|
: undefined;
|
|
478
|
+
const signal = options.requestSignal ? AbortSignal.any([extra.signal, options.requestSignal]) : extra.signal;
|
|
459
479
|
try {
|
|
460
480
|
const data = await tool.invoke(request.params.arguments, {
|
|
461
481
|
origin: options.origin,
|
|
462
482
|
fetch: options.fetch,
|
|
463
483
|
pollMs: options.pollMs,
|
|
464
484
|
heartbeatMs: options.heartbeatMs,
|
|
465
|
-
|
|
485
|
+
allowedProject: options.allowedProject,
|
|
486
|
+
signal,
|
|
466
487
|
sendProgress,
|
|
467
488
|
});
|
|
468
489
|
return { content: [{ type: 'text', text: JSON.stringify(data) }] };
|