wrenchTools & MCP

Tools, the Global Tool Registry, MCP server seeding, and the ClosureTool pattern for building AI agents with real-world capabilities.

circle-info

Since BoxLang AI v3.0+

Agents use tools to perform real-world actions — querying databases, calling APIs, running calculations, and more. In v3.0, tools can also be sourced from the Global Tool Registry and from remote MCP servers.

Basic Tool Usage

// Inline lambda tool
weatherTool = aiTool(
    "get_weather",
    "Get current weather for a location",
    location => getWeatherData( location )
).describeLocation( "City and country, e.g. Boston, MA" )

agent = aiAgent(
    name : "WeatherBot",
    tools: [ weatherTool ]
)

response = agent.run( "What's the weather in Paris?" )
// Agent automatically calls get_weather("Paris")

Global Tool Registry (v3.0+)

The Tool Registry is a module-wide singleton that stores tools by name (optionally namespaced by module). Agents can look up tools by name at runtime instead of holding direct references.

Registering with Shorthand

@AITool Annotation Scanning

Annotate methods with @AITool and scan a class or package path:

Registry API

Method
Description

register( tool, module )

Register an ITool instance

register( name, description, callback, module )

Shorthand — builds ClosureTool

scan( instanceOrPath, module )

Scan @AITool annotations

get( key )

Get a tool by name or name@module key

has( key )

Check if a tool exists

resolveTools( array )

Convert string keys to ITool instances

unregister( key )

Remove a tool

keys()

List all registered keys

See Tool Registry for the full reference.

ClosureTool Pattern

ClosureTool wraps a lambda directly without going through aiTool():

Accessing _chatRequest in Tools

Tools receive the live AiChatRequest as _chatRequest in their arguments — useful for reading the current model, adding context, or adjusting behavior:

MCP Server Seeding (v3.0+)

Connect agents to remote MCP servers. Tool names from the server are automatically fetched and made available to the agent:

MCP Authentication

Dynamic Tool Assignment

Last updated