Class McpToolset
java.lang.Object
com.google.adk.tools.mcp.McpToolset
- All Implemented Interfaces:
AutoCloseable
Connects to a MCP Server, and retrieves MCP Tools into ADK Tools.
Attributes:
connectionParams
: The connection parameters to the MCP server. Can be eitherServerParameters
orSseServerParameters
.exit_stack
: (Python concept) The async exit stack to manage the connection to the MCP server. In Java, this is implicitly handled byMcpToolset
implementingAutoCloseable
.session
: The MCP session being initialized with the connection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Exception thrown when there's an error during MCP session initialization.static class
Exception thrown when there's an error during loading tools from the MCP server.static class
Holds the result of loading tools, containing both the tools and the toolset instance.static class
Base exception for all errors originating fromMcpToolset
. -
Constructor Summary
ConstructorsConstructorDescriptionMcpToolset
(SseServerParameters connectionParams) Initializes the McpToolset with SSE server parameters, using the ObjectMapper used across the ADK.McpToolset
(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Initializes the McpToolset with SSE server parameters.McpToolset
(io.modelcontextprotocol.client.transport.ServerParameters connectionParams) Initializes the McpToolset with local server parameters, using the ObjectMapper used across the ADK.McpToolset
(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Initializes the McpToolset with local server parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the connection to MCP Server.fromServer
(SseServerParameters connectionParams) Retrieve all tools from the MCP connection using SSE server parameters and the ObjectMapper used across the ADK.fromServer
(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Retrieve all tools from the MCP connection using SSE server parameters.fromServer
(io.modelcontextprotocol.client.transport.ServerParameters connectionParams) Retrieve all tools from the MCP connection using local server parameters and the ObjectMapper used across the ADK.fromServer
(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Retrieve all tools from the MCP connection using local server parameters.Loads all tools from the MCP Server.
-
Constructor Details
-
McpToolset
public McpToolset(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Initializes the McpToolset with SSE server parameters.- Parameters:
connectionParams
- The SSE connection parameters to the MCP server.objectMapper
- An ObjectMapper instance for parsing schemas.
-
McpToolset
public McpToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Initializes the McpToolset with local server parameters.- Parameters:
connectionParams
- The local server connection parameters to the MCP server.objectMapper
- An ObjectMapper instance for parsing schemas.
-
McpToolset
Initializes the McpToolset with SSE server parameters, using the ObjectMapper used across the ADK.- Parameters:
connectionParams
- The SSE connection parameters to the MCP server.
-
McpToolset
public McpToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams) Initializes the McpToolset with local server parameters, using the ObjectMapper used across the ADK.- Parameters:
connectionParams
- The local server connection parameters to the MCP server.
-
-
Method Details
-
fromServer
public static CompletableFuture<McpToolset.McpToolsAndToolsetResult> fromServer(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Retrieve all tools from the MCP connection using SSE server parameters.- Parameters:
connectionParams
- The SSE connection parameters to the MCP server.objectMapper
- An ObjectMapper instance for parsing schemas.- Returns:
- A
CompletableFuture
ofMcpToolsAndToolsetResult
.
-
fromServer
public static CompletableFuture<McpToolset.McpToolsAndToolsetResult> fromServer(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Retrieve all tools from the MCP connection using local server parameters.- Parameters:
connectionParams
- The local server connection parameters to the MCP server.objectMapper
- An ObjectMapper instance for parsing schemas.- Returns:
- A
CompletableFuture
ofMcpToolsAndToolsetResult
.
-
fromServer
public static CompletableFuture<McpToolset.McpToolsAndToolsetResult> fromServer(SseServerParameters connectionParams) Retrieve all tools from the MCP connection using SSE server parameters and the ObjectMapper used across the ADK.- Parameters:
connectionParams
- The SSE connection parameters to the MCP server.- Returns:
- A
CompletableFuture
ofMcpToolsAndToolsetResult
.
-
fromServer
public static CompletableFuture<McpToolset.McpToolsAndToolsetResult> fromServer(io.modelcontextprotocol.client.transport.ServerParameters connectionParams) Retrieve all tools from the MCP connection using local server parameters and the ObjectMapper used across the ADK.- Parameters:
connectionParams
- The local server connection parameters to the MCP server.- Returns:
- A
CompletableFuture
ofMcpToolsAndToolsetResult
.
-
loadTools
Loads all tools from the MCP Server. This method includes retry logic in case of transient session issues.- Returns:
- A
CompletableFuture
that completes with a list ofMcpTool
s imported from the MCP Server.
-
close
public void close()Closes the connection to MCP Server. This method is part of theAutoCloseable
interface, allowingMcpToolset
to be used in a try-with-resources statement for automatic resource management.- Specified by:
close
in interfaceAutoCloseable
-