-
Notifications
You must be signed in to change notification settings - Fork 194
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
SseClientTransport AdditionalHeaders not work #185
Comments
I was just about to add the same issue! I am trying to pass an API Key to an ASP.NET Core SSE server, but the additional headers do not show up on the server when I examine the HTTP headers in my middleware. |
cc: @halter73 |
I am facing the same issue with this looks like the SseClientSessionTransport is making the call but only sends in text/event-stream mediatype header. I'm assuming this is where we can map the additional options? csharp-sdk/src/ModelContextProtocol/Protocol/Transport/SseClientSessionTransport.cs Line 197 in 3b26bf8
|
It looks like nothing is currently reading SseClientTransportOptions.AdditionalHeaders. I'll fix that. In the meantime, you should be able to work around this using this SseClientTransport constructor that takes a custom HttpClient you can configure DefaultRequestHeaders on. |
@taimurlak This is something I'm actively looking into. As of a few minutes ago (see #225), I added a This is far from a complete solution though. It doesn't give you the headers from the JSON-RPC request to invoke the tool (although this often doesn't matter), and it isn't easy to get at from a It'd be nice if HttpContextAccessor worked, but that doesn't play super well with reading from a Channel. |
@halter73 Thanks you so much for quick response. can you please show me the example code so i can understand it well. |
I just confirmed that with the latest preview7 package, IHttpContextAccessor works. The ExecutionContext flows from the /sse request to the call to McpServer.RunAsync into the McpSession.ProcessMessagesAsync loop that ultimately calls the tool. This is despite the fact that the incoming JSON-RPC messages are coming in on a separate messages endpoint. using ModelContextProtocol.Server;
using System.ComponentModel;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpContextAccessor();
builder.Services
.AddMcpServer()
.WithToolsFromAssembly();
var app = builder.Build();
app.MapMcp();
app.Run("http://localhost:3001");
[McpServerToolType]
public class EchoTool(IHttpContextAccessor contextAccessor)
{
[McpServerTool, Description("Echoes the message back to the client.")]
public string Echo(string message)
=> $"hello {message}, {contextAccessor.HttpContext?.Request.Path ?? "(no HttpContext)"}";
}
|
@halter73 Thanks alot dude 🙌 |
Describe the bug
By checking code, look like when use the sse Transport, the header should pass like this
then the header key and value pass to a property named AdditionalHeaders. But this property not be used when send request.
The text was updated successfully, but these errors were encountered: