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:
parent
fa017c04c3
commit
d7d9eab3f8
3 changed files with 166 additions and 21 deletions
|
|
@ -109,6 +109,7 @@ public class McpClientFactoryTests
|
|||
private readonly Channel<JsonRpcMessage> _channel = Channel.CreateUnbounded<JsonRpcMessage>();
|
||||
|
||||
public bool IsConnected => true;
|
||||
public string? SessionId => null;
|
||||
|
||||
public ChannelReader<JsonRpcMessage> MessageReader => _channel.Reader;
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -650,6 +650,7 @@ public class McpServerTests : LoggedTest
|
|||
|
||||
public ValueTask DisposeAsync() => default;
|
||||
|
||||
public string? SessionId => throw new NotImplementedException();
|
||||
public Implementation? ClientInfo => throw new NotImplementedException();
|
||||
public IServiceProvider? Services => throw new NotImplementedException();
|
||||
public LoggingLevel? LoggingLevel => throw new NotImplementedException();
|
||||
|
|
|
|||
Loading…
Reference in a new issue