Class AbstractMcpClient
java.lang.Object
com.shaft.commandline.mcp.AbstractMcpClient
- All Implemented Interfaces:
McpClient, AutoCloseable
- Direct Known Subclasses:
HttpMcpClient, StdioMcpClient
Base MCP client that owns the JSON-RPC framing and the
initialize /
notifications/initialized handshake. Subclasses only implement the raw transport:
rpc(ObjectNode) for request/response and sendNotification(ObjectNode) for
fire-and-forget notifications.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionInvokestools/callfor the given tool name and arguments.tools.jackson.databind.JsonNodecallToolRaw(String name, tools.jackson.databind.node.ObjectNode arguments) Invokes a tool and returns the rawresultnode, for--jsonoutput.Performs theinitializehandshake if it has not already run.Lists the tools advertised by the server viatools/list.listTools(boolean forceRefresh) Lists the tools advertised by the server viatools/list, serving the last successful response from this connection's cache unless a refresh is requested.tools.jackson.databind.JsonNodetools.jackson.databind.JsonNodelistToolsRaw(boolean forceRefresh) Returns the rawresultnode of atools/listcall, for--jsonoutput, serving the last successful response from this connection's cache unless a refresh is requested.
-
Constructor Details
-
AbstractMcpClient
public AbstractMcpClient()
-
-
Method Details
-
initialize
Description copied from interface:McpClientPerforms theinitializehandshake if it has not already run.- Specified by:
initializein interfaceMcpClient- Returns:
- the negotiated server identity
-
listTools
-
listTools
Lists the tools advertised by the server viatools/list, serving the last successful response from this connection's cache unless a refresh is requested.- Parameters:
forceRefresh- whentrue, bypasses the cache and issues a freshtools/list- Returns:
- the advertised tools
-
callTool
Description copied from interface:McpClientInvokestools/callfor the given tool name and arguments. -
listToolsRaw
public tools.jackson.databind.JsonNode listToolsRaw()- Specified by:
listToolsRawin interfaceMcpClient- Returns:
- the raw
resultnode of atools/listcall, for--jsonoutput; served from this connection's cache unless it has not been fetched yet
-
listToolsRaw
public tools.jackson.databind.JsonNode listToolsRaw(boolean forceRefresh) Returns the rawresultnode of atools/listcall, for--jsonoutput, serving the last successful response from this connection's cache unless a refresh is requested.- Parameters:
forceRefresh- whentrue, bypasses the cache and issues a freshtools/list- Returns:
- the raw
resultnode
-
callToolRaw
public tools.jackson.databind.JsonNode callToolRaw(String name, tools.jackson.databind.node.ObjectNode arguments) Invokes a tool and returns the rawresultnode, for--jsonoutput.- Specified by:
callToolRawin interfaceMcpClient- Parameters:
name- the tool namearguments- the arguments object- Returns:
- the raw JSON-RPC
resultnode
-