Skip to content

feat(mcp): describe the shell dialect, commands, and session state in the shell tool - #269

Open
ferdingler wants to merge 2 commits into
strands-agents:mainfrom
ferdingler:feat/mcp-shell-tool-description
Open

ferdingler wants to merge 2 commits into
strands-agents:mainfrom
ferdingler:feat/mcp-shell-tool-description

Conversation

@ferdingler

Copy link
Copy Markdown
Collaborator

Description

An agent connected to the MCP server only learned that the shell tool "runs a command". It had no way to know this is plain sh rather than bash, which commands exist, or that cd, exports and set options stick between calls, so it would try bash syntax, hit errors, and retry.

Now the shell tool's description says it's POSIX sh, names the bash features that don't work ([[ ]], arrays, process substitution, brace expansion, here-strings, (( )), $'...'), lists the available commands, and says what state carries over. The command list comes from the same place as strands-shell list-commands, so it stays current when commands are added. MCP server change only.

I checked each listed bash feature against main and they all fail today. I also checked in an MCP session that working directory, exported variables, shell options, functions and aliases carry over to the next call. A new MCP test checks the description, and the full Rust suite passes. I left builtins and host-provided commands out of the generated list: there's no list of builtins to read from, and a host can only answer whether it serves a given name. The description names the common builtins and tells the agent to check with command -v.

This touches the same description line as #268 (exit code as a third text block), so whichever lands second needs a small rebase to keep that sentence.

Related Issues

Part of #207

Documentation PR

None.

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ferdingler
ferdingler requested a review from a team as a code owner November 13, 2026 05:09
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

@strandly-the-agent strandly-the-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approve. Every claim in the new description holds against the built binary at 804c7bf, and the full suite passes. I left three 🟡 suggestions, none of them blocking:

  • PIPESTATUS / $RANDOM aren't mentioned. pgrayy asked for this on #207. These fail silently (empty string, exit 0), so they're worse for a model than the bashisms you listed, which fail loudly.
  • "sh builtins such as … find, xargs, lua" describes how the code is organised rather than what the model needs. "such as" also suggests the standard set is all there, but kill, jobs, fg and bg are missing.
  • The test only checks the prose. Nothing fails if a listed bashism starts working.

Separately, I filed #294. command -v X >/dev/null ignores the redirect, and this description now points models at command -v.

✅ What I verified
  • Head 804c7bf, base 5f80040. cargo test --workspace --all-targets passed 2,571 tests with 0 failures. cargo clippy --all-targets shows no warnings in the files you touched.
  • Bashisms, run with strands-shell -c:
    • [[ a == a ]] → 127
    • arr=(a b) → "arrays are not supported"
    • cat <(echo hi) → parse error
    • echo {a,b} and echo $'a\tb' → printed literally
    • cat <<< hi → parse error
    • (( x = 1 )) → command not found
  • The suggested alternatives work: [ ], $(( )) and case.
  • Over a real --mcp stdio session, cwd, exported and plain variables, set -e/-u/pipefail, functions and aliases all carry over to the next call.
  • type reports all nine named builtins as builtins, and none of them is also in the generated Commands: list.
  • Silent failures: false | true; echo "EXIT=${PIPESTATUS[0]}" prints EXIT= with exit 0. echo "R=$RANDOM" prints R=. set -o pipefail; false | true; echo $? prints 1.
  • The generated description is 940 chars, up from 244.
  • I applied all three suggestions locally. The new test passes, and the generated description reads cleanly.
  • Not covered: a wasm32 build. mlua-sys won't build in my sandbox. names() shares iter()'s cfg(not(wasm32)) gate and mcp is non-wasm, so I checked that part by reading the code.
Questions (non-blocking)
  • Generate the builtins list too? The "no list to read from" reason is a closed match in src/builtins/mod.rs:39-70, so a builtins::names() would be about 10 lines and would remove the "such as". It would add roughly 180 chars. Your call.
  • $SHELL: #283 sets it to /bin/sh, so I left it out of the suggestion on purpose.
  • #268 edits the same "Returns two text content blocks" sentence, which you already noted.
Appendix — non-blocking (2)
  • ⚪ "The host may provide more": "host" is embedder jargon, and in MCP terms the host is the client app. The standalone --mcp binary never has a fallback (cli.rs:94 passes VfsKernel). This is folded into the second suggestion.
  • Pre-existing, filed #294: command -v output ignores redirects (src/exec.rs:3117-3158).

