Class DefaultMcpClient

java.lang.Object
dev.langchain4j.mcp.client.DefaultMcpClient
All Implemented Interfaces:
McpClient, AutoCloseable

public class DefaultMcpClient extends Object implements McpClient
  • Constructor Details

  • Method Details

    • listTools

      public List<ToolSpecification> listTools()
      Description copied from interface: McpClient
      Obtains a list of tools from the MCP server.
      Specified by:
      listTools in interface McpClient
    • executeTool

      public String executeTool(ToolExecutionRequest executionRequest)
      Description copied from interface: McpClient
      Executes a tool on the MCP server and returns the result as a String. Currently, this expects a tool execution to only contain text-based results.
      Specified by:
      executeTool in interface McpClient
    • listResources

      public List<McpResource> listResources()
      Description copied from interface: McpClient
      Obtains the current list of resources available on the MCP server.
      Specified by:
      listResources in interface McpClient
    • readResource

      public McpReadResourceResult readResource(String uri)
      Description copied from interface: McpClient
      Retrieves the contents of the resource with the specified URI. This also works for dynamic resources (templates).
      Specified by:
      readResource in interface McpClient
    • listPrompts

      public List<McpPrompt> listPrompts()
      Description copied from interface: McpClient
      Obtain a list of prompts available on the MCP server.
      Specified by:
      listPrompts in interface McpClient
    • getPrompt

      public McpGetPromptResult getPrompt(String name, Map<String,Object> arguments)
      Description copied from interface: McpClient
      Render the contents of a prompt.
      Specified by:
      getPrompt in interface McpClient
    • checkHealth

      public void checkHealth()
      Description copied from interface: McpClient
      Performs a health check that returns normally if the MCP server is reachable and properly responding to ping requests. If this method throws an exception, the health of this MCP client is considered degraded.
      Specified by:
      checkHealth in interface McpClient
    • listResourceTemplates

      public List<McpResourceTemplate> listResourceTemplates()
      Description copied from interface: McpClient
      Obtains the current list of resource templates (dynamic resources) available on the MCP server.
      Specified by:
      listResourceTemplates in interface McpClient
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable