Skip to contents

Encapsulates tool metadata and execution logic for MCP protocol integration. Provides comprehensive validation through active bindings, automatic type conversion, and structured tool calling interface. Maintains tool properties with validation and enables direct tool execution with JSON input handling.

Details

Tool Definition

Manages tool lifecycle through validated properties:

  • Function Storage: Maintains executable function with validation

  • Metadata Management: Stores name, description, and annotations

  • Argument Validation: Ensures proper type definitions for parameters

  • Type Conversion: Handles JSON-to-R type conversion automatically

Active bindings

name

Tool name with MCP protocol compliance validation

description

Tool description ensuring non-empty string format

arguments

Argument definitions ensuring proper list structure

convert

JSON conversion flag ensuring logical type

annotations

Tool annotations ensuring basic R type compliance

fun

Executable function ensuring callable object

Methods


Method new()

Initialize ToolDef with validation

Usage

ToolDef$new(
  fun,
  name,
  description,
  arguments = list(),
  convert = TRUE,
  annotations = list()
)

Arguments

fun

Function to be invoked

name

Tool name

description

Tool description

arguments

Named list of argument definitions

convert

Enable JSON type conversion

annotations

Additional tool metadata

Returns

New ToolDef instance


Method call()

Execute tool with arguments and optional type conversion

Usage

ToolDef$call(...)

Arguments

...

Arguments to pass to the tool function

Returns

Result of tool function execution


Method print()

Print formatted tool definition with metadata

Usage

ToolDef$print(...)

Arguments

...

Additional arguments (unused)

Returns

Self (invisibly)


Method clone()

The objects of this class are cloneable with this method.

Usage

ToolDef$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.