# McpToolset

class McpToolset : Toolset

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 McpToolsetConfig.toToolset, for example:

    val toolset =
      McpToolset.McpToolsetConfig(
          stdioConnectionParams =
            McpConnectionParameters.Stdio(
              command = "npx",
              args = listOf("-y", "@modelcontextprotocol/server-filesystem"),
            ),
          toolFilter = listOf("read_file", "list_directory"),
        )
        .toToolset()

Content copied to clipboard

The constructor is `internal`; user code should use McpToolsetConfig.toToolset instead.

## Types

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

Configuration for an McpToolset, used to construct one via toToolset.

## Functions

close
Link copied to clipboard
open override fun close()

Performs cleanup and releases resources held by the toolset.

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

Return all tools in the toolset based on the provided context.

listResources
Link copied to clipboard
suspend fun listResources(readonlyContext: ReadonlyContext? = null): List<String>

Returns a list of resource names available on the MCP server.

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

Allows the toolset to process the LLM request.

readResource
Link copied to clipboard
suspend fun readResource(uri: String, readonlyContext: ReadonlyContext? = null): Any

Fetches and returns a list of contents of the resource with the given URI.