Package dev.langchain4j.mcp.client
Interface McpClient
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DefaultMcpClient
Represents a client that can communicate with an MCP server over a given transport protocol,
retrieve and execute tools using the server.
-
Method Summary
Modifier and TypeMethodDescriptionexecuteTool
(ToolExecutionRequest executionRequest) Executes a tool on the MCP server and returns the result as a String.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.Methods inherited from interface java.lang.AutoCloseable
close
-
Method Details
-
listTools
List<ToolSpecification> listTools()Obtains a list of tools from the MCP server. -
executeTool
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. -
listResources
List<ResourceRef> listResources()Obtains the current list of resources available on the MCP server. -
listResourceTemplates
List<ResourceTemplateRef> listResourceTemplates()Obtains the current list of resource templates (dynamic resources) available on the MCP server. -
readResource
Retrieves the contents of the resource with the specified URI. This also works for dynamic resources (templates).
-