@agentcomms/events-daemon 0.0.0-stage → 0.17.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,102 @@
1
+ import { i as serializeMessage, n as process, r as ReadBuffer } from "./mcp-DXXb3Vv3-B0sHZfig.mjs";
2
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+server@2.0.0/node_modules/@modelcontextprotocol/server/dist/stdio.mjs
3
+ /**
4
+ * Server transport for stdio: this communicates with an MCP client by reading from the current process' `stdin` and writing to `stdout`.
5
+ *
6
+ * This transport is only available in Node.js environments.
7
+ *
8
+ * @example
9
+ * ```ts source="./stdio.examples.ts#StdioServerTransport_basicUsage"
10
+ * const server = new McpServer({ name: 'my-server', version: '1.0.0' });
11
+ * const transport = new StdioServerTransport();
12
+ * await server.connect(transport);
13
+ * ```
14
+ */
15
+ var StdioServerTransport = class {
16
+ _readBuffer;
17
+ _started = false;
18
+ _closed = false;
19
+ constructor(_stdin = process.stdin, _stdout = process.stdout, options) {
20
+ this._stdin = _stdin;
21
+ this._stdout = _stdout;
22
+ this._readBuffer = new ReadBuffer({ maxBufferSize: options?.maxBufferSize });
23
+ }
24
+ onclose;
25
+ onerror;
26
+ onmessage;
27
+ _ondata = (chunk) => {
28
+ try {
29
+ this._readBuffer.append(chunk);
30
+ this.processReadBuffer();
31
+ } catch (error) {
32
+ this.onerror?.(error);
33
+ this.close().catch(() => {});
34
+ }
35
+ };
36
+ _onerror = (error) => {
37
+ this.onerror?.(error);
38
+ };
39
+ _onstdouterror = (error) => {
40
+ this.onerror?.(error);
41
+ this.close().catch(() => {});
42
+ };
43
+ /**
44
+ * Starts listening for messages on `stdin`.
45
+ */
46
+ async start() {
47
+ if (this._started) throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");
48
+ this._started = true;
49
+ this._stdin.on("data", this._ondata);
50
+ this._stdin.on("error", this._onerror);
51
+ this._stdout.on("error", this._onstdouterror);
52
+ }
53
+ processReadBuffer() {
54
+ while (true) try {
55
+ const message = this._readBuffer.readMessage();
56
+ if (message === null) break;
57
+ this.onmessage?.(message);
58
+ } catch (error) {
59
+ this.onerror?.(error);
60
+ }
61
+ }
62
+ async close() {
63
+ if (this._closed) return;
64
+ this._closed = true;
65
+ this._stdin.off("data", this._ondata);
66
+ this._stdin.off("error", this._onerror);
67
+ this._stdout.off("error", this._onstdouterror);
68
+ if (this._stdin.listenerCount("data") === 0) this._stdin.pause();
69
+ this._readBuffer.clear();
70
+ this.onclose?.();
71
+ }
72
+ send(message) {
73
+ if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
74
+ return new Promise((resolve, reject) => {
75
+ const json = serializeMessage(message);
76
+ let settled = false;
77
+ const onError = (error) => {
78
+ if (settled) return;
79
+ settled = true;
80
+ this._stdout.off("error", onError);
81
+ this._stdout.off("drain", onDrain);
82
+ reject(error);
83
+ };
84
+ const onDrain = () => {
85
+ if (settled) return;
86
+ settled = true;
87
+ this._stdout.off("error", onError);
88
+ this._stdout.off("drain", onDrain);
89
+ resolve();
90
+ };
91
+ this._stdout.once("error", onError);
92
+ if (this._stdout.write(json)) {
93
+ if (settled) return;
94
+ settled = true;
95
+ this._stdout.off("error", onError);
96
+ resolve();
97
+ } else if (!settled) this._stdout.once("drain", onDrain);
98
+ });
99
+ }
100
+ };
101
+ //#endregion
102
+ export { StdioServerTransport };