@@ -42,7 +42,10 @@ public McpClient(IClientTransport clientTransport, McpClientOptions options, Mcp
42
42
43
43
SetRequestHandler < CreateMessageRequestParams , CreateMessageResult > (
44
44
RequestMethods . SamplingCreateMessage ,
45
- ( request , ct ) => samplingHandler ( request , ct ) ) ;
45
+ ( request , cancellationToken ) => samplingHandler (
46
+ request ,
47
+ request ? . Meta ? . ProgressToken is { } token ? new TokenProgress ( this , token ) : NullProgress . Instance ,
48
+ cancellationToken ) ) ;
46
49
}
47
50
48
51
if ( options . Capabilities ? . Roots is { } rootsCapability )
@@ -54,7 +57,7 @@ public McpClient(IClientTransport clientTransport, McpClientOptions options, Mcp
54
57
55
58
SetRequestHandler < ListRootsRequestParams , ListRootsResult > (
56
59
RequestMethods . RootsList ,
57
- ( request , ct ) => rootsHandler ( request , ct ) ) ;
60
+ ( request , cancellationToken ) => rootsHandler ( request , cancellationToken ) ) ;
58
61
}
59
62
}
60
63
@@ -79,29 +82,27 @@ public async Task ConnectAsync(CancellationToken cancellationToken = default)
79
82
{
80
83
// Connect transport
81
84
_sessionTransport = await _clientTransport . ConnectAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
82
- // We don't want the ConnectAsync token to cancel the session after we've successfully connected.
83
- // The base class handles cleaning up the session in DisposeAsync without our help.
84
- StartSession ( _sessionTransport , fullSessionCancellationToken : CancellationToken . None ) ;
85
+ StartSession ( _sessionTransport ) ;
85
86
86
87
// Perform initialization sequence
87
88
using var initializationCts = CancellationTokenSource . CreateLinkedTokenSource ( cancellationToken ) ;
88
89
initializationCts . CancelAfter ( _options . InitializationTimeout ) ;
89
90
90
- try
91
- {
92
- // Send initialize request
93
- var initializeResponse = await SendRequestAsync < InitializeResult > (
94
- new JsonRpcRequest
95
- {
96
- Method = RequestMethods . Initialize ,
97
- Params = new InitializeRequestParams ( )
91
+ try
92
+ {
93
+ // Send initialize request
94
+ var initializeResponse = await SendRequestAsync < InitializeResult > (
95
+ new JsonRpcRequest
98
96
{
99
- ProtocolVersion = _options . ProtocolVersion ,
100
- Capabilities = _options . Capabilities ?? new ClientCapabilities ( ) ,
101
- ClientInfo = _options . ClientInfo
102
- }
103
- } ,
104
- initializationCts . Token ) . ConfigureAwait ( false ) ;
97
+ Method = RequestMethods . Initialize ,
98
+ Params = new InitializeRequestParams ( )
99
+ {
100
+ ProtocolVersion = _options . ProtocolVersion ,
101
+ Capabilities = _options . Capabilities ?? new ClientCapabilities ( ) ,
102
+ ClientInfo = _options . ClientInfo
103
+ }
104
+ } ,
105
+ initializationCts . Token ) . ConfigureAwait ( false ) ;
105
106
106
107
// Store server information
107
108
_logger . ServerCapabilitiesReceived ( EndpointName ,
0 commit comments