codex - 💡(How to fix) Fix TypeScript SDK fails to parse item.completed for large Figma MCP tool result

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

This exception is raised before the application receives a parsed ThreadEvent, so the app cannot gracefully handle the MCP result. In the TypeScript SDK source, this seems to come from Thread.runStreamedInternal() doing a direct JSON.parse(item) on each stdout line from CodexExec.run(). 2. emit a structured error/truncated result that remains valid JSONL, or

Root Cause

I cannot attach the full Figma metadata because it contains private design content, but I can provide more structural details if useful.

Code Example

Darwin 25.3.0 arm64 arm

---

Failed to parse item: {"type":"item.completed","item":{"id":"item_3","type":"mcp_tool_call","server":"figma","tool":"get_metadata","arguments":{"fileKey":"<redacted>","nodeId":"1173:53","clientFrameworks":"unknown","clientLanguages":"unknown"},"result":{"content":[{"type":"text","text":"<canvas id=\"1173:53\" name=\"<redacted Korean Figma node name>\" x=\"0\" y=\"0\" width=\"0\" height=\"0\">\n  <rounded-rectangle ... />\n  <ellipse ... />\n  <text ... />\n  ... very large multi-line XML-like Figma metadata ..."}] ... }}}

---

{
  "type": "item.completed",
  "item": {
    "id": "item_3",
    "type": "mcp_tool_call",
    "server": "figma",
    "tool": "get_metadata",
    "arguments": {
      "fileKey": "<redacted>",
      "nodeId": "1173:53",
      "clientFrameworks": "unknown",
      "clientLanguages": "unknown"
    },
    "result": {
      "content": [
        {
          "type": "text",
          "text": "<canvas ...>\n  <rounded-rectangle ... />\n  ... large multi-line XML-like metadata ..."
        }
      ]
    }
  }
}
RAW_BUFFERClick to expand / collapse

What version of Codex CLI is running?

codex-cli 0.130.0

Also using @openai/[email protected] from a Node.js service.

What subscription do you have?

Business / corporate workspace

Which model were you using?

A GPT-5.x Codex model via the TypeScript SDK. The failure appears to happen while parsing the codex exec --experimental-json event stream, before model output handling in the app.

What platform is your computer?

Observed in a Linux production container. Local package/version confirmation was done on macOS arm64:

Darwin 25.3.0 arm64 arm

What terminal emulator and version are you using (if applicable)?

Not terminal-interactive. The app uses @openai/codex-sdk, which spawns codex exec --experimental-json and consumes stdout.

Codex doctor report

Not available from the production container at the time of filing.

What issue are you seeing?

@openai/[email protected] throws while iterating thread.runStreamed(...).events:

Failed to parse item: {"type":"item.completed","item":{"id":"item_3","type":"mcp_tool_call","server":"figma","tool":"get_metadata","arguments":{"fileKey":"<redacted>","nodeId":"1173:53","clientFrameworks":"unknown","clientLanguages":"unknown"},"result":{"content":[{"type":"text","text":"<canvas id=\"1173:53\" name=\"<redacted Korean Figma node name>\" x=\"0\" y=\"0\" width=\"0\" height=\"0\">\n  <rounded-rectangle ... />\n  <ellipse ... />\n  <text ... />\n  ... very large multi-line XML-like Figma metadata ..."}] ... }}}

The failing item is an item.completed event for an MCP tool call:

  • item.type: mcp_tool_call
  • server: figma
  • tool: get_metadata
  • result.content[0].type: text
  • result.content[0].text: very large XML-like text with many lines, Korean labels, and non-ASCII whitespace

This exception is raised before the application receives a parsed ThreadEvent, so the app cannot gracefully handle the MCP result. In the TypeScript SDK source, this seems to come from Thread.runStreamedInternal() doing a direct JSON.parse(item) on each stdout line from CodexExec.run().

What steps can reproduce the bug?

  1. Configure Codex with an MCP server that can return a large multi-line text result. We observed it with the Figma MCP server.
  2. Use @openai/[email protected] and start a streamed run through the SDK.
  3. Ask Codex to call a Figma metadata tool on a large design node/canvas.
  4. The MCP tool call completes and the CLI/SDK tries to emit/parse an item.completed event containing the large mcp_tool_call.result.content[0].text payload.
  5. The SDK throws Failed to parse item: ... while iterating the streamed events.

A representative redacted payload shape is:

{
  "type": "item.completed",
  "item": {
    "id": "item_3",
    "type": "mcp_tool_call",
    "server": "figma",
    "tool": "get_metadata",
    "arguments": {
      "fileKey": "<redacted>",
      "nodeId": "1173:53",
      "clientFrameworks": "unknown",
      "clientLanguages": "unknown"
    },
    "result": {
      "content": [
        {
          "type": "text",
          "text": "<canvas ...>\n  <rounded-rectangle ... />\n  ... large multi-line XML-like metadata ..."
        }
      ]
    }
  }
}

I cannot attach the full Figma metadata because it contains private design content, but I can provide more structural details if useful.

What is the expected behavior?

codex exec --experimental-json / @openai/codex-sdk should either:

  1. emit valid JSONL for completed MCP tool calls regardless of large multi-line text results, or
  2. emit a structured error/truncated result that remains valid JSONL, or
  3. have the SDK surface enough diagnostics to distinguish invalid CLI JSONL from SDK parsing limitations.

The SDK stream should not terminate with a raw Failed to parse item for a successful MCP tool result.

Additional information

Related but not identical issues found before filing:

From source inspection:

  • codex-rs/exec/src/event_processor_with_jsonl_output.rs emits events through serde_json::to_string(&event) and println!.
  • sdk/typescript/src/exec.ts reads child stdout with readline.
  • sdk/typescript/src/thread.ts parses each yielded line with JSON.parse(item) and throws Failed to parse item: ${item}.

So the failure seems to be at the CLI JSONL / TypeScript SDK stdout parsing boundary. It is unlikely to be caused by downstream application code because the app never receives a parsed ThreadEvent for this item.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING