For the complete documentation index, see llms.txt. This page is also available as Markdown.

Extending with Custom Tools

Register custom MCP tools and prompts from your own modules and applications at runtime.

You are not limited to the built-in introspection tools. Any module or application can register its own tools, resources, and prompts into the BoxLang MCP server at runtime using the bx-ai BIF mcpServer( "boxlang" ).


πŸ”§ Getting the Server Instance

var server = mcpServer( "boxlang" )

This returns the MCPServer instance that manages all tools, prompts, and resources.


πŸ› οΈ Registering a Simple Tool

The simplest way to register a tool is with a handler closure:

server.registerTool(
  aiTool(
    "check_deployment_status",
    "Check the current deployment status of the application",
    ( environment ) => {
      var status = deploymentService.getStatus( environment )
      return {
        environment: arguments.environment,
        version: status.version,
        deployedAt: status.deployedAt.toString(),
        healthy: status.healthy
      }
    }
  )
  .addParameter(
    aiToolParam( "environment", "string", "The deployment environment to check (e.g., staging, production)" )
      .required()
  )
)

How it Works

  1. aiTool() creates a tool definition with a name, description, and handler function

  2. .addParameter() defines the arguments the tool accepts

  3. .registerTool() makes the tool available to MCP clients


πŸ“ Registering a Custom Prompt

The prompt handler receives arguments and returns an array of messages (system and user roles) that guide the AI agent.


πŸ” Classpath Scanning

For larger tool sets, annotate methods with @mcpTool and scan a package:

The scanner discovers all methods annotated with @mcpTool and registers them automatically. Each method becomes a tool with the method name as the tool name.


πŸ“¦ Batch Registration

Register multiple tools at once from an array of AITool instances:


πŸ”Ž Accessing Existing Tools

You can look up any registered tool by name:


πŸ—οΈ Best Practices for Registration

Register custom tools in your module's onLoad method in ModuleConfig.bx:

This ensures your tools are available as soon as the MCP server is active.

Application Startup

For application-level tools, use the onApplicationStart lifecycle method in your Application.bx.

ColdBox Applications

Register tools in config/ColdBox.cfc in the configure() method, or in the onApplicationStart handler.

Use Descriptive Names

Follow the existing naming convention: domain_action_description. For example:

  • deployment_get_status

  • analytics_get_dashboard

  • notification_send_alert

Return Structured Data

Always return a struct from your tool handler. The MCP server serializes the return value as JSON in the response.


πŸ’‘ Complete Working Example

Here's a full example that registers a deployment health tool from a module:


πŸ“š Next Steps

Last updated

Was this helpful?