Class McpAsyncToolset
java.lang.Object
com.google.adk.tools.mcp.McpAsyncToolset
- All Implemented Interfaces:
BaseToolset, AutoCloseable
Connects to a MCP Server, and retrieves MCP Tools into ADK Tools.
Attributes:
connectionParams: The connection parameters to the MCP server. Can be eitherServerParametersorSseServerParameters.session: The MCP session being initialized with the connection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for McpAsyncToolset -
Constructor Summary
ConstructorsConstructorDescriptionMcpAsyncToolset(McpSessionManager mcpSessionManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Optional<Object> toolFilter) Initializes the McpAsyncToolset with a provided McpSessionManager.McpAsyncToolset(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Optional<Object> toolFilter) Initializes the McpAsyncToolset with SSE server parameters.McpAsyncToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Optional<Object> toolFilter) Initializes the McpAsyncToolset with local server parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Performs cleanup and releases resources held by the toolset.io.reactivex.rxjava3.core.Flowable<BaseTool> getTools(ReadonlyContext readonlyContext) Return all tools in the toolset based on the provided context.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BaseToolset
isToolSelected, isToolSelected
-
Constructor Details
-
McpAsyncToolset
public McpAsyncToolset(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Optional<Object> toolFilter) Initializes the McpAsyncToolset with SSE server parameters.- Parameters:
connectionParams- The SSE connection parameters to the MCP server.objectMapper- An ObjectMapper instance for parsing schemas.toolFilter- An Optional containing either a ToolPredicate or a List of tool names.
-
McpAsyncToolset
public McpAsyncToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Optional<Object> toolFilter) Initializes the McpAsyncToolset with local server parameters.- Parameters:
connectionParams- The local server connection parameters to the MCP server.objectMapper- An ObjectMapper instance for parsing schemas.toolFilter- An Optional containing either a ToolPredicate or a List of tool names.
-
McpAsyncToolset
public McpAsyncToolset(McpSessionManager mcpSessionManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Optional<Object> toolFilter) Initializes the McpAsyncToolset with a provided McpSessionManager.- Parameters:
mcpSessionManager- The session manager for MCP connections.objectMapper- An ObjectMapper instance for parsing schemas.toolFilter- An Optional containing either a ToolPredicate or a List of tool names.
-
-
Method Details
-
getTools
Description copied from interface:BaseToolsetReturn all tools in the toolset based on the provided context.- Specified by:
getToolsin interfaceBaseToolset- Parameters:
readonlyContext- Context used to filter tools available to the agent.- Returns:
- A Single emitting a list of tools available under the specified context.
-
close
public void close()Description copied from interface:BaseToolsetPerforms cleanup and releases resources held by the toolset.NOTE: This method is invoked, for example, at the end of an agent server's lifecycle or when the toolset is no longer needed. Implementations should ensure that any open connections, files, or other managed resources are properly released to prevent leaks.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBaseToolset
-