2424import java .util .function .Function ;
2525
2626import io .modelcontextprotocol .spec .McpSchema ;
27+ import org .slf4j .Logger ;
28+ import org .slf4j .LoggerFactory ;
2729import org .springaicommunity .mcp .annotation .McpElicitation ;
2830import org .springaicommunity .mcp .annotation .McpLogging ;
2931import org .springaicommunity .mcp .annotation .McpProgress ;
6264public class ClientMcpSyncHandlersRegistry extends AbstractClientMcpHandlerRegistry
6365 implements SmartInitializingSingleton {
6466
67+ private static final Logger logger = LoggerFactory .getLogger (ClientMcpSyncHandlersRegistry .class );
68+
6569 private final Map <String , Function <McpSchema .CreateMessageRequest , McpSchema .CreateMessageResult >> samplingHandlers = new HashMap <>();
6670
6771 private final Map <String , Function <McpSchema .ElicitRequest , McpSchema .ElicitResult >> elicitationHandlers = new HashMap <>();
@@ -90,6 +94,8 @@ public McpSchema.ClientCapabilities getCapabilities(String clientName) {
9094 * @see McpSampling
9195 */
9296 public McpSchema .CreateMessageResult handleSampling (String name , McpSchema .CreateMessageRequest samplingRequest ) {
97+ logger .debug ("Handling sampling request for client {}" , name );
98+
9399 var handler = this .samplingHandlers .get (name );
94100 if (handler != null ) {
95101 return handler .apply (samplingRequest );
@@ -104,6 +110,8 @@ public McpSchema.CreateMessageResult handleSampling(String name, McpSchema.Creat
104110 * @see McpElicitation
105111 */
106112 public McpSchema .ElicitResult handleElicitation (String name , McpSchema .ElicitRequest elicitationRequest ) {
113+ logger .debug ("Handling elicitation request for client {}" , name );
114+
107115 var handler = this .elicitationHandlers .get (name );
108116 if (handler != null ) {
109117 return handler .apply (elicitationRequest );
@@ -118,9 +126,10 @@ public McpSchema.ElicitResult handleElicitation(String name, McpSchema.ElicitReq
118126 * @see McpLogging
119127 */
120128 public void handleLogging (String name , McpSchema .LoggingMessageNotification loggingMessageNotification ) {
129+ logger .debug ("Handling logging notification for client {}" , name );
130+
121131 var consumers = this .loggingHandlers .get (name );
122132 if (consumers == null ) {
123- // TODO handle
124133 return ;
125134 }
126135 for (var consumer : consumers ) {
@@ -134,9 +143,10 @@ public void handleLogging(String name, McpSchema.LoggingMessageNotification logg
134143 * @see McpProgress
135144 */
136145 public void handleProgress (String name , McpSchema .ProgressNotification progressNotification ) {
146+ logger .debug ("Handling progress notification for client {}" , name );
147+
137148 var consumers = this .progressHandlers .get (name );
138149 if (consumers == null ) {
139- // TODO handle
140150 return ;
141151 }
142152 for (var consumer : consumers ) {
@@ -150,9 +160,10 @@ public void handleProgress(String name, McpSchema.ProgressNotification progressN
150160 * @see McpToolListChanged
151161 */
152162 public void handleToolListChanged (String name , List <McpSchema .Tool > updatedTools ) {
163+ logger .debug ("Handling tool list changed notification for client {}" , name );
164+
153165 var consumers = this .toolListChangedHandlers .get (name );
154166 if (consumers == null ) {
155- // TODO handle
156167 return ;
157168 }
158169 for (var consumer : consumers ) {
@@ -166,9 +177,10 @@ public void handleToolListChanged(String name, List<McpSchema.Tool> updatedTools
166177 * @see McpPromptListChanged
167178 */
168179 public void handlePromptListChanged (String name , List <McpSchema .Prompt > updatedPrompts ) {
180+ logger .debug ("Handling prompt list changed notification for client {}" , name );
181+
169182 var consumers = this .promptListChangedHandlers .get (name );
170183 if (consumers == null ) {
171- // TODO handle
172184 return ;
173185 }
174186 for (var consumer : consumers ) {
@@ -182,9 +194,10 @@ public void handlePromptListChanged(String name, List<McpSchema.Prompt> updatedP
182194 * @see McpResourceListChanged
183195 */
184196 public void handleResourceListChanged (String name , List <McpSchema .Resource > updatedResources ) {
197+ logger .debug ("Handling resource list changed notification for client {}" , name );
198+
185199 var consumers = this .resourceListChangedHandlers .get (name );
186200 if (consumers == null ) {
187- // TODO handle
188201 return ;
189202 }
190203 for (var consumer : consumers ) {
@@ -200,6 +213,7 @@ public void afterSingletonsInstantiated() {
200213 .samplingSpecifications (new ArrayList <>(beansByAnnotation .get (McpSampling .class )));
201214 for (var samplingSpec : samplingSpecs ) {
202215 for (var client : samplingSpec .clients ()) {
216+ logger .debug ("Registering sampling handler for {}" , client );
203217 this .samplingHandlers .put (client , samplingSpec .samplingHandler ());
204218 }
205219 }
@@ -208,6 +222,7 @@ public void afterSingletonsInstantiated() {
208222 .elicitationSpecifications (new ArrayList <>(beansByAnnotation .get (McpElicitation .class )));
209223 for (var elicitationSpec : elicitationSpecs ) {
210224 for (var client : elicitationSpec .clients ()) {
225+ logger .debug ("Registering elicitation handler for {}" , client );
211226 this .elicitationHandlers .put (client , elicitationSpec .elicitationHandler ());
212227 }
213228 }
@@ -216,6 +231,7 @@ public void afterSingletonsInstantiated() {
216231 .loggingSpecifications (new ArrayList <>(beansByAnnotation .get (McpLogging .class )));
217232 for (var loggingSpec : loggingSpecs ) {
218233 for (var client : loggingSpec .clients ()) {
234+ logger .debug ("Registering logging handler for {}" , client );
219235 this .loggingHandlers .computeIfAbsent (client , k -> new ArrayList <>()).add (loggingSpec .loggingHandler ());
220236 }
221237 }
@@ -224,6 +240,7 @@ public void afterSingletonsInstantiated() {
224240 .progressSpecifications (new ArrayList <>(beansByAnnotation .get (McpProgress .class )));
225241 for (var progressSpec : progressSpecs ) {
226242 for (var client : progressSpec .clients ()) {
243+ logger .debug ("Registering progress handler for {}" , client );
227244 this .progressHandlers .computeIfAbsent (client , k -> new ArrayList <>())
228245 .add (progressSpec .progressHandler ());
229246 }
@@ -233,6 +250,7 @@ public void afterSingletonsInstantiated() {
233250 .toolListChangedSpecifications (new ArrayList <>(beansByAnnotation .get (McpToolListChanged .class )));
234251 for (var toolsListChangedSpec : toolsListChangedSpecs ) {
235252 for (var client : toolsListChangedSpec .clients ()) {
253+ logger .debug ("Registering tool list changed handler for {}" , client );
236254 this .toolListChangedHandlers .computeIfAbsent (client , k -> new ArrayList <>())
237255 .add (toolsListChangedSpec .toolListChangeHandler ());
238256 }
@@ -242,6 +260,7 @@ public void afterSingletonsInstantiated() {
242260 .promptListChangedSpecifications (new ArrayList <>(beansByAnnotation .get (McpPromptListChanged .class )));
243261 for (var promptListChangedSpec : promptListChangedSpecs ) {
244262 for (var client : promptListChangedSpec .clients ()) {
263+ logger .debug ("Registering prompt list changed handler for {}" , client );
245264 this .promptListChangedHandlers .computeIfAbsent (client , k -> new ArrayList <>())
246265 .add (promptListChangedSpec .promptListChangeHandler ());
247266 }
@@ -251,6 +270,7 @@ public void afterSingletonsInstantiated() {
251270 .resourceListChangedSpecifications (new ArrayList <>(beansByAnnotation .get (McpResourceListChanged .class )));
252271 for (var resourceListChangedSpec : resourceListChangedSpecs ) {
253272 for (var client : resourceListChangedSpec .clients ()) {
273+ logger .debug ("Registering resource list changed handler for {}" , client );
254274 this .resourceListChangedHandlers .computeIfAbsent (client , k -> new ArrayList <>())
255275 .add (resourceListChangedSpec .resourceListChangeHandler ());
256276 }
0 commit comments