Class McpToolProvider
java.lang.Object
dev.langchain4j.mcp.McpToolProvider
- All Implemented Interfaces:
ToolProvider
A tool provider backed by one or more MCP clients.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMcpToolProvider(List<McpClient> mcpClients, boolean failIfOneServerFails, BiPredicate<McpClient, ToolSpecification> mcpToolsFilter, Function<ToolExecutor, ToolExecutor> toolWrapper, McpResourcesAsToolsPresenter resourcesAsToolsPresenter, BiFunction<McpClient, ToolSpecification, String> toolNameMapper, BiFunction<McpClient, ToolSpecification, ToolSpecification> toolSpecificationMapper) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFilter(BiPredicate<McpClient, ToolSpecification> filter) Adds a tools filter that will act in conjunction (AND) with the eventually existing ones.voidaddMcpClient(McpClient client) Adds a new MCP client to the list of clients.static McpToolProvider.Builderbuilder()provideTools(ToolProviderRequest request) Provides tools for the request to the LLM.protected ToolProviderResultprovideTools(ToolProviderRequest request, BiPredicate<McpClient, ToolSpecification> mcpToolsFilter) voidremoveMcpClient(McpClient client) Removes an MCP client from the list of clients.voidResets the all the eventually existing tools filters.voidsetFilter(BiPredicate<McpClient, ToolSpecification> filter) Sets the tools filter overriding the eventually existing ones.voidsetToolNameMapper(BiFunction<McpClient, ToolSpecification, String> toolNameMapper) Sets the tool name mapper overriding the current one.voidsetToolSpecificationMapper(BiFunction<McpClient, ToolSpecification, ToolSpecification> toolSpecificationMapper) Sets the tool specification mapper overriding the current one.
-
Constructor Details
-
McpToolProvider
protected McpToolProvider(List<McpClient> mcpClients, boolean failIfOneServerFails, BiPredicate<McpClient, ToolSpecification> mcpToolsFilter, Function<ToolExecutor, ToolExecutor> toolWrapper, McpResourcesAsToolsPresenter resourcesAsToolsPresenter, BiFunction<McpClient, ToolSpecification, String> toolNameMapper, BiFunction<McpClient, ToolSpecification, ToolSpecification> toolSpecificationMapper)
-
-
Method Details
-
addMcpClient
Adds a new MCP client to the list of clients.- Parameters:
client- the MCP client to add
-
removeMcpClient
Removes an MCP client from the list of clients.- Parameters:
client- the MCP client to remove
-
addFilter
Adds a tools filter that will act in conjunction (AND) with the eventually existing ones.- Parameters:
filter- the filter to add
-
setFilter
Sets the tools filter overriding the eventually existing ones.- Parameters:
filter- the filter to add
-
setToolNameMapper
Sets the tool name mapper overriding the current one. The mapper can be null, in which case the tool names will be used as-is. -
setToolSpecificationMapper
public void setToolSpecificationMapper(BiFunction<McpClient, ToolSpecification, ToolSpecification> toolSpecificationMapper) Sets the tool specification mapper overriding the current one. The mapper can be null, in which case the tool specifications will be used as-is. -
resetFilters
public void resetFilters()Resets the all the eventually existing tools filters. -
provideTools
Description copied from interface:ToolProviderProvides tools for the request to the LLM.- Specified by:
provideToolsin interfaceToolProvider- Parameters:
request- theToolProviderRequest, containsUserMessage,ChatMemoryID (seeMemoryId) andInvocationParameters.- Returns:
ToolProviderResultcontains tools that should be included in the request to the LLM.
-
provideTools
protected ToolProviderResult provideTools(ToolProviderRequest request, BiPredicate<McpClient, ToolSpecification> mcpToolsFilter) -
builder
-