Package dev.langchain4j.mcp.client
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 TypeMethodDescriptionvoid
Performs a health check that returns normally if the MCP server is reachable and properly responding to ping requests.void
close()
executeTool
(ToolExecutionRequest executionRequest) Executes a tool on the MCP server and returns the result as a String.Render the contents of a prompt.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.
-
Constructor Details
-
DefaultMcpClient
-
-
Method Details
-
listTools
Description copied from interface:McpClient
Obtains a list of tools from the MCP server. -
executeTool
Description copied from interface:McpClient
Executes a tool on the MCP server and returns the result as a String. Currently, this expects a tool execution to only contain text-based results.- Specified by:
executeTool
in interfaceMcpClient
-
listResources
Description copied from interface:McpClient
Obtains the current list of resources available on the MCP server.- Specified by:
listResources
in interfaceMcpClient
-
readResource
Description copied from interface:McpClient
Retrieves the contents of the resource with the specified URI. This also works for dynamic resources (templates).- Specified by:
readResource
in interfaceMcpClient
-
listPrompts
Description copied from interface:McpClient
Obtain a list of prompts available on the MCP server.- Specified by:
listPrompts
in interfaceMcpClient
-
getPrompt
Description copied from interface:McpClient
Render the contents of a prompt. -
checkHealth
public void checkHealth()Description copied from interface:McpClient
Performs 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:
checkHealth
in interfaceMcpClient
-
listResourceTemplates
Description copied from interface:McpClient
Obtains the current list of resource templates (dynamic resources) available on the MCP server.- Specified by:
listResourceTemplates
in interfaceMcpClient
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-