Skip to content

Commit da33720

Browse files
committed
Standardize comments. Add Example comment. Add header conflict protection to Initialize
1 parent a2d8ace commit da33720

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

client/sse.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ func WithSSEReadTimeout(timeout time.Duration) ClientOption {
5858

5959
// NewSSEMCPClient creates a new SSE-based MCP client with the given base URL.
6060
// Returns an error if the URL is invalid.
61+
// Example:
62+
//
63+
// // Create a client with authentication headers
64+
// client, err := NewSSEMCPClient(
65+
// "https://mcp.example.com",
66+
// WithHeaders(map[string]string{
67+
// "Authorization": "Bearer your-token-here",
68+
// }),
69+
// )
6170
func NewSSEMCPClient(baseURL string, options ...ClientOption) (*SSEMCPClient, error) {
6271
parsedURL, err := url.Parse(baseURL)
6372
if err != nil {
@@ -97,7 +106,7 @@ func (c *SSEMCPClient) Start(ctx context.Context) error {
97106
req.Header.Set("Cache-Control", "no-cache")
98107
req.Header.Set("Connection", "keep-alive")
99108

100-
// set custom http headers
109+
// Set custom http headers
101110
for k, v := range c.headers {
102111
// Skip standard headers that should not be overridden
103112
switch k {
@@ -314,7 +323,7 @@ func (c *SSEMCPClient) sendRequest(
314323
}
315324

316325
req.Header.Set("Content-Type", "application/json")
317-
// set custom http headers
326+
// Set custom http headers
318327
for k, v := range c.headers {
319328
// Skip standard headers that should not be overridden
320329
switch k {
@@ -409,8 +418,13 @@ func (c *SSEMCPClient) Initialize(
409418
}
410419

411420
req.Header.Set("Content-Type", "application/json")
412-
// set custom http headers
421+
// Set custom http headers
413422
for k, v := range c.headers {
423+
// Skip standard headers that should not be overridden
424+
switch k {
425+
case "Accept", "Cache-Control", "Connection", "Content-Type":
426+
continue
427+
}
414428
req.Header.Set(k, v)
415429
}
416430

0 commit comments

Comments
 (0)