diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java
index 421f2fc7f..b70d5b783 100644
--- a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java
+++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java
@@ -121,7 +121,7 @@ public interface McpClient {
* @throws IllegalArgumentException if transport is null
*/
static SyncSpec sync(McpClientTransport transport) {
- return new SyncSpec(transport);
+ return new McpClient.SyncSpec(transport);
}
/**
@@ -156,44 +156,46 @@ static AsyncSpec async(McpClientTransport transport) {
*
Change notification handlers for tools, resources, and prompts
* Custom message sampling logic
*
+ *
+ * This class can be extended by subclass.
*/
class SyncSpec {
- private final McpClientTransport transport;
+ protected final McpClientTransport transport;
- private Duration requestTimeout = Duration.ofSeconds(20); // Default timeout
+ protected Duration requestTimeout = Duration.ofSeconds(20); // Default timeout
- private Duration initializationTimeout = Duration.ofSeconds(20);
+ protected Duration initializationTimeout = Duration.ofSeconds(20);
- private ClientCapabilities capabilities;
+ protected ClientCapabilities capabilities;
- private Implementation clientInfo = new Implementation("Java SDK MCP Client", "0.15.0");
+ protected Implementation clientInfo = new Implementation("Java SDK MCP Client", "0.15.0");
- private final Map roots = new HashMap<>();
+ protected final Map roots = new HashMap<>();
- private final List>> toolsChangeConsumers = new ArrayList<>();
+ protected final List>> toolsChangeConsumers = new ArrayList<>();
- private final List>> resourcesChangeConsumers = new ArrayList<>();
+ protected final List>> resourcesChangeConsumers = new ArrayList<>();
- private final List>> resourcesUpdateConsumers = new ArrayList<>();
+ protected final List>> resourcesUpdateConsumers = new ArrayList<>();
- private final List>> promptsChangeConsumers = new ArrayList<>();
+ protected final List>> promptsChangeConsumers = new ArrayList<>();
- private final List> loggingConsumers = new ArrayList<>();
+ protected final List> loggingConsumers = new ArrayList<>();
- private final List> progressConsumers = new ArrayList<>();
+ protected final List> progressConsumers = new ArrayList<>();
- private Function samplingHandler;
+ protected Function samplingHandler;
- private Function elicitationHandler;
+ protected Function elicitationHandler;
- private Supplier contextProvider = () -> McpTransportContext.EMPTY;
+ protected Supplier contextProvider = () -> McpTransportContext.EMPTY;
- private JsonSchemaValidator jsonSchemaValidator;
+ protected JsonSchemaValidator jsonSchemaValidator;
- private boolean enableCallToolSchemaCaching = false; // Default to false
+ protected boolean enableCallToolSchemaCaching = false; // Default to false
- private SyncSpec(McpClientTransport transport) {
+ public SyncSpec(McpClientTransport transport) {
Assert.notNull(transport, "Transport must not be null");
this.transport = transport;
}
@@ -496,42 +498,44 @@ public McpSyncClient build() {
* Change notification handlers for tools, resources, and prompts
* Custom message sampling logic
*
+ *
+ * This class can be extended by subclass.
*/
class AsyncSpec {
- private final McpClientTransport transport;
+ protected final McpClientTransport transport;
- private Duration requestTimeout = Duration.ofSeconds(20); // Default timeout
+ protected Duration requestTimeout = Duration.ofSeconds(20); // Default timeout
- private Duration initializationTimeout = Duration.ofSeconds(20);
+ protected Duration initializationTimeout = Duration.ofSeconds(20);
- private ClientCapabilities capabilities;
+ protected ClientCapabilities capabilities;
- private Implementation clientInfo = new Implementation("Java SDK MCP Client", "0.15.0");
+ protected Implementation clientInfo = new Implementation("Java SDK MCP Client", "0.15.0");
- private final Map roots = new HashMap<>();
+ protected final Map roots = new HashMap<>();
- private final List, Mono>> toolsChangeConsumers = new ArrayList<>();
+ protected final List, Mono>> toolsChangeConsumers = new ArrayList<>();
- private final List, Mono>> resourcesChangeConsumers = new ArrayList<>();
+ protected final List, Mono>> resourcesChangeConsumers = new ArrayList<>();
- private final List, Mono>> resourcesUpdateConsumers = new ArrayList<>();
+ protected final List, Mono>> resourcesUpdateConsumers = new ArrayList<>();
- private final List, Mono>> promptsChangeConsumers = new ArrayList<>();
+ protected final List, Mono>> promptsChangeConsumers = new ArrayList<>();
- private final List>> loggingConsumers = new ArrayList<>();
+ protected final List>> loggingConsumers = new ArrayList<>();
- private final List>> progressConsumers = new ArrayList<>();
+ protected final List>> progressConsumers = new ArrayList<>();
- private Function> samplingHandler;
+ protected Function> samplingHandler;
- private Function> elicitationHandler;
+ protected Function> elicitationHandler;
- private JsonSchemaValidator jsonSchemaValidator;
+ protected JsonSchemaValidator jsonSchemaValidator;
- private boolean enableCallToolSchemaCaching = false; // Default to false
+ protected boolean enableCallToolSchemaCaching = false; // Default to false
- private AsyncSpec(McpClientTransport transport) {
+ public AsyncSpec(McpClientTransport transport) {
Assert.notNull(transport, "Transport must not be null");
this.transport = transport;
}