Class McpToolProvider

java.lang.Object
dev.langchain4j.mcp.McpToolProvider
All Implemented Interfaces:
ToolProvider

public class McpToolProvider extends Object implements ToolProvider
A tool provider backed by one or more MCP clients.
  • Constructor Details

    • McpToolProvider

      protected McpToolProvider(List<McpClient> mcpClients, boolean failIfOneServerFails, BiPredicate<McpClient,dev.langchain4j.agent.tool.ToolSpecification> mcpToolsFilter)
  • Method Details

    • addMcpClient

      public void addMcpClient(McpClient client)
      Adds a new MCP client to the list of clients.
      Parameters:
      client - the MCP client to add
    • removeMcpClient

      public void removeMcpClient(McpClient client)
      Removes an MCP client from the list of clients.
      Parameters:
      client - the MCP client to remove
    • addFilter

      public void addFilter(BiPredicate<McpClient,dev.langchain4j.agent.tool.ToolSpecification> filter)
      Adds a tools filter that will act in conjunction (AND) with the eventually existing ones.
      Parameters:
      filter - the filter to add
    • setFilter

      public void setFilter(BiPredicate<McpClient,dev.langchain4j.agent.tool.ToolSpecification> filter)
      Sets the tools filter overriding the eventually existing ones.
      Parameters:
      filter - the filter to add
    • resetFilters

      public void resetFilters()
      Resets the all the eventually existing tools filters.
    • provideTools

      public ToolProviderResult provideTools(ToolProviderRequest request)
      Specified by:
      provideTools in interface ToolProvider
    • provideTools

      protected ToolProviderResult provideTools(ToolProviderRequest request, BiPredicate<McpClient,dev.langchain4j.agent.tool.ToolSpecification> mcpToolsFilter)
    • builder

      public static McpToolProvider.Builder builder()