@@ -52,6 +52,10 @@ public class McpServerSession implements McpSession {
5252
5353 private Authentication authentication ;
5454
55+ private boolean proxySession = false ;
56+
57+ boolean isExchangeEmitted = false ;
58+
5559 private static final int STATE_UNINITIALIZED = 0 ;
5660
5761 private static final int STATE_INITIALIZING = 1 ;
@@ -107,6 +111,14 @@ public McpServerTransport getTransport() {
107111 return transport ;
108112 }
109113
114+ public boolean isProxySession () {
115+ return proxySession ;
116+ }
117+
118+ public void setProxySession (boolean proxySession ) {
119+ this .proxySession = proxySession ;
120+ }
121+
110122 /**
111123 * Called upon successful initialization sequence between the client and the server
112124 * with the client capabilities and information.
@@ -240,6 +252,11 @@ private Mono<McpSchema.JSONRPCResponse> handleIncomingRequest(McpSchema.JSONRPCR
240252 error .message (), error .data ())));
241253 }
242254
255+ if (proxySession && !isExchangeEmitted ) {
256+ exchangeSink
257+ .tryEmitValue (new McpAsyncServerExchange (this , clientCapabilities .get (), clientInfo .get ()));
258+ isExchangeEmitted = true ;
259+ }
243260 resultMono = this .exchangeSink .asMono ().flatMap (exchange -> handler .handle (exchange , request .params ()));
244261 }
245262 return resultMono
@@ -261,6 +278,7 @@ private Mono<Void> handleIncomingNotification(McpSchema.JSONRPCNotification noti
261278 if (McpSchema .METHOD_NOTIFICATION_INITIALIZED .equals (notification .method ())) {
262279 this .state .lazySet (STATE_INITIALIZED );
263280 exchangeSink .tryEmitValue (new McpAsyncServerExchange (this , clientCapabilities .get (), clientInfo .get ()));
281+ isExchangeEmitted = true ;
264282 return this .initNotificationHandler .handle ();
265283 }
266284
0 commit comments