@particle-academy/agent-integrations 0.5.0 → 0.6.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.
@@ -0,0 +1,134 @@
1
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
+
3
+ /**
4
+ * RelayBroker — pure logic for the SSE+POST tunnel described in
5
+ * docs/relay-protocol.md, hostable in any Node-compatible runtime
6
+ * (Node, Bun, Deno-with-Node-compat, Cloudflare Workers via the Web
7
+ * standards subset). No HTTP framework opinions; this class just
8
+ * stores sessions, validates tokens, enqueues frames, and produces
9
+ * SSE event payloads ready to flush.
10
+ *
11
+ * const broker = new RelayBroker();
12
+ * const reg = broker.register("session-id", "token"); // ok / error
13
+ * broker.inbox("session-id", "token", '{"jsonrpc":"2.0",…}'); // enqueue inbound
14
+ * const sub = broker.subscribe("session-id", "token", "inbound");
15
+ * for await (const payload of sub.frames()) yield encodeSse(payload);
16
+ *
17
+ * Storage is an in-memory Map by default — fine for a single relay
18
+ * process. To run multiple instances behind a load balancer, swap
19
+ * `MemoryStore` for a Redis-backed equivalent (same Store interface).
20
+ */
21
+ type Direction = "inbound" | "outbound";
22
+ type Session = {
23
+ id: string;
24
+ /** SHA-256 hex of the original token. Compared with timing-safe equals. */
25
+ tokenHash: string;
26
+ /** Last touched (ms since epoch). Used for TTL cleanup. */
27
+ lastSeen: number;
28
+ };
29
+ type Subscriber = {
30
+ id: string;
31
+ direction: Direction;
32
+ queue: string[];
33
+ resolveNext: ((frame: string | null) => void) | null;
34
+ };
35
+ type RelayBrokerOptions = {
36
+ /** Sessions auto-expire after this many ms of inactivity. Default 4h. */
37
+ ttlMs?: number;
38
+ /** Cleanup tick interval in ms. Default 60 000. */
39
+ reapIntervalMs?: number;
40
+ /** Bring-your-own storage layer (redis, etc.). Defaults to in-memory. */
41
+ store?: Store;
42
+ };
43
+ interface Store {
44
+ putSession(s: Session): void;
45
+ getSession(id: string): Session | undefined;
46
+ deleteSession(id: string): void;
47
+ /** Used by the reap tick — return ids whose lastSeen < cutoff. */
48
+ expiredSessionIds(cutoff: number): string[];
49
+ }
50
+ declare class RelayBroker {
51
+ private readonly ttlMs;
52
+ private readonly store;
53
+ /** Per-session, per-direction subscriber list. */
54
+ private subs;
55
+ private reaper?;
56
+ constructor(opts?: RelayBrokerOptions);
57
+ dispose(): void;
58
+ /** Register a session id + token. Idempotent — same id+token re-registers,
59
+ * different token fails. */
60
+ register(id: string, token: string): {
61
+ ok: true;
62
+ } | {
63
+ ok: false;
64
+ reason: string;
65
+ };
66
+ unregister(id: string, token: string): boolean;
67
+ /** Validate an authenticated touch and slide the TTL forward. */
68
+ validate(id: string, token: string): boolean;
69
+ /** Push a frame onto the inbound queue (external agent → browser). */
70
+ inbox(id: string, token: string, payload: string): boolean;
71
+ /** Push a frame onto the outbound queue (browser server → external agents). */
72
+ outbox(id: string, token: string, payload: string): boolean;
73
+ /**
74
+ * Subscribe to a session's queue for one direction. Returns an iterable
75
+ * the caller (an HTTP handler) pumps as SSE.
76
+ */
77
+ subscribe(id: string, token: string, direction: Direction): SubscribeResult;
78
+ private getDirSubs;
79
+ private fanOut;
80
+ private isFrame;
81
+ private reap;
82
+ }
83
+ type SubscribeResult = {
84
+ ok: false;
85
+ reason: string;
86
+ } | {
87
+ ok: true;
88
+ subscriberId: string;
89
+ frames: AsyncGenerator<string, void, void>;
90
+ unsubscribe: () => void;
91
+ };
92
+
93
+ /**
94
+ * Node HTTP adapter for {@link RelayBroker}. Returns a single request
95
+ * handler plus per-route handlers, so you can either drop it into
96
+ * `http.createServer(...)` directly or mount the individual handlers
97
+ * onto your existing Node HTTP framework (Express, Hono w/ node-adapter,
98
+ * native http).
99
+ *
100
+ * const relay = createNodeRelay({ pathPrefix: "/mcp-relay" });
101
+ * http.createServer(relay.handler).listen(8787);
102
+ *
103
+ * // Or piecemeal:
104
+ * app.post("/mcp-relay/register", relay.register);
105
+ * app.post("/mcp-relay/:s/inbox", relay.inbox);
106
+ * app.post("/mcp-relay/:s/outbox", relay.outbox);
107
+ * app.get ("/mcp-relay/:s/events", relay.events);
108
+ * app.post("/mcp-relay/:s/unregister", relay.unregister);
109
+ */
110
+ type NodeRelayOptions = RelayBrokerOptions & {
111
+ /** URL path prefix (without trailing slash). Default `""` — handlers
112
+ * expect paths like `/register`, `/{id}/inbox`, etc. directly. */
113
+ pathPrefix?: string;
114
+ /** Comma-separated origins (or `*`) for CORS. Default `*` — relays
115
+ * are typically called cross-origin from the demo host. */
116
+ corsAllowOrigin?: string;
117
+ };
118
+ type NodeHandler = (req: IncomingMessage, res: ServerResponse) => unknown | Promise<unknown>;
119
+ type NodeRelay = {
120
+ broker: RelayBroker;
121
+ /** Single-handler shape — routes internally based on method + URL. */
122
+ handler: NodeHandler;
123
+ /** Per-route handlers. Each handler ignores the URL prefix and
124
+ * acts on the path remainder, so you can mount them under any
125
+ * prefix in your existing app. */
126
+ register: NodeHandler;
127
+ inbox: NodeHandler;
128
+ outbox: NodeHandler;
129
+ events: NodeHandler;
130
+ unregister: NodeHandler;
131
+ };
132
+ declare function createNodeRelay(opts?: NodeRelayOptions): NodeRelay;
133
+
134
+ export { type Direction, type NodeHandler, type NodeRelay, type NodeRelayOptions, RelayBroker, type RelayBrokerOptions, type Session, type Store, type Subscriber, createNodeRelay };
@@ -0,0 +1,483 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var http = require('http');
5
+ var url = require('url');
6
+ var crypto = require('crypto');
7
+
8
+ var MemoryStore = class {
9
+ constructor() {
10
+ this.sessions = /* @__PURE__ */ new Map();
11
+ }
12
+ putSession(s) {
13
+ this.sessions.set(s.id, s);
14
+ }
15
+ getSession(id) {
16
+ return this.sessions.get(id);
17
+ }
18
+ deleteSession(id) {
19
+ this.sessions.delete(id);
20
+ }
21
+ expiredSessionIds(cutoff) {
22
+ const out = [];
23
+ for (const [id, s] of this.sessions) if (s.lastSeen < cutoff) out.push(id);
24
+ return out;
25
+ }
26
+ };
27
+ var SESSION_ID_PATTERN = /^[A-Za-z0-9_-]{4,64}$/;
28
+ var RelayBroker = class {
29
+ constructor(opts = {}) {
30
+ /** Per-session, per-direction subscriber list. */
31
+ this.subs = /* @__PURE__ */ new Map();
32
+ this.ttlMs = opts.ttlMs ?? 4 * 60 * 60 * 1e3;
33
+ this.store = opts.store ?? new MemoryStore();
34
+ const tick = opts.reapIntervalMs ?? 6e4;
35
+ if (tick > 0) {
36
+ this.reaper = setInterval(() => this.reap(), tick);
37
+ if (typeof this.reaper.unref === "function") {
38
+ this.reaper.unref();
39
+ }
40
+ }
41
+ }
42
+ dispose() {
43
+ if (this.reaper) clearInterval(this.reaper);
44
+ this.subs.clear();
45
+ }
46
+ /** Register a session id + token. Idempotent — same id+token re-registers,
47
+ * different token fails. */
48
+ register(id, token) {
49
+ if (!SESSION_ID_PATTERN.test(id)) return { ok: false, reason: "invalid_session_id" };
50
+ if (typeof token !== "string" || token.length < 16 || token.length > 128) {
51
+ return { ok: false, reason: "invalid_token" };
52
+ }
53
+ const existing = this.store.getSession(id);
54
+ const hash = sha256Hex(token);
55
+ if (existing) {
56
+ if (!timingSafeEqualHex(existing.tokenHash, hash)) return { ok: false, reason: "session_taken" };
57
+ existing.lastSeen = Date.now();
58
+ this.store.putSession(existing);
59
+ return { ok: true };
60
+ }
61
+ this.store.putSession({ id, tokenHash: hash, lastSeen: Date.now() });
62
+ return { ok: true };
63
+ }
64
+ unregister(id, token) {
65
+ if (!this.validate(id, token)) return false;
66
+ this.store.deleteSession(id);
67
+ this.subs.delete(id);
68
+ return true;
69
+ }
70
+ /** Validate an authenticated touch and slide the TTL forward. */
71
+ validate(id, token) {
72
+ if (!id || !token) return false;
73
+ const s = this.store.getSession(id);
74
+ if (!s) return false;
75
+ if (!timingSafeEqualHex(s.tokenHash, sha256Hex(token))) return false;
76
+ s.lastSeen = Date.now();
77
+ this.store.putSession(s);
78
+ return true;
79
+ }
80
+ /** Push a frame onto the inbound queue (external agent → browser). */
81
+ inbox(id, token, payload) {
82
+ if (!this.validate(id, token)) return false;
83
+ if (!this.isFrame(payload)) return false;
84
+ this.fanOut(id, "inbound", payload);
85
+ return true;
86
+ }
87
+ /** Push a frame onto the outbound queue (browser server → external agents). */
88
+ outbox(id, token, payload) {
89
+ if (!this.validate(id, token)) return false;
90
+ if (!this.isFrame(payload)) return false;
91
+ this.fanOut(id, "outbound", payload);
92
+ return true;
93
+ }
94
+ /**
95
+ * Subscribe to a session's queue for one direction. Returns an iterable
96
+ * the caller (an HTTP handler) pumps as SSE.
97
+ */
98
+ subscribe(id, token, direction) {
99
+ if (!this.validate(id, token)) return { ok: false, reason: "invalid_token" };
100
+ const subscriberId = crypto.randomBytes(8).toString("hex");
101
+ const subscriber = { id: subscriberId, direction, queue: [], resolveNext: null };
102
+ this.getDirSubs(id, direction).set(subscriberId, subscriber);
103
+ if (direction === "outbound") {
104
+ this.fanOut(
105
+ id,
106
+ "inbound",
107
+ JSON.stringify({
108
+ jsonrpc: "2.0",
109
+ method: "notifications/peer_joined",
110
+ params: { subscriberId, ts: Date.now() }
111
+ })
112
+ );
113
+ }
114
+ const unsubscribe = () => {
115
+ this.getDirSubs(id, direction).delete(subscriberId);
116
+ if (direction === "outbound") {
117
+ this.fanOut(
118
+ id,
119
+ "inbound",
120
+ JSON.stringify({
121
+ jsonrpc: "2.0",
122
+ method: "notifications/peer_left",
123
+ params: { subscriberId, ts: Date.now() }
124
+ })
125
+ );
126
+ }
127
+ };
128
+ const frames = async function* () {
129
+ while (true) {
130
+ if (this.queue.length > 0) {
131
+ const next2 = this.queue.shift();
132
+ if (next2 !== void 0) yield next2;
133
+ continue;
134
+ }
135
+ const next = await new Promise((resolve) => {
136
+ this.resolveNext = resolve;
137
+ });
138
+ this.resolveNext = null;
139
+ if (next === null) return;
140
+ yield next;
141
+ }
142
+ }.bind(subscriber);
143
+ return {
144
+ ok: true,
145
+ subscriberId,
146
+ frames: frames(),
147
+ unsubscribe: () => {
148
+ subscriber.resolveNext?.(null);
149
+ unsubscribe();
150
+ }
151
+ };
152
+ }
153
+ // ────────────────────────────────────────────────────────────── internals
154
+ getDirSubs(sessionId, direction) {
155
+ let bySession = this.subs.get(sessionId);
156
+ if (!bySession) {
157
+ bySession = /* @__PURE__ */ new Map();
158
+ this.subs.set(sessionId, bySession);
159
+ }
160
+ let byDir = bySession.get(direction);
161
+ if (!byDir) {
162
+ byDir = /* @__PURE__ */ new Map();
163
+ bySession.set(direction, byDir);
164
+ }
165
+ return byDir;
166
+ }
167
+ fanOut(sessionId, direction, payload) {
168
+ const dir = this.subs.get(sessionId)?.get(direction);
169
+ if (!dir) return;
170
+ for (const sub of dir.values()) {
171
+ sub.queue.push(payload);
172
+ sub.resolveNext?.(sub.queue.shift() ?? null);
173
+ }
174
+ }
175
+ isFrame(payload) {
176
+ return payload.length > 0 && payload.includes('"jsonrpc"');
177
+ }
178
+ reap() {
179
+ const cutoff = Date.now() - this.ttlMs;
180
+ for (const id of this.store.expiredSessionIds(cutoff)) {
181
+ const dirs = this.subs.get(id);
182
+ if (dirs) {
183
+ for (const dir of dirs.values()) {
184
+ for (const sub of dir.values()) sub.resolveNext?.(null);
185
+ }
186
+ }
187
+ this.subs.delete(id);
188
+ this.store.deleteSession(id);
189
+ }
190
+ }
191
+ };
192
+ function sha256Hex(input) {
193
+ return crypto.createHash("sha256").update(input).digest("hex");
194
+ }
195
+ function timingSafeEqualHex(a, b) {
196
+ if (a.length !== b.length) return false;
197
+ return crypto.timingSafeEqual(Buffer.from(a, "hex"), Buffer.from(b, "hex"));
198
+ }
199
+
200
+ // src/relay-server/node.ts
201
+ function createNodeRelay(opts = {}) {
202
+ const broker = new RelayBroker(opts);
203
+ const prefix = (opts.pathPrefix ?? "").replace(/\/$/, "");
204
+ const cors = opts.corsAllowOrigin ?? "*";
205
+ function setCorsHeaders(res) {
206
+ res.setHeader("access-control-allow-origin", cors);
207
+ res.setHeader("access-control-allow-methods", "GET, POST, OPTIONS");
208
+ res.setHeader("access-control-allow-headers", "content-type, x-csrf-token, accept");
209
+ res.setHeader("access-control-max-age", "86400");
210
+ }
211
+ function readBody(req) {
212
+ return new Promise((resolve, reject) => {
213
+ const chunks = [];
214
+ let bytes = 0;
215
+ req.on("data", (chunk) => {
216
+ bytes += chunk.length;
217
+ if (bytes > 256 * 1024) {
218
+ reject(new Error("payload_too_large"));
219
+ req.destroy();
220
+ return;
221
+ }
222
+ chunks.push(chunk);
223
+ });
224
+ req.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
225
+ req.on("error", reject);
226
+ });
227
+ }
228
+ function json(res, status, body) {
229
+ res.statusCode = status;
230
+ res.setHeader("content-type", "application/json");
231
+ res.end(JSON.stringify(body));
232
+ }
233
+ function getQuery(req) {
234
+ const host = req.headers.host || "x";
235
+ const u = new url.URL(req.url || "/", `http://${host}`);
236
+ return u.searchParams;
237
+ }
238
+ function getPathname(req) {
239
+ const host = req.headers.host || "x";
240
+ const u = new url.URL(req.url || "/", `http://${host}`);
241
+ return u.pathname;
242
+ }
243
+ const register = async (req, res) => {
244
+ setCorsHeaders(res);
245
+ if (req.method === "OPTIONS") {
246
+ res.statusCode = 204;
247
+ return res.end();
248
+ }
249
+ if (req.method !== "POST") return json(res, 405, { error: "method_not_allowed" });
250
+ let body;
251
+ try {
252
+ body = await readBody(req);
253
+ } catch (e) {
254
+ return json(res, 413, { error: e instanceof Error ? e.message : "payload_error" });
255
+ }
256
+ let parsed;
257
+ try {
258
+ parsed = JSON.parse(body);
259
+ } catch {
260
+ return json(res, 400, { error: "invalid_json" });
261
+ }
262
+ const { session, token } = parsed ?? {};
263
+ if (typeof session !== "string" || typeof token !== "string") {
264
+ return json(res, 400, { error: "missing_fields" });
265
+ }
266
+ const result = broker.register(session, token);
267
+ if (!result.ok) return json(res, 401, { error: result.reason });
268
+ return json(res, 200, { ok: true });
269
+ };
270
+ function makeSessionHandler(direction) {
271
+ return async (req, res) => {
272
+ setCorsHeaders(res);
273
+ if (req.method === "OPTIONS") {
274
+ res.statusCode = 204;
275
+ return res.end();
276
+ }
277
+ if (req.method !== "POST") return json(res, 405, { error: "method_not_allowed" });
278
+ const session = extractSession(req, prefix);
279
+ if (!session) return json(res, 400, { error: "missing_session" });
280
+ const token = getQuery(req).get("token") ?? "";
281
+ if (direction === "unregister") {
282
+ const ok2 = broker.unregister(session, token);
283
+ return json(res, ok2 ? 200 : 401, ok2 ? { ok: true } : { error: "invalid_token" });
284
+ }
285
+ let body;
286
+ try {
287
+ body = await readBody(req);
288
+ } catch (e) {
289
+ return json(res, 413, { error: e instanceof Error ? e.message : "payload_error" });
290
+ }
291
+ const ok = direction === "inbound" ? broker.inbox(session, token, body) : broker.outbox(session, token, body);
292
+ return json(res, ok ? 200 : 401, ok ? { ok: true } : { error: "invalid_token_or_frame" });
293
+ };
294
+ }
295
+ const inbox = makeSessionHandler("inbound");
296
+ const outbox = makeSessionHandler("outbound");
297
+ const unregister = makeSessionHandler("unregister");
298
+ const events = async (req, res) => {
299
+ setCorsHeaders(res);
300
+ if (req.method === "OPTIONS") {
301
+ res.statusCode = 204;
302
+ return res.end();
303
+ }
304
+ if (req.method !== "GET") return json(res, 405, { error: "method_not_allowed" });
305
+ const session = extractSession(req, prefix);
306
+ if (!session) return json(res, 400, { error: "missing_session" });
307
+ const q = getQuery(req);
308
+ const token = q.get("token") ?? "";
309
+ const direction = q.get("direction") === "outbound" ? "outbound" : "inbound";
310
+ const sub = broker.subscribe(session, token, direction);
311
+ if (!sub.ok) {
312
+ res.statusCode = 401;
313
+ res.setHeader("content-type", "text/event-stream");
314
+ res.write(`event: error
315
+ data: ${sub.reason}
316
+
317
+ `);
318
+ return res.end();
319
+ }
320
+ res.statusCode = 200;
321
+ res.setHeader("content-type", "text/event-stream");
322
+ res.setHeader("cache-control", "no-cache");
323
+ res.setHeader("connection", "keep-alive");
324
+ res.setHeader("x-accel-buffering", "no");
325
+ res.write("retry: 2000\n\n");
326
+ flush(res);
327
+ let heartbeat = setInterval(() => {
328
+ res.write(": keepalive\n\n");
329
+ flush(res);
330
+ }, 15e3);
331
+ if (heartbeat && typeof heartbeat.unref === "function") {
332
+ heartbeat.unref();
333
+ }
334
+ const cleanup = () => {
335
+ if (heartbeat) {
336
+ clearInterval(heartbeat);
337
+ heartbeat = null;
338
+ }
339
+ sub.unsubscribe();
340
+ };
341
+ req.on("close", cleanup);
342
+ req.on("error", cleanup);
343
+ try {
344
+ for await (const frame of sub.frames) {
345
+ res.write(`event: mcp
346
+ data: ${frame}
347
+
348
+ `);
349
+ flush(res);
350
+ }
351
+ } catch {
352
+ } finally {
353
+ cleanup();
354
+ res.end();
355
+ }
356
+ };
357
+ const handler = async (req, res) => {
358
+ const pathname = getPathname(req);
359
+ if (!pathname.startsWith(prefix + "/")) {
360
+ return json(res, 404, { error: "not_found" });
361
+ }
362
+ const rest = pathname.slice(prefix.length);
363
+ if (rest === "/register") return register(req, res);
364
+ const m = /^\/([A-Za-z0-9_-]{4,64})\/(inbox|outbox|events|unregister)$/.exec(rest);
365
+ if (!m) return json(res, 404, { error: "not_found" });
366
+ const route = m[2];
367
+ if (route === "inbox") return inbox(req, res);
368
+ if (route === "outbox") return outbox(req, res);
369
+ if (route === "events") return events(req, res);
370
+ if (route === "unregister") return unregister(req, res);
371
+ return json(res, 404, { error: "not_found" });
372
+ };
373
+ return { broker, handler, register, inbox, outbox, events, unregister };
374
+ }
375
+ function extractSession(req, prefix) {
376
+ const host = req.headers.host || "x";
377
+ const u = new url.URL(req.url || "/", `http://${host}`);
378
+ const path = u.pathname;
379
+ if (prefix && !path.startsWith(prefix + "/")) return null;
380
+ const rest = prefix ? path.slice(prefix.length) : path;
381
+ const m = /^\/([A-Za-z0-9_-]{4,64})\//.exec(rest);
382
+ return m ? m[1] : null;
383
+ }
384
+ function flush(res) {
385
+ const r = res;
386
+ r.flush?.();
387
+ }
388
+
389
+ // src/relay-server/cli.ts
390
+ async function main() {
391
+ const argv = process.argv.slice(2);
392
+ let port = Number(process.env.PORT ?? 8787);
393
+ let host = process.env.HOST ?? "0.0.0.0";
394
+ let prefix = process.env.PREFIX ?? "";
395
+ let ttlMs = Number(process.env.TTL_MS ?? 4 * 60 * 60 * 1e3);
396
+ let cors = process.env.CORS_ALLOW_ORIGIN ?? "*";
397
+ for (let i = 0; i < argv.length; i++) {
398
+ const a = argv[i];
399
+ switch (a) {
400
+ case "--port":
401
+ port = Number(argv[++i]);
402
+ break;
403
+ case "--host":
404
+ host = argv[++i];
405
+ break;
406
+ case "--prefix":
407
+ prefix = argv[++i];
408
+ break;
409
+ case "--ttl-ms":
410
+ ttlMs = Number(argv[++i]);
411
+ break;
412
+ case "--cors":
413
+ cors = argv[++i];
414
+ break;
415
+ case "-h":
416
+ case "--help":
417
+ process.stdout.write(HELP);
418
+ process.exit(0);
419
+ default:
420
+ process.stderr.write(`[relay] unknown flag: ${a}
421
+ `);
422
+ process.exit(2);
423
+ }
424
+ }
425
+ if (!Number.isFinite(port) || port <= 0) {
426
+ process.stderr.write(`[relay] invalid --port: ${port}
427
+ `);
428
+ process.exit(2);
429
+ }
430
+ const relay = createNodeRelay({ pathPrefix: prefix, ttlMs, corsAllowOrigin: cors });
431
+ const server = http.createServer((req, res) => {
432
+ const url = req.url || "/";
433
+ if ((url === "/" || url === "/healthz" || url === prefix + "/") && req.method === "GET") {
434
+ res.statusCode = 200;
435
+ res.setHeader("content-type", "application/json");
436
+ res.end(JSON.stringify({ ok: true, service: "agent-integrations-relay" }));
437
+ return;
438
+ }
439
+ relay.handler(req, res);
440
+ });
441
+ server.listen(port, host, () => {
442
+ process.stdout.write(
443
+ `[relay] listening on http://${host}:${port}${prefix || ""} (ttl=${Math.round(ttlMs / 1e3)}s, cors=${cors})
444
+ `
445
+ );
446
+ });
447
+ const shutdown = () => {
448
+ process.stdout.write("[relay] shutting down\n");
449
+ relay.broker.dispose();
450
+ server.close(() => process.exit(0));
451
+ setTimeout(() => process.exit(0), 2e3).unref();
452
+ };
453
+ process.on("SIGTERM", shutdown);
454
+ process.on("SIGINT", shutdown);
455
+ }
456
+ var HELP = `agent-integrations-relay \u2014 Node HTTP server for the MCP relay broker.
457
+
458
+ Usage: agent-integrations-relay [options]
459
+
460
+ Options:
461
+ --port <n> Listen port (env: PORT). Default 8787.
462
+ --host <addr> Bind address (env: HOST). Default 0.0.0.0.
463
+ --prefix <path> URL path prefix (env: PREFIX). Default "".
464
+ --ttl-ms <n> Session TTL ms (env: TTL_MS). Default 14_400_000.
465
+ --cors <origin> CORS Access-Control-Allow-Origin (env: CORS_ALLOW_ORIGIN). Default "*".
466
+ -h, --help Show this help.
467
+
468
+ Endpoints (under --prefix):
469
+ POST /register { session, token } \u2192 { ok: true }
470
+ POST /<session>/inbox?token=... body: JSON-RPC frame
471
+ POST /<session>/outbox?token=... body: JSON-RPC frame
472
+ GET /<session>/events?token=...&direction=inbound|outbound
473
+ Server-sent events stream
474
+ POST /<session>/unregister?token=... Tear down session
475
+ GET / Healthcheck \u2192 200
476
+ `;
477
+ main().catch((e) => {
478
+ process.stderr.write(`[relay] fatal: ${e instanceof Error ? e.stack ?? e.message : String(e)}
479
+ `);
480
+ process.exit(1);
481
+ });
482
+ //# sourceMappingURL=relay-server-cli.cjs.map
483
+ //# sourceMappingURL=relay-server-cli.cjs.map