Skip to content

fix: stop MCP dispatch after response transport failures - #63

Merged
alexshapalov merged 1 commit into
pgrundev:mainfrom
DivyamTalwar:fix/stop-mcp-response-failures
Sep 22, 2026
Merged

alexshapalov merged 1 commit into
pgrundev:mainfrom
DivyamTalwar:fix/stop-mcp-response-failures

Conversation

@DivyamTalwar

Copy link
Copy Markdown
Contributor

What and why

Closes #60.

Server.Serve ignored buffered response write errors, so a broken output pipe could leave it dispatching further diagnostic tools and ultimately returning success at input EOF. Return the flush error immediately instead. The response format and normal serving behavior are unchanged.

The regression uses the real read/dispatch/write loop and proves that only the first of two tool calls runs after output failure. It covers small and larger-than-buffer responses, short writes, and a final request without a trailing newline.

Verification

Verified commit: c1325b1de0b0f90f72426788ac927f8c5a450581.

  • Base control at a1e6561e366455756c45a16a46647f882b3b6a1c: the new regression tests fail because the error is ignored and the second handler is called.
  • go test -race ./internal/mcp -run 'TestServe_' -count=20: passed.
  • bash scripts/gate.sh: passed on the committed HEAD, including build, vet, pinned golangci-lint, unit tests and all six release target builds.
  • go test -race ./...: passed.
  • gofmt -l on changed Go files and git diff --check: clean.
  • The identical source tree also passed PostgreSQL 18 collector/CLI integration and dependency scanning in the fork validation run. This commit changes only author/message metadata relative to that validated source tree.

Risk and rollback

The change is limited to an already-failed output transport. Callers now receive the original write error rather than false success. Successful writes and notification handling are unchanged. Reverting this commit restores the prior behavior; no migrations or dependency changes are involved.

Checklist

  • scripts/gate.sh passes on the committed HEAD.
  • No new SQL or inspected-query execution; findings remain deterministic.
  • No new data enters model.Context, JSON, or the store.
  • JSON schema and finding catalog are unchanged.

The serving loop ignored buffered response write failures and continued dispatching diagnostic tools after losing its output transport. Propagate flush errors immediately, including the final response at EOF.

Regression coverage exercises buffered and large responses, short writes, dispatch counts, and EOF error precedence. The protocol and JSON schema are unchanged.

Closes pgrundev#60
@alexshapalov
alexshapalov merged commit e3bcff4 into pgrundev:main Sep 22, 2026
19 checks passed
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.

MCP server ignores response write errors and continues dispatching tools

2 participants