Skip to content

fix: add file-redirection example for JSON stdin mode in mcp_cli_tools_prompt (#29649)#29653

Merged
pelikhan merged 1 commit intomainfrom
copilot/fix-mcp-to-cli-stdin-json-parsing
May 2, 2026
Merged

fix: add file-redirection example for JSON stdin mode in mcp_cli_tools_prompt (#29649)#29653
pelikhan merged 1 commit intomainfrom
copilot/fix-mcp-to-cli-stdin-json-parsing

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 2, 2026

Summary

Fixes the "automatic mcp-to-cli stdin JSON parsing" issue observed in PR #29649, where the PR body contained a raw JSON object instead of the intended markdown content.

Root Cause

When an agent tried to create a PR with a multi-field JSON payload via the safeoutputs CLI, this sequence occurred:

  1. Tried pipeprintf '...' | safeoutputs create_pull_request . → ❌ blocked by Claude Code bash security ("Redirect has multiple targets")
  2. Tried cat pipecat file | safeoutputs create_pull_request . → ❌ blocked ("multiple operations require approval")
  3. Fell back tosafeoutputs create_pull_request --body - < /tmp/payload.json → ✅ allowed, but wrong: --body - reads the entire JSON object as a raw string for the body parameter, rather than parsing it and distributing title, body, branch, base to their respective fields

The correct approach — safeoutputs create_pull_request . < /tmp/payload.json — was never tried because the prompt only showed pipe examples.

Fix

Updated actions/setup/md/mcp_cli_tools_prompt.md to:

  • Add a "When pipes are blocked" section showing safeoutputs create_pull_request . < /tmp/payload.json (. sentinel with < file redirection, no pipe required)
  • Add an explicit warning against using --body - < file for multi-field JSON payloads — this reads the whole JSON object as the body string
  • Update the "pipe from a file" example to show the correct . < file form
  • Update notes to list . < file alongside printf ... | as equivalent approaches

Why . < file works

  • The . sentinel tells the bridge to parse stdin as a full JSON argument object
  • < file redirects stdin from a file (not a pipe — no second command)
  • process.stdin.isTTY is undefined for both pipes and file redirections, so the bridge reads stdin correctly in both cases
  • No bash security restrictions apply because only one executable runs

Copilot AI requested a review from pelikhan May 2, 2026 00:31
@pelikhan pelikhan marked this pull request as ready for review May 2, 2026 00:51
Copilot AI review requested due to automatic review settings May 2, 2026 00:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the MCP CLI usage prompt to document a non-pipe workflow for passing multi-field JSON payloads via stdin, preventing PR bodies from accidentally becoming raw JSON when agents fall back to --body - patterns.

Changes:

  • Rewords JSON-stdin guidance to emphasize supplying a JSON object via stdin (dot sentinel) rather than only “piping.”
  • Adds a “When pipes are blocked” section demonstrating . < file stdin file-redirection for JSON payload mode.
  • Adds an explicit warning against --body - < file for multi-field JSON payloads and updates examples/notes accordingly.
Show a summary per file
File Description
actions/setup/md/mcp_cli_tools_prompt.md Adds file-redirection examples and warnings so multi-field JSON stdin payloads are parsed correctly even when pipes are restricted.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@github-actions github-actions Bot mentioned this pull request May 2, 2026
@pelikhan pelikhan merged commit 82b09a6 into main May 2, 2026
53 of 63 checks passed
@pelikhan pelikhan deleted the copilot/fix-mcp-to-cli-stdin-json-parsing branch May 2, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants