Class McpToolProvider.Builder

java.lang.Object
dev.langchain4j.mcp.McpToolProvider.Builder
Enclosing class:
McpToolProvider

public static class McpToolProvider.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • mcpClients

      public McpToolProvider.Builder mcpClients(List<McpClient> mcpClients)
      The list of MCP clients to use for retrieving tools.
    • mcpClients

      public McpToolProvider.Builder mcpClients(McpClient... mcpClients)
      The list of MCP clients to use for retrieving tools.
    • filter

      public McpToolProvider.Builder filter(BiPredicate<McpClient, dev.langchain4j.agent.tool.ToolSpecification> mcpToolsFilter)
      The predicate to filter MCP provided tools. Filtering is applied *before* the name or specification mapping (see toolNameMapper(BiFunction) and toolSpecificationMapper(BiFunction)) so it should expect raw tool names as received from the MCP server.
    • filterToolNames

      public McpToolProvider.Builder filterToolNames(String... toolNames)
      Filter MCP provided tools with a specific name. Filtering is applied *before* the name or specification mapping (see toolNameMapper(BiFunction) and toolSpecificationMapper(BiFunction)) so it should expect raw tool names as received from the MCP server.
    • failIfOneServerFails

      public McpToolProvider.Builder failIfOneServerFails(boolean failIfOneServerFails)
      If this is true, then the tool provider will throw an exception if it fails to list tools from any of the servers. If this is false (default), then the tool provider will ignore the error and continue with the next server.
    • toolWrapper

      public McpToolProvider.Builder toolWrapper(Function<ToolExecutor, ToolExecutor> toolWrapper)
      Provide a wrapper around the ToolExecutor that can be used to implement tracing for example.
    • resourcesAsToolsPresenter

      public McpToolProvider.Builder resourcesAsToolsPresenter(McpResourcesAsToolsPresenter resourcesAsToolsPresenter)
      Provides a presenter for presenting resources via synthetic tools. If none is provided, then resources won't automatically be exposed via tools.
    • toolNameMapper

      public McpToolProvider.Builder toolNameMapper(BiFunction<McpClient, dev.langchain4j.agent.tool.ToolSpecification, String> toolNameMapper)
      Defines a mapping function to customize the tool names as they are registered in the tool provider. By default, the tool names are used as-is. It is forbidden to set both a toolNameMapper and a toolSpecificationMapper at the same time. Filtering (seefilter(BiPredicate) and filterToolNames(String...)) is applied before name mapping.
    • toolSpecificationMapper

      public McpToolProvider.Builder toolSpecificationMapper(BiFunction<McpClient, dev.langchain4j.agent.tool.ToolSpecification, dev.langchain4j.agent.tool.ToolSpecification> toolSpecificationMapper)
      Defines a mapping function to customize the tool specifications as they are registered in the tool provider. By default, the tool descriptions are used as-is. NOTE: When writing the mapping function, don't forget to include the tool arguments as well (these should generally not be changed, perhaps except when adjusting the descriptions of arguments). It is forbidden to set both a toolNameMapper and a toolSpecificationMapper at the same time. Filtering (seefilter(BiPredicate) and filterToolNames(String...)) is applied before specification mapping.
    • build

      public McpToolProvider build()