Package dev.langchain4j.mcp
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
ConstructorsModifierConstructorDescriptionprotected
McpToolProvider
(List<McpClient> mcpClients, boolean failIfOneServerFails, BiPredicate<McpClient, ToolSpecification> mcpToolsFilter) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFilter
(BiPredicate<McpClient, ToolSpecification> filter) Adds a tools filter that will act in conjunction (AND) with the eventually existing ones.void
addMcpClient
(McpClient client) Adds a new MCP client to the list of clients.static McpToolProvider.Builder
builder()
provideTools
(ToolProviderRequest request) Provides tools for the request to the LLM.protected ToolProviderResult
provideTools
(ToolProviderRequest request, BiPredicate<McpClient, ToolSpecification> mcpToolsFilter) void
removeMcpClient
(McpClient client) Removes an MCP client from the list of clients.void
Resets the all the eventually existing tools filters.void
setFilter
(BiPredicate<McpClient, ToolSpecification> filter) Sets the tools filter overriding the eventually existing ones.
-
Constructor Details
-
McpToolProvider
protected McpToolProvider(List<McpClient> mcpClients, boolean failIfOneServerFails, BiPredicate<McpClient, ToolSpecification> mcpToolsFilter)
-
-
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
-
resetFilters
public void resetFilters()Resets the all the eventually existing tools filters. -
provideTools
Description copied from interface:ToolProvider
Provides tools for the request to the LLM.- Specified by:
provideTools
in interfaceToolProvider
- Parameters:
request
-ToolProviderRequest
containsUserMessage
and chat memory id (seeMemoryId
).- Returns:
ToolProviderResult
contains tools that should be included in the request to the LLM.
-
provideTools
protected ToolProviderResult provideTools(ToolProviderRequest request, BiPredicate<McpClient, ToolSpecification> mcpToolsFilter) -
builder
-