Skip to content

Commit 0176c6c

Browse files
Address feedback.
1 parent e6182e7 commit 0176c6c

9 files changed

Lines changed: 22 additions & 14 deletions

File tree

src/ModelContextProtocol.Core/Client/McpClient.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,16 @@ public McpClient(IClientTransport clientTransport, McpClientOptions? options, IL
9595
}
9696

9797
/// <inheritdoc/>
98-
public ITransport Transport
98+
public string? SessionId
9999
{
100100
get
101101
{
102-
return _sessionTransport ?? throw new InvalidOperationException("Must have already initialized a session when invoking this property.");
102+
if (_sessionTransport is null)
103+
{
104+
throw new InvalidOperationException("Must have already initialized a session when invoking this property.");
105+
}
106+
107+
return _sessionTransport.SessionId;
103108
}
104109
}
105110

src/ModelContextProtocol.Core/IMcpEndpoint.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ namespace ModelContextProtocol;
2828
/// </remarks>
2929
public interface IMcpEndpoint : IAsyncDisposable
3030
{
31-
/// <summary>
32-
/// Gets the underlying transport driving the current MCP endpoint.
33-
/// </summary>
34-
ITransport Transport { get; }
31+
/// <summary>Gets an identifier associated with the current MCP session.</summary>
32+
/// <remarks>
33+
/// Typically populated in transports supporting multiple sessions such as Streamable HTTP or SSE.
34+
/// Can return <see langword="null"/> if the session hasn't initialized or if the transport doesn't
35+
/// support multiple sessions (as is the case with STDIO).
36+
/// </remarks>
37+
string? SessionId { get; }
3538

3639
/// <summary>
3740
/// Sends a JSON-RPC request to the connected endpoint and waits for a response.

src/ModelContextProtocol.Core/Server/DestinationBoundMcpServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace ModelContextProtocol.Server;
66
internal sealed class DestinationBoundMcpServer(McpServer server, ITransport? transport) : IMcpServer
77
{
88
public string EndpointName => server.EndpointName;
9-
public ITransport Transport => transport ?? server.Transport;
9+
public string? SessionId => transport?.SessionId ?? server.SessionId;
1010
public ClientCapabilities? ClientCapabilities => server.ClientCapabilities;
1111
public Implementation? ClientInfo => server.ClientInfo;
1212
public McpServerOptions ServerOptions => server.ServerOptions;

src/ModelContextProtocol.Core/Server/McpServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void Register<TPrimitive>(McpServerPrimitiveCollection<TPrimitive>? collection,
9797
}
9898

9999
/// <inheritdoc/>
100-
public ITransport Transport => _sessionTransport;
100+
public string? SessionId => _sessionTransport.SessionId;
101101

102102
/// <inheritdoc/>
103103
public ServerCapabilities ServerCapabilities { get; } = new();

tests/ModelContextProtocol.AspNetCore.Tests/HttpServerIntegrationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ public async Task Connect_TestServer_ShouldProvideServerFields()
5555

5656
if (ClientTransportOptions.Endpoint.AbsolutePath.EndsWith("/sse"))
5757
{
58-
Assert.Null(client.Transport.SessionId);
58+
Assert.Null(client.SessionId);
5959
}
6060
else
6161
{
62-
Assert.NotNull(client.Transport.SessionId);
62+
Assert.NotNull(client.SessionId);
6363
}
6464
}
6565

tests/ModelContextProtocol.TestServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private static ToolsCapability ConfigureTools()
184184
{
185185
return new CallToolResponse()
186186
{
187-
Content = [new Content() { Text = request.Server.Transport.SessionId, Type = "text" }]
187+
Content = [new Content() { Text = request.Server.SessionId, Type = "text" }]
188188
};
189189
}
190190
else if (request.Params?.Name == "sampleLLM")

tests/ModelContextProtocol.TestSseServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static CreateMessageRequestParams CreateRequestSamplingParams(string context, st
182182
{
183183
return new CallToolResponse()
184184
{
185-
Content = [new Content() { Text = request.Server.Transport.SessionId, Type = "text" }]
185+
Content = [new Content() { Text = request.Server.SessionId, Type = "text" }]
186186
};
187187
}
188188
else if (request.Params.Name == "sampleLLM")

tests/ModelContextProtocol.Tests/ClientIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public async Task Connect_ShouldProvideServerFields(string clientId)
5555
if (clientId != "everything") // Note: Comment the below assertion back when the everything server is updated to provide instructions
5656
Assert.NotNull(client.ServerInstructions);
5757

58-
Assert.Null(client.Transport.SessionId);
58+
Assert.Null(client.SessionId);
5959
}
6060

6161
[Theory]

tests/ModelContextProtocol.Tests/Server/McpServerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ public Task<JsonRpcResponse> SendRequestAsync(JsonRpcRequest request, Cancellati
650650

651651
public ValueTask DisposeAsync() => default;
652652

653-
public ITransport Transport => throw new NotImplementedException();
653+
public string? SessionId => throw new NotImplementedException();
654654
public Implementation? ClientInfo => throw new NotImplementedException();
655655
public IServiceProvider? Services => throw new NotImplementedException();
656656
public LoggingLevel? LoggingLevel => throw new NotImplementedException();

0 commit comments

Comments
 (0)