13
13
import java .util .concurrent .atomic .AtomicBoolean ;
14
14
import java .util .function .Function ;
15
15
16
- import com . fasterxml . jackson . core . type . TypeReference ;
16
+ import io . modelcontextprotocol . schema . McpType ;
17
17
import io .modelcontextprotocol .session .McpClientSession ;
18
18
import io .modelcontextprotocol .session .McpClientSession .NotificationHandler ;
19
19
import io .modelcontextprotocol .session .McpClientSession .RequestHandler ;
20
20
import io .modelcontextprotocol .spec .McpClientTransport ;
21
21
import 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 ;
33
33
import io .modelcontextprotocol .spec .McpTransport ;
34
34
import io .modelcontextprotocol .util .Assert ;
35
35
import io .modelcontextprotocol .util .Utils ;
@@ -80,8 +80,7 @@ public class McpAsyncClient {
80
80
81
81
private static final Logger logger = LoggerFactory .getLogger (McpAsyncClient .class );
82
82
83
- private static TypeReference <Void > VOID_TYPE_REFERENCE = new TypeReference <>() {
84
- };
83
+ private static final McpType <Void > VOID_TYPE_REFERENCE = McpType .of (Void .class );
85
84
86
85
protected final Sinks .One <McpSchema .InitializeResult > initializedSink = Sinks .one ();
87
86
@@ -337,8 +336,7 @@ public Mono<McpSchema.InitializeResult> initialize() {
337
336
this .clientInfo ); // @formatter:on
338
337
339
338
Mono <McpSchema .InitializeResult > result = this .mcpSession .sendRequest (McpSchema .METHOD_INITIALIZE ,
340
- initializeRequest , new TypeReference <McpSchema .InitializeResult >() {
341
- });
339
+ initializeRequest , McpType .of (McpSchema .InitializeResult .class ));
342
340
343
341
return result .flatMap (initializeResult -> {
344
342
@@ -389,8 +387,7 @@ private <T> Mono<T> withInitializationCheck(String actionName,
389
387
*/
390
388
public Mono <Object > ping () {
391
389
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 )));
394
391
}
395
392
396
393
// --------------------------
@@ -479,8 +476,7 @@ private RequestHandler<McpSchema.ListRootsResult> rootsListRequestHandler() {
479
476
return params -> {
480
477
@ SuppressWarnings ("unused" )
481
478
McpSchema .PaginatedRequest request = transport .unmarshalFrom (params ,
482
- new TypeReference <McpSchema .PaginatedRequest >() {
483
- });
479
+ McpType .of (McpSchema .PaginatedRequest .class ));
484
480
485
481
List <Root > roots = this .roots .values ().stream ().toList ();
486
482
@@ -494,8 +490,7 @@ private RequestHandler<McpSchema.ListRootsResult> rootsListRequestHandler() {
494
490
private RequestHandler <CreateMessageResult > samplingCreateMessageHandler () {
495
491
return params -> {
496
492
McpSchema .CreateMessageRequest request = transport .unmarshalFrom (params ,
497
- new TypeReference <McpSchema .CreateMessageRequest >() {
498
- });
493
+ McpType .of (McpSchema .CreateMessageRequest .class ));
499
494
500
495
return this .samplingHandler .apply (request );
501
496
};
@@ -504,11 +499,11 @@ private RequestHandler<CreateMessageResult> samplingCreateMessageHandler() {
504
499
// --------------------------
505
500
// Tools
506
501
// --------------------------
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 ) ;
509
504
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 ) ;
512
507
513
508
/**
514
509
* Calls a tool provided by the server. Tools enable servers to expose executable
@@ -570,14 +565,14 @@ private NotificationHandler asyncToolsChangeNotificationHandler(
570
565
// Resources
571
566
// --------------------------
572
567
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 ) ;
575
570
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 ) ;
578
573
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 ) ;
581
576
582
577
/**
583
578
* Retrieves the list of all resources provided by the server. Resources represent any
@@ -712,11 +707,11 @@ private NotificationHandler asyncResourcesChangeNotificationHandler(
712
707
// --------------------------
713
708
// Prompts
714
709
// --------------------------
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 ) ;
717
712
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 ) ;
720
715
721
716
/**
722
717
* Retrieves the list of all prompts provided by the server.
@@ -781,8 +776,7 @@ private NotificationHandler asyncLoggingNotificationHandler(
781
776
782
777
return params -> {
783
778
McpSchema .LoggingMessageNotification loggingMessageNotification = transport .unmarshalFrom (params ,
784
- new TypeReference <McpSchema .LoggingMessageNotification >() {
785
- });
779
+ McpType .of (McpSchema .LoggingMessageNotification .class ));
786
780
787
781
return Flux .fromIterable (loggingConsumers )
788
782
.flatMap (consumer -> consumer .apply (loggingMessageNotification ))
@@ -804,8 +798,8 @@ public Mono<Void> setLoggingLevel(LoggingLevel loggingLevel) {
804
798
805
799
return this .withInitializationCheck ("setting logging level" , initializedResult -> {
806
800
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 ();
809
803
});
810
804
}
811
805
@@ -816,13 +810,14 @@ public Mono<Void> setLoggingLevel(LoggingLevel loggingLevel) {
816
810
*/
817
811
void setProtocolVersions (List <String > protocolVersions ) {
818
812
this .protocolVersions = protocolVersions ;
813
+
819
814
}
820
815
821
816
// --------------------------
822
817
// Completions
823
818
// --------------------------
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 ) ;
826
821
827
822
/**
828
823
* Sends a completion/complete request to generate value suggestions based on a given
0 commit comments