McpTool

class McpTool(mcpClient: Client, descriptor: ToolDescriptor) : Tool<JsonObject, CallToolResult?> (source)

A Tool implementation that calls an MCP (Model Context Protocol) tool.

This class serves as a bridge between the agent framework's Tool interface and the MCP SDK. It allows MCP tools to be used within the agent framework by:

  1. Converting agent framework tool arguments to MCP tool arguments

  2. Calling the MCP tool through the MCP client

  3. Converting MCP tool results back to agent framework tool results

Constructors

Link copied to clipboard
constructor(mcpClient: Client, descriptor: ToolDescriptor)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val resultSerializer: KSerializer<CallToolResult?>

Functions

Link copied to clipboard
Link copied to clipboard
fun decodeResult(rawResult: JsonElement): CallToolResult?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun encodeResult(result: CallToolResult?): JsonElement
Link copied to clipboard
open override fun encodeResultToString(result: CallToolResult?): String

Postprocess result string representation for LLMs a bit, removing unnecessary meta fields.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open suspend override fun execute(args: JsonObject): CallToolResult

Executes the MCP tool with the given arguments.

Link copied to clipboard
suspend fun executeUnsafe(args: Any?): CallToolResult?