mcp-agent icon indicating copy to clipboard operation
mcp-agent copied to clipboard

Allow passing headers to SSE server

Open Nicba1010 opened this issue 8 months ago • 3 comments

I have a use-case to pass some headers to the SSE server. The sse_client from mcp.client.sse.sse_client accepts headers in its function signature. Would you be comfortable with adding configurable headers to the config for an sse mcp server? I tried to just put the data I need to pass in the route, like http://mc-server/dataineedtopass/sse. And it works fine, but when the library connects to /messages/ it completely ignores the /dataineedtopass/ part and doesn't preserve it.

I would implement it if you give the goahead.

Nicba1010 avatar Mar 12 '25 18:03 Nicba1010

I have a use-case to pass some headers to the SSE server. The sse_client from mcp.client.sse.sse_client accepts headers in its function signature. Would you be comfortable with adding configurable headers to the config for an sse mcp server? I tried to just put the data I need to pass in the route, like http://mc-server/dataineedtopass/sse. And it works fine, but when the library connects to /messages/ it completely ignores the /dataineedtopass/ part and doesn't preserve it.

I would implement it if you give the goahead.

Go for it! Out of curiosity how does Claude Desktop handle it? I am ultimately using the base sse_client support in the MCP package itself, so it's possible there may be a bug with it ignoring some parts of the url.

I imagine developers may want both programmatic setting of headers as well as config-based setting for static definition, so both should work.

saqadri avatar Mar 12 '25 18:03 saqadri

And thank you for offering to implement @Nicba1010!

saqadri avatar Mar 12 '25 18:03 saqadri

I am unsure how Claude desktop would handle it, but I think the bug (if it even is a bug) is in the base sse_client itself.

I have implemented header support, it was quite simple.

And thank you for offering to implement @Nicba1010!

Thank YOU! For being so prompt in responding to my (sometimes stupid, as is the case of #53) issues.

I have passed the headers through via the MCPServerSettings model, seems like the right place, it's where everything else is defined.

Nicba1010 avatar Mar 12 '25 19:03 Nicba1010