-
Notifications
You must be signed in to change notification settings - Fork 14
Resolve isHTTPConnectionError TODO and update MCPProtocolVersion to 2025-11-25 #1619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,11 @@ import ( | |
| "bytes" | ||
| "context" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "log/slog" | ||
| "net" | ||
| "net/http" | ||
| "strings" | ||
| "sync/atomic" | ||
|
|
@@ -31,7 +33,7 @@ const ( | |
| ) | ||
|
|
||
| // MCPProtocolVersion is the MCP protocol version used in initialization requests. | ||
| const MCPProtocolVersion = "2024-11-05" | ||
| const MCPProtocolVersion = "2025-11-25" | ||
|
Comment on lines
35
to
+36
|
||
|
|
||
| // requestIDCounter is used to generate unique request IDs for HTTP requests | ||
| var requestIDCounter uint64 | ||
|
|
@@ -46,18 +48,18 @@ type httpRequestResult struct { | |
| // transportConnector is a function that creates an SDK transport for a given URL and HTTP client | ||
| type transportConnector func(url string, httpClient *http.Client) sdk.Transport | ||
|
|
||
| // isHTTPConnectionError checks if an error is a network connection error | ||
| // This helper reduces code duplication for checking common connection error patterns. | ||
| // Note: Uses string matching which is fragile but consistent with existing patterns in the codebase. | ||
| // TODO: Consider using errors.Is() or type assertions (*net.OpError) for more robust error classification. | ||
| // isHTTPConnectionError checks if an error is a network connection error. | ||
| // It uses errors.As to inspect the underlying *net.OpError for dial operations, | ||
| // which covers connection refused, no such host, and network unreachable errors. | ||
| func isHTTPConnectionError(err error) bool { | ||
| if err == nil { | ||
| return false | ||
| } | ||
| errMsg := err.Error() | ||
| return strings.Contains(errMsg, "connection refused") || | ||
| strings.Contains(errMsg, "no such host") || | ||
| strings.Contains(errMsg, "network is unreachable") | ||
| var opErr *net.OpError | ||
| if errors.As(err, &opErr) { | ||
| return opErr.Op == "dial" | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // parseSSEResponse extracts JSON data from SSE-formatted response | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The “wrapped” test case uses
fmt.Errorf(...%w...), buthttp.Client.Dotypically wraps dial failures in*url.Error. If the goal is to validate the real error chain thatexecuteHTTPRequestwill see, use aurl.Errorwrapper here so the test covers*url.Error -> *net.OpErrorunwrapping explicitly.