Frun1na opened a new pull request, #5656:
URL: https://github.com/apache/rocketmq-dashboard/pull/5656
### Which Issue(s) This PR Fixes
- Fixes #5655
### Brief Description
`writeStdioError` only described an MCP call failure when the failure was a
structured HTTP status error. Everything else — connection refused, DNS, TLS,
timeouts, protocol-decode errors — produced a bare `-32603 stdio proxy call
failed` with no `data`, and the actual cause stayed on stderr, which the MCP
client never reads.
The fallback branch now classifies the failure with the same
`normalizeCLIError` the CLI's own error path uses, and carries the sanitized
code, message and hint in the frame:
```
$ printf '{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{}}\n' |
rmqctl mcp stdio --config <closed port> --instance-id inst1
# before
{"jsonrpc":"2.0","id":7,"error":{"code":-32603,"message":"stdio proxy call
failed"}}
# after
{"jsonrpc":"2.0","id":7,"error":{"code":-32000,
"message":"failed to send request: ... dial tcp 127.0.0.1:1: connect:
connection refused",
"data":{"code":"UNAVAILABLE",
"message":"failed to send request: ... connect: connection
refused",
"hint":"Check --server, network connectivity, and Studio Server
status."}}}
```
Two deliberate choices: the frame uses the same `-32000` server-error code
as the HTTP branch, so a client sees one shape for "the upstream call failed"
and reads the precise classification from `data.code`; and the text goes
through the existing `safeStdioDiagnostic` sanitizer, so the frame stays a
single line and within the 512-byte diagnostic cap. The HTTP status branch is
untouched, and a request without a parsable id still gets no frame (there is
nothing a JSON-RPC error could address).
### How Did You Test This Change?
End to end against a context pointing at a closed port (`127.0.0.1:1`),
built from this branch and from the base revision:
```
$ go build -o rmqctl . && printf
'{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{}}\n' |
rmqctl mcp stdio --config closed-port-config.yaml --instance-id inst1
# (frame with code UNAVAILABLE, the connection-refused cause and a hint, as
above)
```
Unit level, with a new `cmd/mcp_stdio_error_test.go` (the writer had no
coverage before):
```
$ cd rmqctl && go test ./cmd/ -run TestStdioErrorFrame -v
--- PASS: TestStdioErrorFrameKeepsTheFailureCause (0.00s)
--- PASS: TestStdioErrorFrameKeepsTheFailureCause/transport_failure
(0.00s)
--- PASS: TestStdioErrorFrameKeepsTheFailureCause/deadline_exceeded
(0.00s)
--- PASS:
TestStdioErrorFrameKeepsTheFailureCause/protocol_decode_failure (0.00s)
--- PASS: TestStdioErrorFrameKeepsTheHTTPStatusShape (0.00s)
--- PASS: TestStdioErrorFrameSanitizesAndCapsTheCause (0.00s)
--- PASS: TestStdioErrorFrameSkipsUnparsableRequests (0.00s)
$ cd rmqctl && go test ./cmd/ && go vet ./cmd/
ok github.com/apache/rocketmq-dashboard/rmqctl/cmd 0.219s
(gofmt -l and go vet print nothing)
```
Without the change the new tests fail on exactly the gap: `frame code =
-32603, want -32000` with no `data` payload.
### Checklist
- [x] One coherent change; unrelated modifications are not bundled in
- [x] Commit subject follows Conventional Commits (`feat:` / `fix:` /
`refactor:` / `chore:` / `docs:` / `perf:`)
- [x] Tests added or updated for non-trivial changes, test methods named
`...Test`
- [ ] New UI text has both Chinese and English entries under `web/src/i18n/`
- [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit
checks)
- [x] New source files carry the ASF license header
- [ ] Documentation touched where behaviour changed (README / `docs/` /
in-app help)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]