McpToolset

Connects to an MCP Server and exposes the server's MCP tools to an agent as ADK BaseTools.

McpToolset manages the lifecycle of the connection to a single MCP server and lazily fetches the server's tool list on first use. The instance can then be passed directly to an LlmAgent's toolsets.

Instances are created via McpToolset.McpToolsetConfig.toToolset, for example:

val toolset =
McpToolset.McpToolsetConfig(
stdioConnectionParams =
McpConnectionParameters.Stdio(
serverParameters =
ServerParameters.builder("npx")
.args("-y", "@modelcontextprotocol/server-filesystem")
.build()
),
toolFilter = ToolFilter.allowList("read_file", "list_directory"),
)
.toToolset()

The constructor is internal; user code should use McpToolset.McpToolsetConfig.toToolset instead. Portable Streamable HTTP on JVM and Android uses RemoteMcpToolsetConfig.

A configured headerProvider is invoked before tool discovery and again before each tool call (matching ADK Python). An IllegalArgumentException from that provider or from a ToolFilter.Predicate during getTools is wrapped in McpToolLoadingException.

类型

Link copied to clipboard
object Companion
Link copied to clipboard
data class McpToolsetConfig(val stdioConnectionParams: McpConnectionParameters.Stdio? = null, val sseConnectionParams: McpConnectionParameters.Sse? = null, val streamableHttpConnectionParams: McpConnectionParameters.StreamableHttp? = null, val toolFilter: ToolFilter? = null, val useMcpResources: Boolean = false, val maxMcpResourceLength: Int = DEFAULT_MAX_MCP_RESOURCE_LENGTH)

配置信息: McpToolset用于通过这些组件构建一个整体(或系统)。 toToolset.

函数

Link copied to clipboard
open override fun close()

执行清理操作,并释放工具集所占用的资源。

Link copied to clipboard
open suspend override fun getTools(readonlyContext: ReadonlyContext? = null): List<BaseTool>

发现由 MCP 服务器发布的工具信息。

Link copied to clipboard
open suspend fun processLlmRequest(toolContext: ToolContext, llmRequest: LlmRequest): LlmRequest

该功能允许工具集处理来自大型语言模型(LLM)的请求。