Pass session id's to MCP endpoints. (#466)

* Pass session id's to MCP endpoints.

* Update src/ModelContextProtocol/Client/McpClient.cs

Co-authored-by: Stephen Halter <halter73@gmail.com>

* Update src/ModelContextProtocol.AspNetCore/StreamableHttpHandler.cs

Co-authored-by: Stephen Halter <halter73@gmail.com>

* Make init callback asynchronous.

* Address feedback.

---------

Co-authored-by: Stephen Halter <halter73@gmail.com>
This commit is contained in:
Eirik Tsarpalis 2025-06-12 16:56:57 +02:00 • committed by GitHub
commit d7d9eab3f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -54,6 +54,8 @@ public partial class ClientIntegrationTests : LoggedTest, IClassFixture<ClientIn
Assert.NotNull(client.ServerInfo);
if (clientId != "everything") // Note: Comment the below assertion back when the everything server is updated to provide instructions
Assert.NotNull(client.ServerInstructions);
Assert.Null(client.SessionId);
}
[Theory]
@ -94,6 +96,22 @@ public partial class ClientIntegrationTests : LoggedTest, IClassFixture<ClientIn
Assert.Equal("Echo: Hello MCP!", textContent.Text);
}
[Fact]
public async Task CallTool_Stdio_EchoSessionId_ReturnsNull()
{
// arrange
// act
await using var client = await _fixture.CreateClientAsync("test_server");
var result = await client.CallToolAsync("echoSessionId", cancellationToken: TestContext.Current.CancellationToken);
// assert
Assert.NotNull(result);
Assert.False(result.IsError);
var textContent = Assert.Single(result.Content, c => c.Type == "text");
Assert.Null(textContent.Text);
}
[Theory]
[MemberData(nameof(GetClients))]
public async Task CallTool_Stdio_ViaAIFunction_EchoServer(string clientId)