McpClient¶
This docs was updated at: 2026-02-23
com.paragon.mcp.McpClient ยท Class
Implements AutoCloseable
Abstract base class for MCP client implementations.
This class handles the MCP protocol lifecycle and provides common functionality for both Stdio and HTTP transports.
Lifecycle¶
.connect()- Establishes connection and performs initialization handshake.listTools()/Map)- Perform operations.close()- Closes connection and cleans up resources
See Also
StdioMcpClientStreamableHttpMcpClient
Methods¶
McpClient¶
Creates a new MCP client.
Parameters
| Name | Description |
|---|---|
objectMapper |
the object mapper for JSON serialization |
doConnect¶
Establishes the underlying transport connection.
Throws
| Type | Condition |
|---|---|
McpException |
if connection fails |
sendRequest¶
Sends a JSON-RPC request over the transport.
Parameters
| Name | Description |
|---|---|
request |
the request to send |
Throws
| Type | Condition |
|---|---|
McpException |
if sending fails |
readResponse¶
Reads a JSON-RPC response from the transport.
Returns
the response
Throws
| Type | Condition |
|---|---|
McpException |
if reading fails |
doClose¶
Closes the underlying transport connection.
Throws
| Type | Condition |
|---|---|
McpException |
if closing fails |
connect¶
Connects to the MCP server and performs initialization.
This method establishes the transport connection, sends the initialize request, and sends the initialized notification.
Throws
| Type | Condition |
|---|---|
McpException |
if connection or initialization fails |
listTools¶
Lists all tools available on the MCP server.
Returns
the list of tool definitions
Throws
| Type | Condition |
|---|---|
McpException |
if listing fails or client not initialized |
callTool¶
public @NonNull McpToolResult callTool(
@NonNull String name, @Nullable Map<String, Object> arguments) throws McpException
Calls a tool on the MCP server.
Parameters
| Name | Description |
|---|---|
name |
the tool name |
arguments |
the tool arguments |
Returns
the tool result
Throws
| Type | Condition |
|---|---|
McpException |
if the call fails or client not initialized |
asTools¶
Returns all MCP tools as McpRemoteTool instances that can be used with agents.
Returns
list of MCP remote tools
Throws
| Type | Condition |
|---|---|
McpException |
if listing fails |
asTools¶
public @NonNull List<McpRemoteTool> asTools(@Nullable Set<String> allowedToolNames)
throws McpException
Returns filtered MCP tools as McpRemoteTool instances.
Parameters
| Name | Description |
|---|---|
allowedToolNames |
optional set of tool names to include (null for all) |
Returns
list of MCP remote tools
Throws
| Type | Condition |
|---|---|
McpException |
if listing fails |
toJson¶
Serializes an object to JSON string.
Parameters
| Name | Description |
|---|---|
obj |
the object to serialize |
Returns
the JSON string
Throws
| Type | Condition |
|---|---|
McpException |
if serialization fails |
parseResponse¶
Deserializes a JSON string to JsonRpcResponse.
Parameters
| Name | Description |
|---|---|
json |
the JSON string |
Returns
the parsed response
Throws
| Type | Condition |
|---|---|
McpException |
if parsing fails |