Skip to content

Bcain99 Fixes #151

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions client/sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ func NewSSEMCPClient(baseURL string, options ...ClientOption) (*SSEMCPClient, er
}

smc := &SSEMCPClient{
baseURL: parsedURL,
httpClient: &http.Client{},
baseURL: parsedURL,
//httpClient: &http.Client{},
httpClient: &http.Client{
Transport: &http.Transport{
MaxIdleConns: 100,
MaxIdleConnsPerHost: 10,
IdleConnTimeout: 90 * time.Second,
DisableKeepAlives: false,
},
},
Comment on lines +60 to +67
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to implement this as a WithTransport(*http.Transport) option, rather than hard-coding the settings?

responses: make(map[int64]chan RPCResponse),
done: make(chan struct{}),
endpointChan: make(chan struct{}),
Expand Down Expand Up @@ -302,11 +310,17 @@ func (c *SSEMCPClient) sendRequest(
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}
defer resp.Body.Close()

// drain any io
body, err := io.ReadAll(resp.Body)
resp.Body.Close()

if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}

if resp.StatusCode != http.StatusOK &&
resp.StatusCode != http.StatusAccepted {
body, _ := io.ReadAll(resp.Body)
return nil, fmt.Errorf(
"request failed with status %d: %s",
resp.StatusCode,
Expand Down