@@ -41,6 +41,9 @@ type SSEMCPClient struct {
4141
4242type ClientOption func (* SSEMCPClient )
4343
44+ // WithHeaders sets custom HTTP headers that will be included in all requests made by the client.
45+ // This is particularly useful for authentication (e.g., bearer tokens, API keys) and other
46+ // custom header requirements.
4447func WithHeaders (headers map [string ]string ) ClientOption {
4548 return func (sc * SSEMCPClient ) {
4649 sc .headers = headers
@@ -96,6 +99,11 @@ func (c *SSEMCPClient) Start(ctx context.Context) error {
9699
97100 // set custom http headers
98101 for k , v := range c .headers {
102+ // Skip standard headers that should not be overridden
103+ switch k {
104+ case "Accept" , "Cache-Control" , "Connection" , "Content-Type" :
105+ continue
106+ }
99107 req .Header .Set (k , v )
100108 }
101109
@@ -308,6 +316,11 @@ func (c *SSEMCPClient) sendRequest(
308316 req .Header .Set ("Content-Type" , "application/json" )
309317 // set custom http headers
310318 for k , v := range c .headers {
319+ // Skip standard headers that should not be overridden
320+ switch k {
321+ case "Accept" , "Cache-Control" , "Connection" , "Content-Type" :
322+ continue
323+ }
311324 req .Header .Set (k , v )
312325 }
313326
@@ -396,6 +409,10 @@ func (c *SSEMCPClient) Initialize(
396409 }
397410
398411 req .Header .Set ("Content-Type" , "application/json" )
412+ // set custom http headers
413+ for k , v := range c .headers {
414+ req .Header .Set (k , v )
415+ }
399416
400417 resp , err := c .httpClient .Do (req )
401418 if err != nil {
0 commit comments