|
41 | 41 | import org.slf4j.LoggerFactory; |
42 | 42 | import reactor.core.publisher.Flux; |
43 | 43 | import reactor.core.publisher.Mono; |
| 44 | +import reactor.util.context.ContextView; |
44 | 45 |
|
45 | 46 | /** |
46 | 47 | * The Model Context Protocol (MCP) client implementation that provides asynchronous |
@@ -314,13 +315,21 @@ public class McpAsyncClient { |
314 | 315 | }; |
315 | 316 |
|
316 | 317 | this.initializer = new LifecycleInitializer(clientCapabilities, clientInfo, transport.protocolVersions(), |
317 | | - initializationTimeout, ctx -> new McpClientSession(requestTimeout, transport, requestHandlers, |
318 | | - notificationHandlers, con -> con.contextWrite(ctx)), |
| 318 | + initializationTimeout, ctx -> createSession(ctx, requestTimeout, requestHandlers, notificationHandlers), |
319 | 319 | postInitializationHook); |
320 | 320 |
|
321 | 321 | this.transport.setExceptionHandler(this.initializer::handleException); |
322 | 322 | } |
323 | 323 |
|
| 324 | + /** |
| 325 | + * An extension point to create a custom McpClientSession with additional context. |
| 326 | + */ |
| 327 | + protected McpClientSession createSession(ContextView ctx, Duration requestTimeout, |
| 328 | + Map<String, RequestHandler<?>> requestHandlers, Map<String, NotificationHandler> notificationHandlers) { |
| 329 | + return new McpClientSession(requestTimeout, transport, requestHandlers, notificationHandlers, |
| 330 | + con -> con.contextWrite(ctx)); |
| 331 | + } |
| 332 | + |
324 | 333 | /** |
325 | 334 | * Get the current initialization result. |
326 | 335 | * @return the initialization result. |
|
0 commit comments