Class McpServer.Builder
- Enclosing interface:
McpServer
McpServer instances.- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the MCP server.concurrentConnectionLimit(@Nullable Integer concurrentConnectionLimit) Sets the concurrent connection limit for the MCP server.connectionQueueCapacity(@Nullable Integer connectionQueueCapacity) Sets the outbound queue capacity for live MCP streams.corsAuthorizer(@Nullable McpCorsAuthorizer corsAuthorizer) Sets the MCP CORS authorizer.handlerResolver(@Nullable McpHandlerResolver handlerResolver) Sets the handler resolver.heartbeatInterval(@Nullable Duration heartbeatInterval) Sets the heartbeat interval for long-lived MCP event streams.Sets the host to bind, ornullto use the server default.maximumHeaderCount(@Nullable Integer maximumHeaderCount) Sets the maximum number of HTTP header fields accepted in one MCP request.maximumHeadersSizeInBytes(@Nullable Integer maximumHeadersSizeInBytes) Sets the maximum accepted MCP HTTP header-section size in bytes.maximumRequestSizeInBytes(@Nullable Integer maximumRequestSizeInBytes) Sets the maximum accepted MCP request size in bytes.maximumRequestTargetLengthInBytes(@Nullable Integer maximumRequestTargetLengthInBytes) Sets the maximum MCP HTTP request-target length accepted in bytes.Sets the port to bind.requestAdmissionPolicy(@Nullable McpRequestAdmissionPolicy requestAdmissionPolicy) Sets the request admission policy.requestBodyTimeout(@Nullable Duration requestBodyTimeout) Sets the maximum duration for reading the MCP HTTP request body after the request line and headers have been received.requestHandlerConcurrency(@Nullable Integer requestHandlerConcurrency) Sets the handler concurrency level for MCP JSON-RPC request handling.requestHandlerExecutorServiceSupplier(@Nullable Supplier<ExecutorService> requestHandlerExecutorServiceSupplier) Sets the supplier used to create the handler executor service.requestHandlerQueueCapacity(@Nullable Integer requestHandlerQueueCapacity) Sets the handler queue capacity for MCP JSON-RPC request handling.requestHandlerTimeout(@Nullable Duration requestHandlerTimeout) Sets the timeout for MCP handler execution, including framework-managedMcpEndpoint.initialize(McpInitializationContext, McpSessionContext)calls.requestHeaderTimeout(@Nullable Duration requestHeaderTimeout) Sets the maximum duration for reading the MCP HTTP request line and headers.requestInterceptor(@Nullable McpRequestInterceptor requestInterceptor) Sets the request interceptor.requestReadBufferSizeInBytes(@Nullable Integer requestReadBufferSizeInBytes) Sets the read buffer size used while reading MCP requests.responseMarshaler(@Nullable McpResponseMarshaler responseMarshaler) Sets the response marshaler used for tool structured content.sessionStore(@Nullable McpSessionStore sessionStore) Sets the session store.shutdownTimeout(@Nullable Duration shutdownTimeout) Sets the shutdown timeout.writeTimeout(@Nullable Duration writeTimeout) Sets the transport write timeout for established MCP event streams.
-
Method Details
-
port
Sets the port to bind.- Parameters:
port- the port- Returns:
- this builder
-
host
Sets the host to bind, ornullto use the server default.- Parameters:
host- the host to bind- Returns:
- this builder
-
handlerResolver
Sets the handler resolver.- Parameters:
handlerResolver- the handler resolver- Returns:
- this builder
-
requestAdmissionPolicy
public @NonNull McpServer.Builder requestAdmissionPolicy(@Nullable McpRequestAdmissionPolicy requestAdmissionPolicy) Sets the request admission policy.- Parameters:
requestAdmissionPolicy- the admission policy- Returns:
- this builder
-
requestInterceptor
public @NonNull McpServer.Builder requestInterceptor(@Nullable McpRequestInterceptor requestInterceptor) Sets the request interceptor.- Parameters:
requestInterceptor- the request interceptor- Returns:
- this builder
-
responseMarshaler
public @NonNull McpServer.Builder responseMarshaler(@Nullable McpResponseMarshaler responseMarshaler) Sets the response marshaler used for tool structured content.- Parameters:
responseMarshaler- the response marshaler- Returns:
- this builder
-
corsAuthorizer
Sets the MCP CORS authorizer.- Parameters:
corsAuthorizer- the CORS authorizer- Returns:
- this builder
-
sessionStore
Sets the session store.- Parameters:
sessionStore- the session store- Returns:
- this builder
-
requestHeaderTimeout
Sets the maximum duration for reading the MCP HTTP request line and headers.If this value is not specified, Soklet uses the server default.
- Parameters:
requestHeaderTimeout- the request header timeout, ornullfor the default- Returns:
- this builder
-
requestBodyTimeout
Sets the maximum duration for reading the MCP HTTP request body after the request line and headers have been received.If this value is not specified, Soklet uses the server default.
- Parameters:
requestBodyTimeout- the request body timeout, ornullfor the default- Returns:
- this builder
-
requestHandlerTimeout
Sets the timeout for MCP handler execution, including framework-managedMcpEndpoint.initialize(McpInitializationContext, McpSessionContext)calls.- Parameters:
requestHandlerTimeout- the handler timeout- Returns:
- this builder
-
requestHandlerConcurrency
public @NonNull McpServer.Builder requestHandlerConcurrency(@Nullable Integer requestHandlerConcurrency) Sets the handler concurrency level for MCP JSON-RPC request handling.On runtimes with virtual threads, established MCP live
GETstreams are processed on a virtual-thread-per-stream executor and are not limited by this value. On runtimes without virtual threads, the live-stream processor uses the bounded fallback executor and this value also bounds active live-stream processing.- Parameters:
requestHandlerConcurrency- the handler concurrency- Returns:
- this builder
-
requestHandlerQueueCapacity
public @NonNull McpServer.Builder requestHandlerQueueCapacity(@Nullable Integer requestHandlerQueueCapacity) Sets the handler queue capacity for MCP JSON-RPC request handling.- Parameters:
requestHandlerQueueCapacity- the handler queue capacity- Returns:
- this builder
-
requestHandlerExecutorServiceSupplier
public @NonNull McpServer.Builder requestHandlerExecutorServiceSupplier(@Nullable Supplier<ExecutorService> requestHandlerExecutorServiceSupplier) Sets the supplier used to create the handler executor service.- Parameters:
requestHandlerExecutorServiceSupplier- the executor service supplier- Returns:
- this builder
-
maximumRequestSizeInBytes
public @NonNull McpServer.Builder maximumRequestSizeInBytes(@Nullable Integer maximumRequestSizeInBytes) Sets the maximum accepted MCP request size in bytes.The MCP transport rejects requests whose declared body size is larger than this limit. Header-section size is governed by
maximumHeadersSizeInBytes(Integer).- Parameters:
maximumRequestSizeInBytes- the maximum request size, ornullfor the default- Returns:
- this builder
-
maximumHeaderCount
Sets the maximum number of HTTP header fields accepted in one MCP request.- Parameters:
maximumHeaderCount- the maximum header count, ornullfor the default- Returns:
- this builder
-
maximumHeadersSizeInBytes
public @NonNull McpServer.Builder maximumHeadersSizeInBytes(@Nullable Integer maximumHeadersSizeInBytes) Sets the maximum accepted MCP HTTP header-section size in bytes.This limit applies to the header bytes after the request line, including header-field line endings and the terminating blank line.
- Parameters:
maximumHeadersSizeInBytes- the maximum headers size, ornullfor the default- Returns:
- this builder
-
maximumRequestTargetLengthInBytes
public @NonNull McpServer.Builder maximumRequestTargetLengthInBytes(@Nullable Integer maximumRequestTargetLengthInBytes) Sets the maximum MCP HTTP request-target length accepted in bytes.- Parameters:
maximumRequestTargetLengthInBytes- the maximum request-target length, ornullfor the default- Returns:
- this builder
-
requestReadBufferSizeInBytes
public @NonNull McpServer.Builder requestReadBufferSizeInBytes(@Nullable Integer requestReadBufferSizeInBytes) Sets the read buffer size used while reading MCP requests.- Parameters:
requestReadBufferSizeInBytes- the read buffer size- Returns:
- this builder
-
concurrentConnectionLimit
public @NonNull McpServer.Builder concurrentConnectionLimit(@Nullable Integer concurrentConnectionLimit) Sets the concurrent connection limit for the MCP server.A value of
0disables Soklet's MCP live-stream connection cap entirely. Use0only when an external proxy, load balancer, operating-system limit, or custom admission policy provides the intended production cap.- Parameters:
concurrentConnectionLimit- the concurrent connection limit- Returns:
- this builder
-
connectionQueueCapacity
public @NonNull McpServer.Builder connectionQueueCapacity(@Nullable Integer connectionQueueCapacity) Sets the outbound queue capacity for live MCP streams.This controls each established stream's outbound message queue. On runtimes without virtual threads, the same value is also used by the bounded fallback executor for queued live-stream processing tasks.
- Parameters:
connectionQueueCapacity- the outbound queue capacity- Returns:
- this builder
-
shutdownTimeout
Sets the shutdown timeout.- Parameters:
shutdownTimeout- the shutdown timeout- Returns:
- this builder
-
writeTimeout
Sets the transport write timeout for established MCP event streams.If this value is not specified, Soklet uses the server default. Use
Duration.ZEROto disable MCP event-stream write timeouts.- Parameters:
writeTimeout- the write timeout, ornullfor the default- Returns:
- this builder
-
heartbeatInterval
Sets the heartbeat interval for long-lived MCP event streams.- Parameters:
heartbeatInterval- the heartbeat interval- Returns:
- this builder
-
build
-