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.

Built-in Audio Tools (v3.1+) 🎙️

The bx-ai module automatically registers three audio tools at startup. Opt in by including their keys in your agent's tools array — no registration code required.

Tool Key
Description

speak@bxai

Convert text to speech; returns the absolute path to the saved audio file (auto-generates a temp file if no outputFile is provided)

transcribe@bxai

Transcribe a local audio file path or URL to plain text

translate@bxai

Translate any-language audio to English text

💡 The speak@bxai tool writes to a temporary file automatically when the agent does not supply an outputFile. For production use, instruct the agent to provide a specific output path or post-process the returned path.

See Audio & Speech for full details on providers, voices, and formats.

Built-in FileSystem Tools (v3.1+) 📂

FileSystemTools gives agents the ability to read, write, move, delete, and list files and directories on the local filesystem. It is not auto-registered — you must opt in explicitly, which lets you apply path guards that restrict the AI to specific directories.

Tool Keys

Tool Key
Description

readFile@bxai

Read a file and return its text content

writeFile@bxai

Write (overwrite) text to a file; creates parent dirs as needed

appendFile@bxai

Append text to a file; creates the file if it does not exist

fileMetadata@bxai

Return file metadata (name, size, MIME type, modified date) as JSON

pathExists@bxai

Check whether a file or directory exists ("true" / "false")

deleteFile@bxai

Delete a file ⚠️ irreversible

moveFile@bxai

Move or rename a file

copyFile@bxai

Copy a file to a new location

listDirectory@bxai

List directory contents as a JSON array; supports glob filters and recursion

createDirectory@bxai

Create a directory including any missing parent directories

deleteDirectory@bxai

Recursively delete a directory and all its contents ⚠️ irreversible

Registration with Path Guards

Every path argument is resolved to its canonical form before the guard check runs. This blocks directory-traversal tricks like ../../etc/passwd even if the AI constructs them.

Example: Coding Agent

Example: File listing with glob filter

🔐 deleteFile@bxai and deleteDirectory@bxai are irreversible. Consider omitting them from agents that only need read or write access.

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

  • Tool Registry — Full registry reference

  • AI ToolsaiTool() BIF reference

  • Skills — Injecting knowledge vs. calling tools

  • MCP Server — Building your own MCP server

  • MCP Client — Consuming MCP servers directly

Last updated