fix: retry callTool on transient network errors + code quality fixes#117
Open
icebear0828 wants to merge 1 commit intogoogle-labs-code:mainfrom
Open
fix: retry callTool on transient network errors + code quality fixes#117icebear0828 wants to merge 1 commit intogoogle-labs-code:mainfrom
icebear0828 wants to merge 1 commit intogoogle-labs-code:mainfrom
Conversation
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
884c372 to
51239a4
Compare
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
Network retry:
callToolonce on transient network errors for idempotent read operationsRETRYABLE_TOOLSallowlist — unknown tools default to NOT retryingType safety (remove all
as anyfrom src/ and test/):CallToolResult/CompatibilityCallToolResultfrom MCP SDKasCallToolResult()to handle legacy protocol format safelyRecord<string, any>withRecord<string, unknown>{} as anyProxy target with concrete type in singleton.tsProxy improvements:
Date.now()JSON-RPC ID with auto-incrementing counternotifications/initializedbeforerefreshTools(fix race condition)accessToken+projectIdin config and headers)apiKeyOR (accessToken+projectId)buildProxyAuthHeaders()for consistent auth header constructionOther:
@ai-sdk/googledevDependency (fixes tsc error in model-helpers.ts)protocolVersionin capture-tools.tsdistentry in .gitignore__stitchPatchedcleanup from testsasCallToolResultTest plan
npm run test— 88 tests passednpm run test:scripts— 57 tests passednpm run test:smoke— all checks passednpx tsc --noEmit— zero errors