Skip to content

feat(http): add default timeouts and graceful shutdown for MCP server/client#77

Merged
electather merged 1 commit intomainfrom
feat/http-timeouts-graceful-shutdown
Mar 16, 2026
Merged

feat(http): add default timeouts and graceful shutdown for MCP server/client#77
electather merged 1 commit intomainfrom
feat/http-timeouts-graceful-shutdown

Conversation

@electather
Copy link
Owner

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 create http.Client with a 30 s Timeout; custom transports are wrapped in the same client so they get the timeout too
  • cmd/mcp/serve.go: export NewHTTPServer that sets ReadHeaderTimeout (5 s), ReadTimeout (15 s), WriteTimeout (30 s), and IdleTimeout (60 s); replace inline http.Server{} literal with this constructor; add signal handler that calls srv.Shutdown with a 30 s deadline on SIGINT/SIGTERM
  • tests/apiutil_client_test.go: two new tests verify the 30 s timeout is applied with and without a custom transport
  • tests/mcp_http_server_test.go: three new tests verify non-zero timeouts, exact default values, and correct addr/handler wiring

Test plan

  • go test -v ./... passes
  • go fmt ./... produces no diff
  • go build succeeds

Checklist

  • New tests added for new behaviour
  • Documentation updated (README, command --help, comments)
  • No unrelated changes included

…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
@electather electather merged commit 3ccfe66 into main Mar 16, 2026
2 checks passed
@electather electather deleted the feat/http-timeouts-graceful-shutdown branch March 16, 2026 13:11
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.

refactor: Add default HTTP timeouts and graceful shutdown for MCP server/client

1 participant