Skip to content

fix(nu-mcp): keep $history indices stable, run evaluations one at a time, and correct stale guidance in the MCP instructions and AGENTS.md - #19318

Merged
fdncred merged 1 commit into
nushell:mainfrom
fdncred:prompt_audit_fixes
Oct 23, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
fdncred:prompt_audit_fixes

Conversation

@fdncred

@fdncred fdncred commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

Once $history was full, each new evaluation shifted every older entry down by one. History::push returned the buffer length after evicting, so an index from an earlier response could point at a later result, while the instructions promised "indices do not shift, older ones simply become unavailable". This PR makes that promise true: indices only increase, and an evicted index reads as null. push also evicts until the buffer fits the limit instead of dropping one entry per push, so lowering NU_MCP_HISTORY_LIMIT trims $history to the new limit.

Two evaluate calls sent at once (agents send parallel tool calls) each forked the same state, and the one that finished last overwrote the other. Both responses reported the same history_index, and the other call's $history entry and $env changes were lost. Evaluations now run one at a time, like lines typed into a REPL: a lock is held from fork to commit and released early when an evaluation is promoted to a background job. list_commands and command_help don't wait for it.

The rest of the text nu --mcp sends to agents (instructions.md, evaluate_tool.md, and the list_commands / command_help descriptions) also gave advice that nushell contradicts. It said ls **/* walks hidden directories and glob avoids them, when the reverse is true. It used a job spawn --tag flag that was renamed in #17496, and said command_help shows input/output types, which it doesn't. The evaluate tool description still told agents to avoid large output, which contradicts the server instructions sent in the same session. This PR rewrites those passages to match nushell, tones down the all-caps "THE RULE" section while keeping the rule and its reason, and fills in the two short tool descriptions with their real output format and limits.

In AGENTS.md, it fixes the claim that cargo nuclippy-tests runs all tests (it runs clippy), says how integration-test targets are named in crates without a tests target, states three wordy or hedged rules more plainly, and fixes a typo.

User-facing changes (Release notes)

MCP: stable $history indices, one evaluation at a time

  • In nu --mcp, $history indices no longer shift when old entries are evicted. An evicted index reads as null, and $history | length counts every result stored in the session. Lowering NU_MCP_HISTORY_LIMIT now trims $history to the new limit.
  • nu --mcp now runs evaluate calls one at a time. Before, two calls sent together could get the same history_index, and one call's $history entry and $env changes were lost.
  • The MCP server's instructions and tool descriptions now match nushell's behavior for ls vs glob on hidden directories, job spawn --description, command_help output, and \u{...} escapes.
  • The evaluate tool description no longer tells agents to avoid large output. Output over the limit already comes back as a note pointing at $history.

Additional notes

… time, and correct stale guidance in the MCP instructions and AGENTS.md
@fdncred fdncred added the A:MCP Model Context Protocol (nu-mcp) label Oct 22, 2026
@fdncred
fdncred merged commit 89e6efe into nushell:main Oct 23, 2026
12 checks passed
@fdncred
fdncred deleted the prompt_audit_fixes branch October 23, 2026 11:04
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Oct 23, 2026
@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:MCP Model Context Protocol (nu-mcp) notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant