-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Basics
- I have done a basic search through the issue tracker to find similar or related issues.
- I have made myself familiar with the available features of Nushell for the particular area this enhancement request touches.
Related problem
When nushell is used as an MCP server, errors are returned as human-readable formatted strings (with ANSI colors, box-drawing characters, etc.). While this is great for terminal display, it is not useful for LLM clients consuming the MCP interface.
For example, an error might come back as:
Error: nu::shell::external_command
× External command failed
╭─[source:1:1]
1 │ some-command
· ──────┬─────
· ╰── command not found
╰────
This format is problematic for LLMs because:
- LLMs are notoriously bad at counting spaces/characters - they cannot reliably follow the visual pointer (the
┬and╰──) to determine the exact error location - The box-drawing characters and visual formatting add noise
- Extracting the error type, span, and message requires unreliable text parsing
Describe the solution you'd like
Return errors in a structured format when running as an MCP server. The MCP protocol supports structured error responses. Nushell already has rich error information internally (error code, span, labels, etc.) - this should be exposed in a machine-readable format.
Something like:
{
"error_type": "nu::shell::external_command",
"message": "External command failed",
"span": {"start": 0, "end": 12},
"labels": [{"text": "command not found", "span": {"start": 0, "end": 12}}],
"source": "some-command"
}This would allow LLM clients to:
- Understand the error category programmatically
- Know exactly where in the input the error occurred (via byte offsets, not visual counting)
- Make better decisions about how to fix the issue
Describe alternatives you've considered
I have implemented structured MCP errors in other projects before - it significantly improves LLM tool-use accuracy when debugging commands.
Additional context and details
Related to the general MCP experience in nushell. See also #17122 for another MCP-related issue.