Repository navigation
feat(mcp): describe the shell dialect, commands, and session state in the shell tool - #269
ferdingler wants to merge 2 commits into
Conversation
… the shell tool Part of strands-agents#207
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
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/$RANDOMaren't mentioned.pgrayyasked 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,fgandbgare 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, base5f80040.cargo test --workspace --all-targetspassed 2,571 tests with 0 failures.cargo clippy --all-targetsshows no warnings in the files you touched. - Bashisms, run with
strands-shell -c:[[ a == a ]]→ 127arr=(a b)→ "arrays are not supported"cat <(echo hi)→ parse errorecho {a,b}andecho $'a\tb'→ printed literallycat <<< hi→ parse error(( x = 1 ))→ command not found
- The suggested alternatives work:
[ ],$(( ))andcase. - Over a real
--mcpstdio session, cwd, exported and plain variables,set -e/-u/pipefail, functions and aliases all carry over to the next call. typereports all nine named builtins as builtins, and none of them is also in the generatedCommands:list.- Silent failures:
false | true; echo "EXIT=${PIPESTATUS[0]}"printsEXIT=with exit 0.echo "R=$RANDOM"printsR=.set -o pipefail; false | true; echo $?prints1. - 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-syswon't build in my sandbox.names()sharesiter()'scfg(not(wasm32))gate andmcpis 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
matchinsrc/builtins/mod.rs:39-70, so abuiltins::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
--mcpbinary never has a fallback (cli.rs:94passesVfsKernel). This is folded into the second suggestion. - Pre-existing, filed #294:
command -voutput ignores redirects (src/exec.rs:3117-3158).
| "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. \ |
There was a problem hiding this comment.
🟡 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!):
| `(( ))`, or `$'...'`; use `[ ]`, `$(( ))`, and `case` instead. \ | |
| `(( ))`, `$'...'`, `PIPESTATUS`, or `$RANDOM`; use `[ ]`, `$(( ))`, `case`, and \ | |
| `set -o pipefail` instead. \ |
There was a problem hiding this comment.
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.
| 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`. \ |
There was a problem hiding this comment.
🟡 "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):
| 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`. \ |
There was a problem hiding this comment.
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.
| for bashism in ["`[[ ]]`", "arrays", "`<(...)`", "`{a,b}`", "`<<<`"] { | ||
| assert!(desc.contains(bashism), "missing {bashism}: {desc}"); | ||
| } |
There was a problem hiding this comment.
🟡 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):
| 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" | |
| ); | |
| } |
There was a problem hiding this comment.
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.
… tool description Part of strands-agents#207
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
setoptions 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 asstrands-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.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.