Skip to content

fix: retry callTool on transient network errors + code quality fixes#117

Open
icebear0828 wants to merge 1 commit intogoogle-labs-code:mainfrom
icebear0828:fix/callTool-network-retry-v2
Open

fix: retry callTool on transient network errors + code quality fixes#117
icebear0828 wants to merge 1 commit intogoogle-labs-code:mainfrom
icebear0828:fix/callTool-network-retry-v2

Conversation

@icebear0828
Copy link
Contributor

Summary

Network retry:

  • Retry callTool once on transient network errors for idempotent read operations
  • Use RETRYABLE_TOOLS allowlist — unknown tools default to NOT retrying
  • Close old transport before reconnecting to prevent resource leaks
  • Preserve original error when retry also fails

Type safety (remove all as any from src/ and test/):

  • Import CallToolResult/CompatibilityCallToolResult from MCP SDK
  • Add asCallToolResult() to handle legacy protocol format safely
  • Replace Record<string, any> with Record<string, unknown>
  • Replace {} as any Proxy target with concrete type in singleton.ts
  • Type all test mocks properly

Proxy improvements:

  • Replace Date.now() JSON-RPC ID with auto-incrementing counter
  • Await notifications/initialized before refreshTools (fix race condition)
  • Add OAuth support (accessToken + projectId in config and headers)
  • Validate config: require either apiKey OR (accessToken + projectId)
  • Extract buildProxyAuthHeaders() for consistent auth header construction

Other:

  • Add @ai-sdk/google devDependency (fixes tsc error in model-helpers.ts)
  • Add missing protocolVersion in capture-tools.ts
  • Remove duplicate dist entry in .gitignore
  • Remove stale __stitchPatched cleanup from tests
  • Add legacy protocol format tests for asCallToolResult

Test plan

  • npm run test — 88 tests passed
  • npm run test:scripts — 57 tests passed
  • npm run test:smoke — all checks passed
  • npx tsc --noEmit — zero errors

Network retry:
- Retry callTool once on transient network errors for idempotent (read) ops
- Use RETRYABLE_TOOLS allowlist — unknown tools default to NOT retrying
- Close old transport before reconnecting to prevent resource leaks
- Preserve original error when retry also fails

Type safety (remove all `as any` from src/ and test/):
- Import CallToolResult/CompatibilityCallToolResult from MCP SDK
- Add asCallToolResult() to handle legacy protocol format safely
- Replace Record<string, any> with Record<string, unknown>
- Replace `{} as any` Proxy target with concrete type in singleton.ts
- Type all test mocks properly (MockFetch, ProxyContext helpers, etc.)

Proxy improvements:
- Replace Date.now() JSON-RPC ID with auto-incrementing counter
- Await notifications/initialized before refreshTools (fix race)
- Add OAuth support (accessToken + projectId in config and headers)
- Add config validation: require either apiKey or accessToken
- Extract buildProxyAuthHeaders() for consistent auth header construction

Other:
- Add @ai-sdk/google devDependency (fixes tsc error in model-helpers.ts)
- Add missing protocolVersion in capture-tools.ts
- Remove duplicate `dist` entry in .gitignore
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.

1 participant