Skip to content

feat(http): implement HTTP timeout handling for fetch requests#99

Merged
mborne merged 3 commits into
masterfrom
45-timeout
May 2, 2026
Merged

feat(http): implement HTTP timeout handling for fetch requests#99
mborne merged 3 commits into
masterfrom
45-timeout

Conversation

@esgn
Copy link
Copy Markdown
Member

@esgn esgn commented May 1, 2026

Closes #45

This PR adds timeout handling to the shared HTTP helpers used for outbound calls to IGN/GPF services.

Without a timeout, MCP tool calls could hang indefinitely when an upstream service is slow or unresponsive. This change makes those failures bounded and explicit.

What changed

  • Wrap fetchJSONGet() and fetchJSONPost() with timeout handling in src/helpers/http.ts
  • Abort stalled outbound requests with AbortController
  • Convert timeout aborts into structured ServiceResponseErrors with:
    • HTTP status 504
    • status text Gateway Timeout
    • service code TIMEOUT
  • Add HTTP_TIMEOUT configuration in seconds
  • Document the new setting in README.md
  • Add test coverage for GET and POST timeout behavior in test/helpers/http.test.ts

Configuration

  • New env var: HTTP_TIMEOUT
  • Unit: seconds
  • Default: 15

Example:

export HTTP_TIMEOUT=15

Why
This prevents the MCP server from waiting forever on upstream HTTP calls and gives clients a predictable error instead of a hanging tool invocation.

Tests

  • npm test -- test/helpers/http.test.ts
  • npm run typecheck

@esgn esgn requested a review from mborne May 1, 2026 20:15
@mborne mborne merged commit f548715 into master May 2, 2026
3 checks passed
@mborne mborne deleted the 45-timeout branch May 2, 2026 20:12
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.

Missing HTTP timeouts

2 participants