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 TypeMethodDescriptionvoidPerforms a health check that returns normally if the MCP server is reachable and properly responding to ping requests.executeTool(ToolExecutionRequest executionRequest) Executes a tool on the MCP server and returns the result.executeTool(ToolExecutionRequest executionRequest, InvocationContext invocationContext) 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.listResources(InvocationContext invocationContext) 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.listResourceTemplates(InvocationContext invocationContext) Obtains the current list of resource templates (dynamic resources) available on the MCP server.Obtains a list of tools from the MCP server.listTools(InvocationContext invocationContext) Obtains a list of tools from the MCP server.readResource(String uri) Retrieves the contents of the resource with the specified URI.readResource(String uri, InvocationContext invocationContext) Retrieves the contents of the resource with the specified URI.voidSets the roots that are made available to the server upon its request.Methods inherited from interface AutoCloseable
close
-
Method Details
-
key
String key()Returns the unique key of this client. -
listTools
List<ToolSpecification> listTools()Obtains a list of tools from the MCP server. -
listTools
Obtains a list of tools from the MCP server. -
executeTool
Executes 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. -
executeTool
ToolExecutionResult executeTool(ToolExecutionRequest executionRequest, InvocationContext invocationContext) Executes 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. -
listResources
List<McpResource> listResources()Obtains the current list of resources available on the MCP server. -
listResources
Obtains the current list of resources available on the MCP server. -
listResourceTemplates
List<McpResourceTemplate> listResourceTemplates()Obtains the current list of resource templates (dynamic resources) available on the MCP server. -
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). -
readResource
Retrieves the contents of the resource with the specified URI. This also works for dynamic resources (templates). -
listPrompts
-
getPrompt
Render the contents of a prompt. -
checkHealth
void checkHealth()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. -
setRoots
-