Skip to content

Commit 31f453e

Browse files
committed
Minor fixes/changes
1 parent 7011142 commit 31f453e

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

mcp-test/src/main/java/io/modelcontextprotocol/server/.LCKAbstractMcpSyncServerTests.java~

Lines changed: 0 additions & 1 deletion
This file was deleted.

mcp/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public class McpAsyncClient {
130130
/**
131131
* Cached tool output schemas.
132132
*/
133-
private final HashMap<String, McpSchema.JsonSchema> toolsOutputSchemaCache;
133+
private final ConcurrentHashMap<String, McpSchema.JsonSchema> toolsOutputSchemaCache;
134134

135135
/**
136136
* Roots define the boundaries of where servers can operate within the filesystem,
@@ -180,7 +180,7 @@ public class McpAsyncClient {
180180
this.transport = transport;
181181
this.roots = new ConcurrentHashMap<>(features.roots());
182182
this.initializationTimeout = initializationTimeout;
183-
this.toolsOutputSchemaCache = new HashMap<>();
183+
this.toolsOutputSchemaCache = new ConcurrentHashMap<>();
184184

185185
// Request Handlers
186186
Map<String, RequestHandler<?>> requestHandlers = new HashMap<>();

mcp/src/main/java/io/modelcontextprotocol/client/McpSyncClient.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)