Send MCP-Protocol-Version header in Streamable HTTP client transport (#500)
This commit is contained in:
parent
b9b4a23005
commit
befa31d5c9
1 changed files with 69 additions and 24 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using ModelContextProtocol.Client;
|
||||
|
||||
namespace ModelContextProtocol.AspNetCore.Tests;
|
||||
|
|
@ -143,4 +144,38 @@ public class MapMcpStreamableHttpTests(ITestOutputHelper outputHelper) : MapMcpT
|
|||
|
||||
Assert.Equal("SseTestServer", mcpClient.ServerInfo.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StreamableHttpClient_SendsMcpProtocolVersionHeader_AfterInitialization()
|
||||
{
|
||||
var protocolVersionHeaderValues = new List<string?>();
|
||||
|
||||
Builder.Services.AddMcpServer().WithHttpTransport(ConfigureStateless).WithTools<EchoHttpContextUserTools>();
|
||||
|
||||
await using var app = Builder.Build();
|
||||
|
||||
app.Use(next =>
|
||||
{
|
||||
return async context =>
|
||||
{
|
||||
if (!StringValues.IsNullOrEmpty(context.Request.Headers["mcp-session-id"]))
|
||||
{
|
||||
protocolVersionHeaderValues.Add(context.Request.Headers["mcp-protocol-version"]);
|
||||
}
|
||||
|
||||
await next(context);
|
||||
};
|
||||
});
|
||||
|
||||
app.MapMcp();
|
||||
|
||||
await app.StartAsync(TestContext.Current.CancellationToken);
|
||||
|
||||
await using var mcpClient = await ConnectAsync();
|
||||
await mcpClient.ListToolsAsync(cancellationToken: TestContext.Current.CancellationToken);
|
||||
|
||||
// The header should be included in the GET request, the initialized notification, and the tools/list call.
|
||||
Assert.Equal(3, protocolVersionHeaderValues.Count);
|
||||
Assert.All(protocolVersionHeaderValues, v => Assert.Equal("2025-03-26", v));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue