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
aiTool()creates a tool definition with a name, description, and handler function.addParameter()defines the arguments the tool accepts.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
Module Startup (Recommended)
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_statusanalytics_get_dashboardnotification_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
MCP Tools Reference — Complete catalog of built-in tools
MCP Prompts Reference — Pre-built prompt catalog
Protocol Reference — JSON-RPC 2.0 endpoint details
Last updated
Was this helpful?
