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<dev.langchain4j.agent.tool.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(dev.langchain4j.agent.tool.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<ResourceRef> 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 ResourceResponse 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
    • listResourceTemplates

      public List<ResourceTemplateRef> 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