u-foo 4.0.2 → 4.0.3

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/README.md CHANGED
@@ -132,16 +132,19 @@ loopback endpoint. Existing ufoo authentication fields and headers are retained.
132
132
  Use `ufoo mcp configure codex --dry-run` to preview the change with credentials
133
133
  redacted. Restart the Codex surface after configuring it.
134
134
 
135
- For a host that has not been verified with direct HTTP, keep the compatible
136
- stdio configuration:
135
+ For Cursor and any other host that has not been verified with direct HTTP,
136
+ keep the compatible stdio configuration:
137
137
 
138
138
  ```bash
139
139
  ufoo mcp
140
140
  ```
141
141
 
142
142
  This command is a stateless transport proxy into the same global server. It
143
- does not own Agent registrations or project state. Inspect or restart the
144
- singleton listener with `ufoo mcp status` and `ufoo mcp restart`.
143
+ accepts both newline-delimited JSON and standard `Content-Length` frames, and
144
+ answers in the framing that client used. Cursor can keep `command: ufoo` and
145
+ `args: ["mcp"]`. The proxy does not own Agent registrations or project state.
146
+ Inspect or restart the singleton listener with `ufoo mcp status` and
147
+ `ufoo mcp restart`.
145
148
 
146
149
  ## Runtime Model
147
150
 
package/README.zh-CN.md CHANGED
@@ -138,10 +138,11 @@ ufoo -g
138
138
  ufoo mcp configure codex
