Repository navigation
Closed
Labels
bugSomething isn't workinggood first issueGood for newcomersmcp-serverseverity: mediumMedium severity
Description
Summary
When a remote command exits non-zero, execSSH builds the error from stderr only. About 30 tool commands redirect 2>&1, so stderr is empty and the user gets Command exited with code N with the real error message thrown away.
Where
mcp-server/src/utils/ssh-api.ts:345-346(execSSH)mcp-server/src/utils/errors.ts:379(CommandFailedError)- Affected commands include
composeUp/Down/Pull/Ps,backupRestore.ts:40,backupDiff.ts:22,volumeBackup.ts:29,certRenew.ts:44,certCheck.ts:25,systemdServices.ts:26,ufwStatus.ts:12,fail2banStatus.ts:22
Details
} else if (code !== 0 && code !== null && code !== undefined) {
reject(new CommandFailedError(command, code, stderr.toString()));stdout, which holds the merged output for 2>&1 commands, is dropped. Two visible consequences:
systemctl statusexits 3 for an inactive unit, so askinghomelab_systemdServicesfor a stopped service returns only an exit code.certCheckhas a friendly fallback (certCheck.ts:30) that can never run, becauseopenssl x509exits non-zero when no certificate was received.
Impact
The failures users most need explained (invalid compose file, restore errors, certbot errors, stopped units) come back as a bare exit code plus the command line.
Steps to reproduce
- Call
homelab_systemdServiceswithunitset to an inactive unit. - Result:
[CommandFailedError] Command exited with code 3.
Suggested fix
- In
execSSH, fall back to the tail of stdout when stderr is empty (bounded, for example the last 40 lines), or include both. - In
systemdServices, treat exit code 3 fromsystemctl statusas a successful read. - In
certCheck, return the fallback message when the x509 step fails.
Acceptance criteria
- A failing
2>&1command returns its output in the error. -
systemdServicesshows status for inactive units. - Test in
utils/__tests__/ssh-exec.test.tsfor a non-zero exit with output only on stdout.
Getting started
- Relevant files:
mcp-server/src/utils/ssh-api.ts,mcp-server/src/utils/__tests__/ssh-exec.test.ts - How to run tests:
cd mcp-server && npm install && npm test
Filed by repo-audit/full-audit at a59395f. Severity: medium. Effort: S. audit-key: bug|mcp-server/src/utils/ssh-api.ts|execSSH-stderr
Metadata
Metadata
Assignees
Labels
bugSomething isn't workinggood first issueGood for newcomersmcp-serverseverity: mediumMedium severity
Activity