Skip to content

Counterintuitive ssh Hang Under invoke_expression: Manual Terminal Execution Exits Normally, MCP Execution Waits Until Enter Is Pressed #43

@doraemonkeys

Description

@doraemonkeys

Describe the bug

The same ssh command behaves differently depending on how it is started:

  • When the user runs it directly in a normal PowerShell terminal, it completes normally after authentication/output.
  • When the same command is executed through PowerShell.MCP invoke_expression, it remains in a busy/running state until the user presses Enter in the shared console.

This is counterintuitive because the command has already authenticated and produced its visible output, but the MCP execution path still does not return.

To Reproduce

  1. Open a normal PowerShell terminal and run:
ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new -vT git@github.com 2>&1 | Select-String 'Offering public key|Trying private key|Authenticated to|Permission denied|No more authentication methods|identity file|Will attempt key' | ForEach-Object { $_.Line }
  1. Observe that the command completes normally.
  2. Run the same command through PowerShell.MCP invoke_expression.
  3. Observe that PowerShell.MCP reports the pipeline as still running.
  4. Press Enter in the shared console window.
  5. Observe that the command returns immediately after that input.

The same behavior also reproduces with the simpler command below:

ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new -T git@github.com

Expected behavior

If a command completes normally when run directly in the same PowerShell environment and does not require user interaction, the same command should also complete normally when executed via invoke_expression.

Actual behavior

  • Direct manual execution in a normal terminal does not hang.
  • Execution through PowerShell.MCP invoke_expression remains busy until the user presses Enter.

Why this feels wrong

From a user perspective, this does not look like a normal interactive command waiting for input:

  • authentication has already succeeded
  • output has already been produced
  • the command only finishes after an unrelated-looking Enter keypress

That makes the failure mode easy to misread as an SSH/network/authentication problem, even though the manual terminal path does not show the same behavior.

Possible reasons

  • PowerShell.MCP executes commands programmatically inside a persistent shared console/runspace, which is not identical to a user typing the command directly at the prompt.
  • In the MCP execution path, the child process appears to retain a live stdin handle even when the overall command is expected to behave non-interactively.
  • ssh appears to observe that stdin differently in the MCP path than in a direct foreground terminal invocation, which would explain why an Enter keypress changes the outcome.
  • The issue therefore looks less like an SSH-specific authentication failure and more like a difference in stdin/console semantics between direct terminal execution and MCP-mediated execution.

Environment

  • OS: Windows 11
  • PowerShell: 7.6.0
  • OpenSSH client: Windows built-in ssh.exe OpenSSH_for_Windows_9.5p2, LibreSSL 3.8.2
  • PowerShell.MCP: 1.7.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions