@@ -68,23 +68,35 @@ public class McpSyncClient implements AutoCloseable {
6868
6969 private static final Logger logger = LoggerFactory .getLogger (McpSyncClient .class );
7070
71- private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ();
72-
7371 // TODO: Consider providing a client config to set this properly
7472 // this is currently a concern only because AutoCloseable is used - perhaps it
7573 // is not a requirement?
7674 private static final long DEFAULT_CLOSE_TIMEOUT_MS = 10_000L ;
7775
7876 private final McpAsyncClient delegate ;
7977
78+ /** JSON object mapper for message serialization/deserialization */
79+ protected ObjectMapper objectMapper ;
80+
8081 /**
8182 * Create a new McpSyncClient with the given delegate.
8283 * @param delegate the asynchronous kernel on top of which this synchronous client
8384 * provides a blocking API.
8485 */
8586 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 ) {
8697 Assert .notNull (delegate , "The delegate can not be null" );
8798 this .delegate = delegate ;
99+ this .objectMapper = objectMapper ;
88100 }
89101
90102 /**
@@ -247,10 +259,10 @@ public McpSchema.CallToolResult callTool(McpSchema.CallToolRequest callToolReque
247259
248260 try {
249261 // Convert outputSchema to string
250- String outputSchemaString = OBJECT_MAPPER .writeValueAsString (outputSchema );
262+ String outputSchemaString = this . objectMapper .writeValueAsString (outputSchema );
251263
252264 // Create JsonSchema validator
253- ObjectNode schemaNode = (ObjectNode ) OBJECT_MAPPER .readTree (outputSchemaString );
265+ ObjectNode schemaNode = (ObjectNode ) this . objectMapper .readTree (outputSchemaString );
254266 // Set additional properties to false if not specified in output schema
255267 if (!schemaNode .has ("additionalProperties" )) {
256268 schemaNode .put ("additionalProperties" , false );
@@ -259,7 +271,7 @@ public McpSchema.CallToolResult callTool(McpSchema.CallToolRequest callToolReque
259271 .getSchema (schemaNode );
260272
261273 // Convert structured content in reult to JsonNode
262- JsonNode jsonNode = OBJECT_MAPPER .valueToTree (result .structuredContent ());
274+ JsonNode jsonNode = this . objectMapper .valueToTree (result .structuredContent ());
263275
264276 // Validate outputSchema against structuredContent
265277 Set <ValidationMessage > validationResult = schema .validate (jsonNode );
@@ -415,8 +427,4 @@ public McpSchema.CompleteResult completeCompletion(McpSchema.CompleteRequest com
415427 return this .delegate .completeCompletion (completeRequest ).block ();
416428 }
417429
418- private void isStrict (boolean b ) {
419- throw new UnsupportedOperationException ("Not supported yet." );
420- }
421-
422430}
0 commit comments