Skip to content

MCP: complete command doesn't capture external command errors #17173

@andrewgazelka

Description

@andrewgazelka

Bug report form

  • I have done a basic search of the issue tracker to find any existing issues that are similar.
  • I have checked that my version is at least the latest stable release available via my installation method.

Describe the bug

When using nushell as an MCP server, the complete command does not properly capture external command errors. Instead of returning a structured result with stdout, stderr, and exit_code, it throws an error.

How to reproduce

  1. Start nushell as an MCP server (nu --mcp)
  2. Use an MCP client (e.g., Claude Code) to run:
    let a = (^ls asjhdsakjhds | complete); $a
  3. The command fails with an error instead of capturing it

Expected behavior

In normal nushell, the above command returns:

{stdout: "", stderr: "ls: cannot access 'asjhdsakjhds': No such file or directory", exit_code: 2}

The complete command should swallow the external command error and return the structured result.

Actual behavior

In MCP mode, it throws:

Error: nu::shell::non_zero_exit_code
x External command had a non-zero exit code

Context

This makes it difficult to handle external command errors gracefully in MCP mode. The complete command is specifically designed to capture errors from external commands, but this behavior is broken in the MCP server.

Configuration

Running from main branch (recent commit).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions