Class AbstractMcpClient

java.lang.Object
com.shaft.commandline.mcp.AbstractMcpClient
All Implemented Interfaces:
McpClient, AutoCloseable
Direct Known Subclasses:
HttpMcpClient, StdioMcpClient

public abstract class AbstractMcpClient extends Object implements McpClient
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    callTool(String name, tools.jackson.databind.node.ObjectNode arguments)
    Invokes tools/call for the given tool name and arguments.
    tools.jackson.databind.JsonNode
    callToolRaw(String name, tools.jackson.databind.node.ObjectNode arguments)
    Invokes a tool and returns the raw result node, for --json output.
    Performs the initialize handshake if it has not already run.
    Lists the tools advertised by the server via tools/list.
    listTools(boolean forceRefresh)
    Lists the tools advertised by the server via tools/list, serving the last successful response from this connection's cache unless a refresh is requested.
    tools.jackson.databind.JsonNode
     
    tools.jackson.databind.JsonNode
    listToolsRaw(boolean forceRefresh)
    Returns the raw result node of a tools/list call, for --json output, serving the last successful response from this connection's cache unless a refresh is requested.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface McpClient

    close
  • Constructor Details

    • AbstractMcpClient

      public AbstractMcpClient()
  • Method Details

    • initialize

      public InitializeResult initialize()
      Description copied from interface: McpClient
      Performs the initialize handshake if it has not already run.
      Specified by:
      initialize in interface McpClient
      Returns:
      the negotiated server identity
    • listTools

      public List<Tool> listTools()
      Description copied from interface: McpClient
      Lists the tools advertised by the server via tools/list.
      Specified by:
      listTools in interface McpClient
      Returns:
      the advertised tools
    • listTools

      public List<Tool> listTools(boolean forceRefresh)
      Lists the tools advertised by the server via tools/list, serving the last successful response from this connection's cache unless a refresh is requested.
      Parameters:
      forceRefresh - when true, bypasses the cache and issues a fresh tools/list
      Returns:
      the advertised tools
    • callTool

      public CallToolResult callTool(String name, tools.jackson.databind.node.ObjectNode arguments)
      Description copied from interface: McpClient
      Invokes tools/call for the given tool name and arguments.
      Specified by:
      callTool in interface McpClient
      Parameters:
      name - the tool name
      arguments - the arguments object (may be empty, never null)
      Returns:
      the tool result
    • listToolsRaw

      public tools.jackson.databind.JsonNode listToolsRaw()
      Specified by:
      listToolsRaw in interface McpClient
      Returns:
      the raw result node of a tools/list call, for --json output; served from this connection's cache unless it has not been fetched yet
    • listToolsRaw

      public tools.jackson.databind.JsonNode listToolsRaw(boolean forceRefresh)
      Returns the raw result node of a tools/list call, for --json output, serving the last successful response from this connection's cache unless a refresh is requested.
      Parameters:
      forceRefresh - when true, bypasses the cache and issues a fresh tools/list
      Returns:
      the raw result node
    • callToolRaw

      public tools.jackson.databind.JsonNode callToolRaw(String name, tools.jackson.databind.node.ObjectNode arguments)
      Invokes a tool and returns the raw result node, for --json output.
      Specified by:
      callToolRaw in interface McpClient
      Parameters:
      name - the tool name
      arguments - the arguments object
      Returns:
      the raw JSON-RPC result node