Class McpToolProvider.Builder
java.lang.Object
dev.langchain4j.mcp.McpToolProvider.Builder
- Enclosing class:
McpToolProvider
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()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.filter(BiPredicate<McpClient, ToolSpecification> mcpToolsFilter) The predicate to filter MCP provided tools.filterToolNames(String... toolNames) Filter MCP provided tools with a specific name.mcpClients(McpClient... mcpClients) The list of MCP clients to use for retrieving tools.mcpClients(List<McpClient> mcpClients) The list of MCP clients to use for retrieving tools.resourcesAsToolsPresenter(McpResourcesAsToolsPresenter resourcesAsToolsPresenter) Provides a presenter for presenting resources via synthetic tools.toolNameMapper(BiFunction<McpClient, ToolSpecification, String> toolNameMapper) Defines a mapping function to customize the tool names as they are registered in the tool provider.toolSpecificationMapper(BiFunction<McpClient, ToolSpecification, ToolSpecification> toolSpecificationMapper) Defines a mapping function to customize the tool specifications as they are registered in the tool provider.toolWrapper(Function<ToolExecutor, ToolExecutor> toolWrapper) Provide a wrapper around theToolExecutorthat can be used to implement tracing for example.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
mcpClients
The list of MCP clients to use for retrieving tools. -
mcpClients
The list of MCP clients to use for retrieving tools. -
filter
The predicate to filter MCP provided tools. Filtering is applied *before* the name or specification mapping (seetoolNameMapper(BiFunction)andtoolSpecificationMapper(BiFunction)) so it should expect raw tool names as received from the MCP server. -
filterToolNames
Filter MCP provided tools with a specific name. Filtering is applied *before* the name or specification mapping (seetoolNameMapper(BiFunction)andtoolSpecificationMapper(BiFunction)) so it should expect raw tool names as received from the MCP server. -
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
Provide a wrapper around theToolExecutorthat 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, 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)andfilterToolNames(String...)) is applied before name mapping. -
toolSpecificationMapper
public McpToolProvider.Builder toolSpecificationMapper(BiFunction<McpClient, ToolSpecification, 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)andfilterToolNames(String...)) is applied before specification mapping. -
build
-