mcp-agent
mcp-agent copied to clipboard
Allow passing headers to SSE server
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.
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.
And thank you for offering to implement @Nicba1010!
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.