Class DefaultMcpClient
java.lang.Object
dev.langchain4j.mcp.client.DefaultMcpClient
- All Implemented Interfaces:
McpClient, AutoCloseable
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPerforms a health check that returns normally if the MCP server is reachable and properly responding to ping requests.voidclose()voidEvicts the tool list cache, forcing the next call tolistTools()to retrieve a fresh list of tools from the MCP server.executeTool(ToolExecutionRequest executionRequest) Executes a tool on the MCP server and returns the result.Render the contents of a prompt.key()Returns the unique key of this client.Obtain a list of prompts available on the MCP server.Obtains the current list of resources available on the MCP server.Obtains the current list of resource templates (dynamic resources) available on the MCP server.Obtains a list of tools from the MCP server.readResource(String uri) Retrieves the contents of the resource with the specified URI.voidSets the roots that are made available to the server upon its request.
-
Constructor Details
-
DefaultMcpClient
-
-
Method Details
-
key
-
listTools
Description copied from interface:McpClientObtains a list of tools from the MCP server. -
evictToolListCache
public void evictToolListCache()Evicts the tool list cache, forcing the next call tolistTools()to retrieve a fresh list of tools from the MCP server. -
executeTool
Description copied from interface:McpClientExecutes a tool on the MCP server and returns the result. Currently, this expects a tool execution to only contain text-based results or JSON structured content.- Specified by:
executeToolin interfaceMcpClient
-
listResources
Description copied from interface:McpClientObtains the current list of resources available on the MCP server.- Specified by:
listResourcesin interfaceMcpClient
-
readResource
Description copied from interface:McpClientRetrieves the contents of the resource with the specified URI. This also works for dynamic resources (templates).- Specified by:
readResourcein interfaceMcpClient
-
listPrompts
Description copied from interface:McpClientObtain a list of prompts available on the MCP server.- Specified by:
listPromptsin interfaceMcpClient
-
getPrompt
-
checkHealth
public void checkHealth()Description copied from interface:McpClientPerforms a health check that returns normally if the MCP server is reachable and properly responding to ping requests. If this method throws an exception, the health of this MCP client is considered degraded.- Specified by:
checkHealthin interfaceMcpClient
-
setRoots
Description copied from interface:McpClientSets the roots that are made available to the server upon its request. After calling this method, the client also sends a `notifications/roots/list_changed` message to the server. -
listResourceTemplates
Description copied from interface:McpClientObtains the current list of resource templates (dynamic resources) available on the MCP server.- Specified by:
listResourceTemplatesin interfaceMcpClient
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-