Comment thread src/mcp.rs Outdated
"Runs a command in Strands Shell, an in-process virtual shell. \
The dialect is POSIX sh, not bash: there is no `[[ ]]`, arrays, \
process substitution `<(...)`, brace expansion `{{a,b}}`, here-strings `<<<`, \
`(( ))`, or `$'...'`; use `[ ]`, `$(( ))`, and `case` instead. \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟡 The bashisms that fail silently aren't listed. false | true; echo "EXIT=${PIPESTATUS[0]}" → EXIT=, exit 0. echo "R=$RANDOM" → R=. A model won't notice either of these, while every bashism listed here errors loudly. pgrayy asked on #207 for the description to show supported ways to check command outcomes. set -o pipefail works (false | true; echo $? → 1), so that's the alternative to name.

Suggestion (no braces, so nothing to escape in format!):

Suggested change
`(( ))`, or `$'...'`; use `[ ]`, `$(( ))`, and `case` instead. \
`(( ))`, `$'...'`, `PIPESTATUS`, or `$RANDOM`; use `[ ]`, `$(( ))`, `case`, and \
`set -o pipefail` instead. \

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Applied in c102f20. Checked on main: ${PIPESTATUS[0]} and $RANDOM expand to empty with exit 0, and set -o pipefail works, so the description now names both and points to pipefail.

Comment thread src/mcp.rs Outdated
Comment on lines +136 to +137
Commands: {commands}; plus sh builtins such as cd, export, set, read, printf, \
test, find, xargs, and lua. The host may provide more; check with `command -v NAME`. \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟡 "sh builtins such as … find, xargs, lua" mirrors the dispatch table, not what the model knows. No sh has find, xargs or lua as builtins. "such as" also tells the model the rest of the standard set is there, but command -v returns 1 for kill, jobs, fg and bg. "The host may provide more" is embedder jargon too, and the standalone --mcp binary never has a fallback.

Suggestion (keeps Commands: {commands}; intact, so your test still passes; I checked locally):

Suggested change
Commands: {commands}; plus sh builtins such as cd, export, set, read, printf, \
test, find, xargs, and lua. The host may provide more; check with `command -v NAME`. \
Commands: {commands}; also find, xargs, and lua; plus the usual sh builtins \
(cd, export, set, read, printf, test, ...) but no `kill` or job control. \
Other commands may be available; check with `command -v NAME`. \

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Applied in c102f20. Confirmed command -v returns 1 for kill, jobs, fg and bg. find/xargs/lua are now listed as commands rather than sh builtins, and the fallback line no longer says "host". I didn't generate the builtins list in this PR: builtins::names() would be a hand-kept copy of the lookup() match (and would still miss the special builtins handled in exec.rs), so it isn't really derived from a registry. Making builtins a table that both lookup and the description read from would fix that; happy to do it as a follow-up.

Comment thread tests/mcp_integration.rs
Comment on lines +117 to +119
for bashism in ["`[[ ]]`", "arrays", "`<(...)`", "`{a,b}`", "`<<<`"] {
assert!(desc.contains(bashism), "missing {bashism}: {desc}");
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟡 Nothing fails when the description goes stale. These assertions match the prose you just wrote. #207 says "either implement them or make the tool description clearly say…", so if someone later implements [[ ]] or <<<, this test stays green while the description becomes wrong. Running the claims through the tool pins them where the model sees them. Aliases and set options, the two new persistence claims, also have no test yet (mcp_shell_state_persists_across_calls covers cwd, env and functions only).

Suggestion (passes at this head):

Suggested change
for bashism in ["`[[ ]]`", "arrays", "`<(...)`", "`{a,b}`", "`<<<`"] {
assert!(desc.contains(bashism), "missing {bashism}: {desc}");
}
for bashism in ["`[[ ]]`", "arrays", "`<(...)`", "`{a,b}`", "`<<<`"] {
assert!(desc.contains(bashism), "missing {bashism}: {desc}");
}
// If one of these starts working, the description is stale.
for cmd in ["[[ a == a ]]", "arr=(a b)", "cat <(echo x)", "cat <<< x"] {
let r = mcp_tool("shell", json!({"command": cmd}));
assert_ne!(
r["result"]["metadata"]["exit_code"],
0,
"{cmd} now works; update the description"
);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Applied in c102f20. The test now runs the four loud bash-isms through the tool and fails if any of them exits 0. I also added a test that aliases and set options (set -u) carry over to the next call, since those claims weren't covered. PIPESTATUS/$RANDOM can't be pinned the same way because they fail silently.

@ferdingler ferdingler mentioned this pull request Nov 13, 2026
10 tasks done

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants