1515import io .modelcontextprotocol .spec .McpSchema ;
1616import io .modelcontextprotocol .util .Assert ;
1717import io .modelcontextprotocol .util .Utils ;
18+ import org .reactivestreams .Publisher ;
1819import reactor .core .publisher .Mono ;
1920import reactor .core .scheduler .Schedulers ;
2021
@@ -57,12 +58,14 @@ class McpClientFeatures {
5758 * @param roots the roots.
5859 * @param toolsChangeConsumers the tools change consumers.
5960 * @param resourcesChangeConsumers the resources change consumers.
61+ * @param resourcesUpdateConsumers the resources update consumers.
6062 * @param promptsChangeConsumers the prompts change consumers.
6163 * @param loggingConsumers the logging consumers.
6264 * @param progressConsumers the progress consumers.
6365 * @param samplingHandler the sampling handler.
6466 * @param elicitationHandler the elicitation handler.
6567 * @param enableCallToolSchemaCaching whether to enable call tool schema caching.
68+ * @param connectHook the connection hook.
6669 */
6770 record Async (McpSchema .Implementation clientInfo , McpSchema .ClientCapabilities clientCapabilities ,
6871 Map <String , McpSchema .Root > roots , List <Function <List <McpSchema .Tool >, Mono <Void >>> toolsChangeConsumers ,
@@ -73,20 +76,23 @@ record Async(McpSchema.Implementation clientInfo, McpSchema.ClientCapabilities c
7376 List <Function <McpSchema .ProgressNotification , Mono <Void >>> progressConsumers ,
7477 Function <McpSchema .CreateMessageRequest , Mono <McpSchema .CreateMessageResult >> samplingHandler ,
7578 Function <McpSchema .ElicitRequest , Mono <McpSchema .ElicitResult >> elicitationHandler ,
76- boolean enableCallToolSchemaCaching ) {
79+ boolean enableCallToolSchemaCaching , Function <? super Mono < Void >, ? extends Publisher < Void >> connectHook ) {
7780
7881 /**
7982 * Create an instance and validate the arguments.
83+ * @param clientInfo the client implementation information.
8084 * @param clientCapabilities the client capabilities.
8185 * @param roots the roots.
8286 * @param toolsChangeConsumers the tools change consumers.
8387 * @param resourcesChangeConsumers the resources change consumers.
88+ * @param resourcesUpdateConsumers the resources update consumers.
8489 * @param promptsChangeConsumers the prompts change consumers.
8590 * @param loggingConsumers the logging consumers.
8691 * @param progressConsumers the progress consumers.
8792 * @param samplingHandler the sampling handler.
8893 * @param elicitationHandler the elicitation handler.
8994 * @param enableCallToolSchemaCaching whether to enable call tool schema caching.
95+ * @param connectHook the connection hook.
9096 */
9197 public Async (McpSchema .Implementation clientInfo , McpSchema .ClientCapabilities clientCapabilities ,
9298 Map <String , McpSchema .Root > roots ,
@@ -98,7 +104,8 @@ public Async(McpSchema.Implementation clientInfo, McpSchema.ClientCapabilities c
98104 List <Function <McpSchema .ProgressNotification , Mono <Void >>> progressConsumers ,
99105 Function <McpSchema .CreateMessageRequest , Mono <McpSchema .CreateMessageResult >> samplingHandler ,
100106 Function <McpSchema .ElicitRequest , Mono <McpSchema .ElicitResult >> elicitationHandler ,
101- boolean enableCallToolSchemaCaching ) {
107+ boolean enableCallToolSchemaCaching ,
108+ Function <? super Mono <Void >, ? extends Publisher <Void >> connectHook ) {
102109
103110 Assert .notNull (clientInfo , "Client info must not be null" );
104111 this .clientInfo = clientInfo ;
@@ -118,6 +125,7 @@ public Async(McpSchema.Implementation clientInfo, McpSchema.ClientCapabilities c
118125 this .samplingHandler = samplingHandler ;
119126 this .elicitationHandler = elicitationHandler ;
120127 this .enableCallToolSchemaCaching = enableCallToolSchemaCaching ;
128+ this .connectHook = connectHook ;
121129 }
122130
123131 /**
@@ -134,7 +142,7 @@ public Async(McpSchema.Implementation clientInfo, McpSchema.ClientCapabilities c
134142 Function <McpSchema .ElicitRequest , Mono <McpSchema .ElicitResult >> elicitationHandler ) {
135143 this (clientInfo , clientCapabilities , roots , toolsChangeConsumers , resourcesChangeConsumers ,
136144 resourcesUpdateConsumers , promptsChangeConsumers , loggingConsumers , List .of (), samplingHandler ,
137- elicitationHandler , false );
145+ elicitationHandler , false , null );
138146 }
139147
140148 /**
@@ -193,7 +201,7 @@ public static Async fromSync(Sync syncSpec) {
193201 return new Async (syncSpec .clientInfo (), syncSpec .clientCapabilities (), syncSpec .roots (),
194202 toolsChangeConsumers , resourcesChangeConsumers , resourcesUpdateConsumers , promptsChangeConsumers ,
195203 loggingConsumers , progressConsumers , samplingHandler , elicitationHandler ,
196- syncSpec .enableCallToolSchemaCaching );
204+ syncSpec .enableCallToolSchemaCaching , syncSpec . connectHook () );
197205 }
198206 }
199207
@@ -206,12 +214,14 @@ public static Async fromSync(Sync syncSpec) {
206214 * @param roots the roots.
207215 * @param toolsChangeConsumers the tools change consumers.
208216 * @param resourcesChangeConsumers the resources change consumers.
217+ * @param resourcesUpdateConsumers the resources update consumers.
209218 * @param promptsChangeConsumers the prompts change consumers.
210219 * @param loggingConsumers the logging consumers.
211220 * @param progressConsumers the progress consumers.
212221 * @param samplingHandler the sampling handler.
213222 * @param elicitationHandler the elicitation handler.
214223 * @param enableCallToolSchemaCaching whether to enable call tool schema caching.
224+ * @param connectHook the connection hook.
215225 */
216226 public record Sync (McpSchema .Implementation clientInfo , McpSchema .ClientCapabilities clientCapabilities ,
217227 Map <String , McpSchema .Root > roots , List <Consumer <List <McpSchema .Tool >>> toolsChangeConsumers ,
@@ -222,7 +232,7 @@ public record Sync(McpSchema.Implementation clientInfo, McpSchema.ClientCapabili
222232 List <Consumer <McpSchema .ProgressNotification >> progressConsumers ,
223233 Function <McpSchema .CreateMessageRequest , McpSchema .CreateMessageResult > samplingHandler ,
224234 Function <McpSchema .ElicitRequest , McpSchema .ElicitResult > elicitationHandler ,
225- boolean enableCallToolSchemaCaching ) {
235+ boolean enableCallToolSchemaCaching , Function <? super Mono < Void >, ? extends Publisher < Void >> connectHook ) {
226236
227237 /**
228238 * Create an instance and validate the arguments.
@@ -238,6 +248,7 @@ public record Sync(McpSchema.Implementation clientInfo, McpSchema.ClientCapabili
238248 * @param samplingHandler the sampling handler.
239249 * @param elicitationHandler the elicitation handler.
240250 * @param enableCallToolSchemaCaching whether to enable call tool schema caching.
251+ * @param connectHook the connection hook.
241252 */
242253 public Sync (McpSchema .Implementation clientInfo , McpSchema .ClientCapabilities clientCapabilities ,
243254 Map <String , McpSchema .Root > roots , List <Consumer <List <McpSchema .Tool >>> toolsChangeConsumers ,
@@ -248,7 +259,8 @@ public Sync(McpSchema.Implementation clientInfo, McpSchema.ClientCapabilities cl
248259 List <Consumer <McpSchema .ProgressNotification >> progressConsumers ,
249260 Function <McpSchema .CreateMessageRequest , McpSchema .CreateMessageResult > samplingHandler ,
250261 Function <McpSchema .ElicitRequest , McpSchema .ElicitResult > elicitationHandler ,
251- boolean enableCallToolSchemaCaching ) {
262+ boolean enableCallToolSchemaCaching ,
263+ Function <? super Mono <Void >, ? extends Publisher <Void >> connectHook ) {
252264
253265 Assert .notNull (clientInfo , "Client info must not be null" );
254266 this .clientInfo = clientInfo ;
@@ -268,6 +280,7 @@ public Sync(McpSchema.Implementation clientInfo, McpSchema.ClientCapabilities cl
268280 this .samplingHandler = samplingHandler ;
269281 this .elicitationHandler = elicitationHandler ;
270282 this .enableCallToolSchemaCaching = enableCallToolSchemaCaching ;
283+ this .connectHook = connectHook ;
271284 }
272285
273286 /**
@@ -283,7 +296,7 @@ public Sync(McpSchema.Implementation clientInfo, McpSchema.ClientCapabilities cl
283296 Function <McpSchema .ElicitRequest , McpSchema .ElicitResult > elicitationHandler ) {
284297 this (clientInfo , clientCapabilities , roots , toolsChangeConsumers , resourcesChangeConsumers ,
285298 resourcesUpdateConsumers , promptsChangeConsumers , loggingConsumers , List .of (), samplingHandler ,
286- elicitationHandler , false );
299+ elicitationHandler , false , null );
287300 }
288301 }
289302
0 commit comments