StreamableHttpMcpClient¶
This docs was updated at: 2026-02-23
com.paragon.mcp.StreamableHttpMcpClient ยท Class
Extends McpClient
MCP client that communicates over HTTP with optional SSE streaming.
This client implements the Streamable HTTP transport as defined in the MCP specification. It supports:
- JSON responses for simple request-response patterns
- SSE streams for streaming responses
- Session management via MCP-Session-Id header
- Custom headers for authentication
Example Usage¶
var mcp = StreamableHttpMcpClient.builder()
.serverUrl("https://mcp.example.com/api")
.headerProvider(McpHeaderProvider.bearer(() -> authService.getToken()))
.build();
mcp.connect();
var tools = mcp.asTools();
See Also
McpClientMcpHeaderProvider
Methods¶
builder¶
Creates a new builder for StreamableHttpMcpClient.
Returns
a new builder
connect¶
Performs initialization handshake.
handleSseResponse¶
private @NonNull JsonRpcResponse handleSseResponse(@NonNull Response httpResponse)
throws McpException
Parses SSE stream manually without external dependency.
SSE format: - Lines starting with "data:" contain the payload - Lines starting with "event:" contain the event type - Lines starting with "id:" contain the event ID - Empty lines separate events
getSessionId¶
Returns the current session ID.
Returns
the session ID, or null if not established
serverUrl¶
Sets the MCP server URL.
Parameters
| Name | Description |
|---|---|
serverUrl |
the server URL |
Returns
this builder
httpClient¶
Sets the OkHttpClient to use.
Parameters
| Name | Description |
|---|---|
httpClient |
the HTTP client |
Returns
this builder
headerProvider¶
Sets the header provider for custom headers.
Parameters
| Name | Description |
|---|---|
headerProvider |
the header provider |
Returns
this builder
connectTimeout¶
Sets the connection timeout.
Parameters
| Name | Description |
|---|---|
timeout |
the timeout duration |
Returns
this builder
readTimeout¶
Sets the read timeout.
Parameters
| Name | Description |
|---|---|
timeout |
the timeout duration |
Returns
this builder
objectMapper¶
Sets the ObjectMapper for JSON serialization.
Parameters
| Name | Description |
|---|---|
objectMapper |
the object mapper |
Returns
this builder
build¶
Builds the StreamableHttpMcpClient.
Returns
a new StreamableHttpMcpClient
Throws
| Type | Condition |
|---|---|
IllegalArgumentException |
if serverUrl is not set |