feat(http): add default timeouts and graceful shutdown for MCP server/client#77
Merged
electather merged 1 commit intomainfrom Mar 16, 2026
Merged
Conversation
…t and MCP server Set a 30 s timeout on every outbound API HTTP client so requests cannot hang indefinitely. Add ReadHeader/Read/Write/IdleTimeout to the MCP HTTP server to prevent slow-client resource exhaustion. Listen for SIGINT and SIGTERM on the HTTP transport and perform a graceful shutdown with a 30 s deadline. Closes #66
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add safe default HTTP timeouts to all outbound API requests and to the MCP HTTP server. Add SIGINT/SIGTERM-aware graceful shutdown for the HTTP transport.
Closes #66
Changes
cmd/apiutil/client.go: always createhttp.Clientwith a 30 sTimeout; custom transports are wrapped in the same client so they get the timeout toocmd/mcp/serve.go: exportNewHTTPServerthat setsReadHeaderTimeout(5 s),ReadTimeout(15 s),WriteTimeout(30 s), andIdleTimeout(60 s); replace inlinehttp.Server{}literal with this constructor; add signal handler that callssrv.Shutdownwith a 30 s deadline on SIGINT/SIGTERMtests/apiutil_client_test.go: two new tests verify the 30 s timeout is applied with and without a custom transporttests/mcp_http_server_test.go: three new tests verify non-zero timeouts, exact default values, and correct addr/handler wiringTest plan
go test -v ./...passesgo fmt ./...produces no diffgo buildsucceedsChecklist
--help, comments)