1313import java .util .concurrent .atomic .AtomicBoolean ;
1414import java .util .function .Function ;
1515
16- import com . fasterxml . jackson . core . type . TypeReference ;
16+ import io . modelcontextprotocol . schema . McpType ;
1717import io .modelcontextprotocol .session .McpClientSession ;
1818import io .modelcontextprotocol .session .McpClientSession .NotificationHandler ;
1919import io .modelcontextprotocol .session .McpClientSession .RequestHandler ;
2020import io .modelcontextprotocol .spec .McpClientTransport ;
2121import io .modelcontextprotocol .spec .McpError ;
22- import io .modelcontextprotocol .spec .McpSchema ;
23- import io .modelcontextprotocol .spec .McpSchema .ClientCapabilities ;
24- import io .modelcontextprotocol .spec .McpSchema .CreateMessageRequest ;
25- import io .modelcontextprotocol .spec .McpSchema .CreateMessageResult ;
26- import io .modelcontextprotocol .spec .McpSchema .GetPromptRequest ;
27- import io .modelcontextprotocol .spec .McpSchema .GetPromptResult ;
28- import io .modelcontextprotocol .spec .McpSchema .ListPromptsResult ;
29- import io .modelcontextprotocol .spec .McpSchema .LoggingLevel ;
30- import io .modelcontextprotocol .spec .McpSchema .LoggingMessageNotification ;
31- import io .modelcontextprotocol .spec .McpSchema .PaginatedRequest ;
32- import io .modelcontextprotocol .spec .McpSchema .Root ;
22+ import io .modelcontextprotocol .schema .McpSchema ;
23+ import io .modelcontextprotocol .schema .McpSchema .ClientCapabilities ;
24+ import io .modelcontextprotocol .schema .McpSchema .CreateMessageRequest ;
25+ import io .modelcontextprotocol .schema .McpSchema .CreateMessageResult ;
26+ import io .modelcontextprotocol .schema .McpSchema .GetPromptRequest ;
27+ import io .modelcontextprotocol .schema .McpSchema .GetPromptResult ;
28+ import io .modelcontextprotocol .schema .McpSchema .ListPromptsResult ;
29+ import io .modelcontextprotocol .schema .McpSchema .LoggingLevel ;
30+ import io .modelcontextprotocol .schema .McpSchema .LoggingMessageNotification ;
31+ import io .modelcontextprotocol .schema .McpSchema .PaginatedRequest ;
32+ import io .modelcontextprotocol .schema .McpSchema .Root ;
3333import io .modelcontextprotocol .spec .McpTransport ;
3434import io .modelcontextprotocol .util .Assert ;
3535import io .modelcontextprotocol .util .Utils ;
@@ -80,8 +80,7 @@ public class McpAsyncClient {
8080
8181 private static final Logger logger = LoggerFactory .getLogger (McpAsyncClient .class );
8282
83- private static TypeReference <Void > VOID_TYPE_REFERENCE = new TypeReference <>() {
84- };
83+ private static final McpType <Void > VOID_TYPE_REFERENCE = McpType .of (Void .class );
8584
8685 protected final Sinks .One <McpSchema .InitializeResult > initializedSink = Sinks .one ();
8786
@@ -337,8 +336,7 @@ public Mono<McpSchema.InitializeResult> initialize() {
337336 this .clientInfo ); // @formatter:on
338337
339338 Mono <McpSchema .InitializeResult > result = this .mcpSession .sendRequest (McpSchema .METHOD_INITIALIZE ,
340- initializeRequest , new TypeReference <McpSchema .InitializeResult >() {
341- });
339+ initializeRequest , McpType .of (McpSchema .InitializeResult .class ));
342340
343341 return result .flatMap (initializeResult -> {
344342
@@ -389,8 +387,7 @@ private <T> Mono<T> withInitializationCheck(String actionName,
389387 */
390388 public Mono <Object > ping () {
391389 return this .withInitializationCheck ("pinging the server" , initializedResult -> this .mcpSession
392- .sendRequest (McpSchema .METHOD_PING , null , new TypeReference <Object >() {
393- }));
390+ .sendRequest (McpSchema .METHOD_PING , null , McpType .of (Object .class )));
394391 }
395392
396393 // --------------------------
@@ -479,8 +476,7 @@ private RequestHandler<McpSchema.ListRootsResult> rootsListRequestHandler() {
479476 return params -> {
480477 @ SuppressWarnings ("unused" )
481478 McpSchema .PaginatedRequest request = transport .unmarshalFrom (params ,
482- new TypeReference <McpSchema .PaginatedRequest >() {
483- });
479+ McpType .of (McpSchema .PaginatedRequest .class ));
484480
485481 List <Root > roots = this .roots .values ().stream ().toList ();
486482
@@ -494,8 +490,7 @@ private RequestHandler<McpSchema.ListRootsResult> rootsListRequestHandler() {
494490 private RequestHandler <CreateMessageResult > samplingCreateMessageHandler () {
495491 return params -> {
496492 McpSchema .CreateMessageRequest request = transport .unmarshalFrom (params ,
497- new TypeReference <McpSchema .CreateMessageRequest >() {
498- });
493+ McpType .of (McpSchema .CreateMessageRequest .class ));
499494
500495 return this .samplingHandler .apply (request );
501496 };
@@ -504,11 +499,11 @@ private RequestHandler<CreateMessageResult> samplingCreateMessageHandler() {
504499 // --------------------------
505500 // Tools
506501 // --------------------------
507- private static final TypeReference <McpSchema .CallToolResult > CALL_TOOL_RESULT_TYPE_REF = new TypeReference <>() {
508- } ;
502+ private static final McpType <McpSchema .CallToolResult > CALL_TOOL_RESULT_TYPE_REF = McpType
503+ . of ( McpSchema . CallToolResult . class ) ;
509504
510- private static final TypeReference <McpSchema .ListToolsResult > LIST_TOOLS_RESULT_TYPE_REF = new TypeReference <>() {
511- } ;
505+ private static final McpType <McpSchema .ListToolsResult > LIST_TOOLS_RESULT_TYPE_REF = McpType
506+ . of ( McpSchema . ListToolsResult . class ) ;
512507
513508 /**
514509 * Calls a tool provided by the server. Tools enable servers to expose executable
@@ -570,14 +565,14 @@ private NotificationHandler asyncToolsChangeNotificationHandler(
570565 // Resources
571566 // --------------------------
572567
573- private static final TypeReference <McpSchema .ListResourcesResult > LIST_RESOURCES_RESULT_TYPE_REF = new TypeReference <>() {
574- } ;
568+ private static final McpType <McpSchema .ListResourcesResult > LIST_RESOURCES_RESULT_TYPE_REF = McpType
569+ . of ( McpSchema . ListResourcesResult . class ) ;
575570
576- private static final TypeReference <McpSchema .ReadResourceResult > READ_RESOURCE_RESULT_TYPE_REF = new TypeReference <>() {
577- } ;
571+ private static final McpType <McpSchema .ReadResourceResult > READ_RESOURCE_RESULT_TYPE_REF = McpType
572+ . of ( McpSchema . ReadResourceResult . class ) ;
578573
579- private static final TypeReference <McpSchema .ListResourceTemplatesResult > LIST_RESOURCE_TEMPLATES_RESULT_TYPE_REF = new TypeReference <>() {
580- } ;
574+ private static final McpType <McpSchema .ListResourceTemplatesResult > LIST_RESOURCE_TEMPLATES_RESULT_TYPE_REF = McpType
575+ . of ( McpSchema . ListResourceTemplatesResult . class ) ;
581576
582577 /**
583578 * Retrieves the list of all resources provided by the server. Resources represent any
@@ -712,11 +707,11 @@ private NotificationHandler asyncResourcesChangeNotificationHandler(
712707 // --------------------------
713708 // Prompts
714709 // --------------------------
715- private static final TypeReference <McpSchema .ListPromptsResult > LIST_PROMPTS_RESULT_TYPE_REF = new TypeReference <>() {
716- } ;
710+ private static final McpType <McpSchema .ListPromptsResult > LIST_PROMPTS_RESULT_TYPE_REF = McpType
711+ . of ( McpSchema . ListPromptsResult . class ) ;
717712
718- private static final TypeReference <McpSchema .GetPromptResult > GET_PROMPT_RESULT_TYPE_REF = new TypeReference <>() {
719- } ;
713+ private static final McpType <McpSchema .GetPromptResult > GET_PROMPT_RESULT_TYPE_REF = McpType
714+ . of ( McpSchema . GetPromptResult . class ) ;
720715
721716 /**
722717 * Retrieves the list of all prompts provided by the server.
@@ -781,8 +776,7 @@ private NotificationHandler asyncLoggingNotificationHandler(
781776
782777 return params -> {
783778 McpSchema .LoggingMessageNotification loggingMessageNotification = transport .unmarshalFrom (params ,
784- new TypeReference <McpSchema .LoggingMessageNotification >() {
785- });
779+ McpType .of (McpSchema .LoggingMessageNotification .class ));
786780
787781 return Flux .fromIterable (loggingConsumers )
788782 .flatMap (consumer -> consumer .apply (loggingMessageNotification ))
@@ -804,8 +798,8 @@ public Mono<Void> setLoggingLevel(LoggingLevel loggingLevel) {
804798
805799 return this .withInitializationCheck ("setting logging level" , initializedResult -> {
806800 var params = new McpSchema .SetLevelRequest (loggingLevel );
807- return this .mcpSession .sendRequest (McpSchema .METHOD_LOGGING_SET_LEVEL , params , new TypeReference < Object >() {
808- }) .then ();
801+ return this .mcpSession .sendRequest (McpSchema .METHOD_LOGGING_SET_LEVEL , params , McpType . of ( Object . class ))
802+ .then ();
809803 });
810804 }
811805
@@ -816,13 +810,14 @@ public Mono<Void> setLoggingLevel(LoggingLevel loggingLevel) {
816810 */
817811 void setProtocolVersions (List <String > protocolVersions ) {
818812 this .protocolVersions = protocolVersions ;
813+
819814 }
820815
821816 // --------------------------
822817 // Completions
823818 // --------------------------
824- private static final TypeReference <McpSchema .CompleteResult > COMPLETION_COMPLETE_RESULT_TYPE_REF = new TypeReference <>() {
825- } ;
819+ private static final McpType <McpSchema .CompleteResult > COMPLETION_COMPLETE_RESULT_TYPE_REF = McpType
820+ . of ( McpSchema . CompleteResult . class ) ;
826821
827822 /**
828823 * Sends a completion/complete request to generate value suggestions based on a given
0 commit comments