139
139
  ```
140
140
 
141
- 重启 Codex surface 后即可使用。尚未验证直接 HTTP 的 host 继续配置
142
- `ufoo mcp`;该命令只是连接同一 global server 的无状态 stdio 代理,不拥有
143
- Agent 注册或项目状态。用 `ufoo mcp status` 检查唯一 listener,用
144
- `ufoo mcp restart` 只重启 listener。
141
+ 重启 Codex surface 后即可使用。Cursor 以及其他尚未验证直接 HTTP 的 host
142
+ 继续配置 `ufoo mcp`。这个无状态 stdio 代理连接同一个 global server,同时接受
143
+ 换行 JSON 和标准 `Content-Length` 帧,并按客户端使用的帧格式回写。Cursor 保持
144
+ `command: ufoo`、`args: ["mcp"]` 即可。它不拥有 Agent 注册或项目状态。用
145
+ `ufoo mcp status` 检查唯一 listener,用 `ufoo mcp restart` 只重启 listener。
145
146
 
146
147
  ## 运行模型
147
148
 
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u-foo",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "Multi-Agent Workspace Protocol. Just add u. claude → uclaude, codex → ucodex.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://ufoo.dev",
@@ -22,11 +22,81 @@ const REPLAYABLE_TOOLS = new Set([
22
22
  "list_agents", "ufoo_mcp_status", "poll_inbox", "wait_for_message",
23
23
  ]);
24
24
  const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
25
+ const CONTENT_LENGTH_HEADER = "content-length:";
26
+ const MAX_STDIO_HEADER_BYTES = 64 * 1024;
27
+ const MAX_STDIO_BODY_BYTES = 2 * 1024 * 1024;
25
28
 
26
29
  function sleep(ms) {
27
30
  return new Promise((resolve) => setTimeout(resolve, ms));
28
31
  }
29
32
 
33
+ function skipAsciiSpace(buffer) {
34
+ let index = 0;
35
+ while (index < buffer.length && (buffer[index] === 0x20 || buffer[index] === 0x09)) index += 1;
36
+ return index;
37
+ }
38
+
39
+ function classifyStdioChunk(buffer) {
40
+ const offset = skipAsciiSpace(buffer);
41
+ const sample = buffer.slice(offset, offset + CONTENT_LENGTH_HEADER.length).toString("latin1").toLowerCase();
42
+ if (!sample) return "empty";
43
+ if (sample.startsWith("{")) return "json";
44
+ if (sample.startsWith(CONTENT_LENGTH_HEADER)) return "header";
45
+ if (CONTENT_LENGTH_HEADER.startsWith(sample) && !sample.includes("\n")) return "prefix";
46
+ return "line";
47
+ }
48
+
49
+ function takeContentLengthFrame(buffer) {
50
+ let index = 0;
51
+ while (
52
+ index < buffer.length
53
+ && (buffer[index] === 0x20 || buffer[index] === 0x09 || buffer[index] === 0x0d || buffer[index] === 0x0a)
54
+ ) index += 1;
55
+ if (index === buffer.length) return { status: "empty" };
56
+ const slice = buffer.slice(index);
57
+ const crlf = slice.indexOf("\r\n\r\n");
58
+ const lf = slice.indexOf("\n\n");
59
+ let headerEnd = -1;
60
+ let separatorLength = 0;
61
+ if (crlf >= 0 && (lf < 0 || crlf <= lf)) {
62
+ headerEnd = crlf;
63
+ separatorLength = 4;
64
+ } else if (lf >= 0) {
65
+ headerEnd = lf;
66
+ separatorLength = 2;
67
+ }
68
+ if (headerEnd < 0) {
69
+ if (slice.length > MAX_STDIO_HEADER_BYTES) {
70
+ return { status: "invalid", rest: Buffer.alloc(0), message: "MCP header is too large" };
71
+ }
72
+ return { status: "need-more" };
73
+ }
74
+ const header = slice.slice(0, headerEnd).toString("utf8");
75
+ const match = header.match(/content-length:\s*(\d+)/i);
76
+ if (!match) {
77
+ return {
78
+ status: "invalid",
79
+ rest: slice.slice(headerEnd + separatorLength),
80
+ message: "MCP frame is missing Content-Length",
81
+ };
82
+ }
83
+ const length = Number(match[1]);
84
+ if (!Number.isSafeInteger(length) || length < 0 || length > MAX_STDIO_BODY_BYTES) {
85
+ return {
86
+ status: "invalid",
87
+ rest: slice.slice(headerEnd + separatorLength),
88
+ message: "MCP Content-Length is invalid",
89
+ };
90
+ }
91
+ const bodyStart = headerEnd + separatorLength;
92
+ if (slice.length < bodyStart + length) return { status: "need-more" };
93
+ return {
94
+ status: "ok",
95
+ body: slice.slice(bodyStart, bodyStart + length).toString("utf8"),
96
+ rest: slice.slice(bodyStart + length),
97
+ };
98
+ }
99
+
30
100
  function validateEndpoint(raw = "") {
31
101
  let parsed;
32
102
  try {
@@ -85,12 +155,21 @@ class McpStdioProxy {
85
155
  this.initializing = null;
86
156
  this.activeRequests = new Map();
87
157
  this.closed = false;
88
- this.buffer = "";
158
+ this.buffer = Buffer.alloc(0);
159
+ this.inputFraming = "";
160
+ this.outputFraming = "ndjson";
89
161
  }
90
162
 
91
163
  writeMessage(message) {
92
164
  if (!message || this.closed) return;
93
- this.output.write(`${JSON.stringify(message)}\n`);
165
+ const json = JSON.stringify(message);
166
+ if (this.outputFraming === "content-length") {
167
+ const body = Buffer.from(json, "utf8");
168
+ this.output.write(`Content-Length: ${body.length}\r\n\r\n`);
169
+ this.output.write(body);
170
+ return;
171
+ }
172
+ this.output.write(`${json}\n`);
94
173
  }
95
174
 
96
175
  writeError(message) {
@@ -288,11 +367,10 @@ class McpStdioProxy {
288
367
  }
289
368
  }
290
369
 
291
- handleLine(line) {
292
- if (!line.trim()) return;
370
+ handleJsonText(text) {
293
371
  let request;
294
372
  try {
295
- request = JSON.parse(line);
373
+ request = JSON.parse(text);
296
374
  } catch (err) {
297
375
  this.writeMessage(createJsonRpcError(
298
376
  null,
@@ -304,13 +382,55 @@ class McpStdioProxy {
304
382
  void this.forward(request);
305
383
  }
306
384
 
385
+ handleLine(line) {
386
+ if (!line.trim()) return;
387
+ this.handleJsonText(line);
388
+ }
389
+
390
+ drainInput() {
391
+ while (this.buffer.length > 0) {
392
+ if (this.inputFraming === "content-length") {
393
+ const frame = takeContentLengthFrame(this.buffer);
394
+ if (frame.status === "need-more") return;
395
+ if (frame.status === "empty") {
396
+ this.buffer = Buffer.alloc(0);
397
+ return;
398
+ }
399
+ this.buffer = frame.rest;
400
+ this.outputFraming = "content-length";
401
+ if (frame.status === "invalid") {
402
+ this.writeMessage(createJsonRpcError(
403
+ null,
404
+ MCP_ERROR_CODES.PARSE_ERROR,
405
+ frame.message || "Parse error"
406
+ ));
407
+ continue;
408
+ }
409
+ this.handleJsonText(frame.body);
410
+ continue;
411
+ }
412
+
413
+ const kind = classifyStdioChunk(this.buffer);
414
+ if (kind === "empty" || kind === "prefix") return;
415
+ if (kind === "header") {
416
+ this.inputFraming = "content-length";
417
+ this.outputFraming = "content-length";
418
+ continue;
419
+ }
420
+
421
+ const newline = this.buffer.indexOf(0x0a);
422
+ if (newline < 0) return;
423
+ const line = this.buffer.slice(0, newline).toString("utf8").replace(/\r$/, "");
424
+ this.buffer = this.buffer.slice(newline + 1);
425
+ this.handleLine(line);
426
+ }
427
+ }
428
+
307
429
  start() {
308
- this.input.setEncoding("utf8");
309
430
  this.input.on("data", (chunk) => {
310
- this.buffer += chunk;
311
- const lines = this.buffer.split(/\r?\n/);
312
- this.buffer = lines.pop() || "";
313
- for (const line of lines) this.handleLine(line);
431
+ const next = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
432
+ this.buffer = this.buffer.length ? Buffer.concat([this.buffer, next]) : next;
433
+ this.drainInput();
314
434
  });
315
435
  this.input.on("end", () => {
316
436
  void this.close();