@@ -68,23 +68,35 @@ public class McpSyncClient implements AutoCloseable {
68
68
69
69
private static final Logger logger = LoggerFactory .getLogger (McpSyncClient .class );
70
70
71
- private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ();
72
-
73
71
// TODO: Consider providing a client config to set this properly
74
72
// this is currently a concern only because AutoCloseable is used - perhaps it
75
73
// is not a requirement?
76
74
private static final long DEFAULT_CLOSE_TIMEOUT_MS = 10_000L ;
77
75
78
76
private final McpAsyncClient delegate ;
79
77
78
+ /** JSON object mapper for message serialization/deserialization */
79
+ protected ObjectMapper objectMapper ;
80
+
80
81
/**
81
82
* Create a new McpSyncClient with the given delegate.
82
83
* @param delegate the asynchronous kernel on top of which this synchronous client
83
84
* provides a blocking API.
84
85
*/
85
86
McpSyncClient (McpAsyncClient delegate ) {
87
+ this (delegate , new ObjectMapper ());
88
+ }
89
+
90
+ /**
91
+ * Create a new McpSyncClient with the given delegate.
92
+ * @param delegate the asynchronous kernel on top of which this synchronous client
93
+ * provides a blocking API.
94
+ * @param objectMapper the object mapper for JSON serialization/deserialization
95
+ */
96
+ McpSyncClient (McpAsyncClient delegate , ObjectMapper objectMapper ) {
86
97
Assert .notNull (delegate , "The delegate can not be null" );
87
98
this .delegate = delegate ;
99
+ this .objectMapper = objectMapper ;
88
100
}
89
101
90
102
/**
@@ -247,10 +259,10 @@ public McpSchema.CallToolResult callTool(McpSchema.CallToolRequest callToolReque
247
259
248
260
try {
249
261
// Convert outputSchema to string
250
- String outputSchemaString = OBJECT_MAPPER .writeValueAsString (outputSchema );
262
+ String outputSchemaString = this . objectMapper .writeValueAsString (outputSchema );
251
263
252
264
// Create JsonSchema validator
253
- ObjectNode schemaNode = (ObjectNode ) OBJECT_MAPPER .readTree (outputSchemaString );
265
+ ObjectNode schemaNode = (ObjectNode ) this . objectMapper .readTree (outputSchemaString );
254
266
// Set additional properties to false if not specified in output schema
255
267
if (!schemaNode .has ("additionalProperties" )) {
256
268
schemaNode .put ("additionalProperties" , false );
@@ -259,7 +271,7 @@ public McpSchema.CallToolResult callTool(McpSchema.CallToolRequest callToolReque
259
271
.getSchema (schemaNode );
260
272
261
273
// Convert structured content in reult to JsonNode
262
- JsonNode jsonNode = OBJECT_MAPPER .valueToTree (result .structuredContent ());
274
+ JsonNode jsonNode = this . objectMapper .valueToTree (result .structuredContent ());
263
275
264
276
// Validate outputSchema against structuredContent
265
277
Set <ValidationMessage > validationResult = schema .validate (jsonNode );
@@ -415,8 +427,4 @@ public McpSchema.CompleteResult completeCompletion(McpSchema.CompleteRequest com
415
427
return this .delegate .completeCompletion (completeRequest ).block ();
416
428
}
417
429
418
- private void isStrict (boolean b ) {
419
- throw new UnsupportedOperationException ("Not supported yet." );
420
- }
421
-
422
430
}
0 commit comments