Skip to content

Commit 6cf21c3

Browse files
committed
more refactorings
1 parent 4f26fed commit 6cf21c3

26 files changed

Lines changed: 603 additions & 287 deletions

AGENTS.md

Lines changed: 211 additions & 109 deletions
Large diffs are not rendered by default.

ModuleConfig.bx

Lines changed: 4 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -36,135 +36,10 @@ class {
3636
* Fired when the module is registered and activated.
3737
*/
3838
function onLoad(){
39-
// Register our MCP Server here
40-
mcpServer(
41-
name: "cbMCP",
42-
description: "An MCP Server for ColdBox AI Tools",
43-
version: "@build.version@+@build.number@",
44-
cors: "*",
45-
statsEnabled: true,
46-
force: true
47-
)
48-
// Register tools
49-
.scan( "cbMCP.models.tools" )
50-
// -------------------------------------------------------------------------
51-
// Resources — ambient read-only context surfaced to the AI client
52-
// -------------------------------------------------------------------------
53-
.registerResource(
54-
uri : "coldbox://app/settings",
55-
name : "ColdBox Application Settings",
56-
description : "All active ColdBox application configuration settings",
57-
mimeType : "application/json",
58-
handler : () => {
59-
var settings = application.cbController.getConfigSettings()
60-
// Keep only serialisable scalar / array / struct values
61-
var safe = {}
62-
for ( var key in settings ) {
63-
var val = settings[ key ]
64-
if ( isSimpleValue( val ) || isArray( val ) || isStruct( val ) ) {
65-
safe[ key ] = val
66-
}
67-
}
68-
return ( safe )
69-
}
70-
)
71-
.registerResource(
72-
uri : "coldbox://app/modules",
73-
name : "Loaded ColdBox Modules",
74-
description : "All currently activated HMVC modules with their key metadata",
75-
mimeType : "application/json",
76-
handler : () => {
77-
var modules = application.cbController.getSetting( "modules" )
78-
var result = modules
79-
.keyArray()
80-
.sort( "text", "asc" )
81-
.map( name => {
82-
var m = modules[ name ]
83-
return {
84-
"name" : name,
85-
"version" : m.version ?: "",
86-
"description" : m.description ?: "",
87-
"entryPoint" : m.entryPoint ?: "",
88-
"author" : m.author ?: "",
89-
"activated" : m.activated ?: false
90-
}
91-
} )
92-
return ( result )
93-
}
94-
)
95-
.registerResource(
96-
uri : "coldbox://app/routes",
97-
name : "ColdBox Route Definitions",
98-
description : "All registered URL routes with their patterns and handler targets",
99-
mimeType : "application/json",
100-
handler : () => {
101-
var routes = application.cbController.getRoutingService().getRouter().getRoutes()
102-
var result = routes.map( r => {
103-
return {
104-
"pattern" : r.pattern ?: "",
105-
"handler" : r.handler ?: "",
106-
"action" : r.action ?: "",
107-
"name" : r.name ?: "",
108-
"methods" : r.methods ?: [],
109-
"module" : r.module ?: "",
110-
"namespace" : r.namespace ?: ""
111-
}
112-
} )
113-
return ( result )
114-
}
115-
)
116-
.registerResource(
117-
uri : "coldbox://app/handlers",
118-
name : "Registered ColdBox Handlers",
119-
description : "All registered event handlers (controllers) in the application",
120-
mimeType : "application/json",
121-
handler : () => {
122-
var handlers = listToArray( application.cbController.getSetting( "registeredHandlers" ) )
123-
handlers.sort( "text", "asc" )
124-
return ( handlers )
125-
}
126-
)
127-
// -------------------------------------------------------------------------
128-
// Prompts — pre-packaged AI workflows surfaced in the client prompt library
129-
// -------------------------------------------------------------------------
130-
.registerPrompt(
131-
name : "coldbox_app_overview",
132-
description : "Generates a comprehensive overview of this ColdBox application",
133-
handler : () => {
134-
var ctrl = application.cbController
135-
var appName = ctrl.getSetting( "appName" )
136-
var modules = ctrl.getSetting( "modules" ).keyArray().sort( "text", "asc" )
137-
return "Provide a comprehensive overview of this ColdBox application. Here is what I know so far:
138-
App Name : #appName#
139-
Modules : #modules.toList()#
140-
141-
Use the available MCP tools (get_coldbox_settings, get_application_structure, get_router_settings, get_interceptors, etc.) to gather additional details, then summarise the architecture, key modules, routing strategy, and any notable configuration."
142-
}
143-
)
144-
.registerPrompt(
145-
name : "debug_handler",
146-
description : "Diagnoses issues with a specific ColdBox event handler",
147-
args : [
148-
{ name: "handlerName", description: "The handler to investigate (e.g. 'Main' or 'api:Users')", required: true }
149-
],
150-
handler : ( handlerName = "" ) => {
151-
return "Diagnose the ColdBox handler '#handlerName#'. Use the get_handler_metadata and get_registered_handlers MCP tools to gather details, then identify any potential issues with routing, dependency injection, or event execution lifecycle."
152-
}
153-
)
154-
.registerPrompt(
155-
name : "cache_health_report",
156-
description : "Produces a CacheBox health report for all cache providers",
157-
handler : () => {
158-
return "Generate a CacheBox health report for this ColdBox application. Use the get_caches and get_cache_stats MCP tools to collect data on each cache provider, then summarise hit rates, eviction counts, object counts, and identify any providers showing signs of memory pressure or degraded performance."
159-
}
160-
)
161-
.registerPrompt(
162-
name : "interceptor_audit",
163-
description : "Audits all registered ColdBox interceptors and their interception points",
164-
handler : () => {
165-
return "Audit the ColdBox interceptors for this application. Use the get_interceptors MCP tool to list all registered interceptors and their interception points. Identify interceptors listening on the same points that might conflict, flag any with unusual names or patterns, and suggest ordering improvements where applicable."
166-
}
167-
)
39+
var mcpServer = new models.ColdBoxMCP()
40+
getBoxRuntime()
41+
.getGlobalService( "aiService" )
42+
.putServer( "cbMCP", mcpServer )
16843
}
16944

17045
/**

box.json

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,52 @@
11
{
2-
"name" : "ColdBox AI Tools",
3-
"version" : "1.0.0",
4-
"location" : "https://downloads.ortussolutions.com/ortussolutions/coldbox-modules/cbMCP/@build.version@/cbMCP-@build.version@.zip",
5-
"author" : "Ortus Solutions <info@ortussolutions.com>",
6-
"homepage" : "https://github.com/coldbox-modules/cbMCP",
7-
"documentation" : "https://github.com/coldbox-modules/cbMCP",
8-
"repository" : { "type" : "git", "url" : "https://github.com/coldbox-modules/cbMCP" },
9-
"bugs" : "https://github.com/coldbox-modules/cbMCP",
10-
"shortDescription" : "A collection of AI powered tools for ColdBox developers.",
11-
"slug" : "cbMCP",
12-
"type" : "modules",
13-
"keywords":"",
14-
"license" : [
15-
{ "type" : "Apache2", "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" }
16-
],
17-
"contributors" : [
18-
],
19-
"dependencies" :{
20-
},
21-
"devDependencies" :{
22-
"commandbox-boxlang":"*",
2+
"name":"ColdBox AI Tools",
3+
"version":"1.0.0",
4+
"location":"https://downloads.ortussolutions.com/ortussolutions/coldbox-modules/cbMCP/@build.version@/cbMCP-@build.version@.zip",
5+
"author":"Ortus Solutions <info@ortussolutions.com>",
6+
"homepage":"https://github.com/coldbox-modules/cbMCP",
7+
"documentation":"https://github.com/coldbox-modules/cbMCP",
8+
"repository":{
9+
"type":"git",
10+
"url":"https://github.com/coldbox-modules/cbMCP"
11+
},
12+
"bugs":"https://github.com/coldbox-modules/cbMCP",
13+
"shortDescription":"A collection of AI powered tools for ColdBox developers.",
14+
"slug":"cbMCP",
15+
"type":"modules",
16+
"keywords":"",
17+
"license":[
18+
{
19+
"type":"Apache2",
20+
"url":"http://www.apache.org/licenses/LICENSE-2.0.html"
21+
}
22+
],
23+
"contributors":[],
24+
"dependencies":{
25+
"testbox":"^7.0.0+19"
26+
},
27+
"devDependencies":{
28+
"commandbox-boxlang":"*",
2329
"commandbox-docbox":"*"
24-
},
25-
"ignore":[
30+
},
31+
"ignore":[
2632
"**/.*",
2733
"test-harness",
28-
"/server*.json"
34+
"/server*.json"
2935
],
30-
"scripts":{
31-
"build:module":"task run taskFile=build/Build.cfc :projectName=`package show slug` :version=`package show version`",
32-
"build:docs":"task run taskFile=build/Build.cfc target=docs :projectName=`package show slug` :version=`package show version`",
36+
"scripts":{
37+
"build:module":"task run taskFile=build/Build.cfc :projectName=`package show slug` :version=`package show version`",
38+
"build:docs":"task run taskFile=build/Build.cfc target=docs :projectName=`package show slug` :version=`package show version`",
3339
"install:dependencies":"install && cd test-harness && install",
34-
"release":"recipe build/release.boxr",
35-
"start:boxlang" : "server start serverConfigFile=server-boxlang@1.json",
36-
"stop:boxlang" : "server stop serverConfigFile=server-boxlang@1.json",
37-
"logs:boxlang" : "server log serverConfigFile=server-boxlang@1.json",
38-
"forget:boxlang" : "server forget serverConfigFile=server-boxlang@1.json"
40+
"release":"recipe build/release.boxr",
41+
"start:boxlang":"server start serverConfigFile=server-boxlang@1.json",
42+
"stop:boxlang":"server stop serverConfigFile=server-boxlang@1.json",
43+
"logs:boxlang":"server log serverConfigFile=server-boxlang@1.json",
44+
"forget:boxlang":"server forget serverConfigFile=server-boxlang@1.json"
45+
},
46+
"testbox":{
47+
"runner":"http://localhost:60299/tests/runner.bxm"
3948
},
40-
"testbox":{
41-
"runner":"http://localhost:60299/tests/runner.cfm"
49+
"installPaths":{
50+
"testbox":"/Users/lmajano/Sites/projects/commandbox-modules/testbox-cli/testbox/"
4251
}
4352
}

models/ColdBoxMCP.bx

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
3+
* www.ortussolutions.com
4+
* ---
5+
* MCP Tools for ColdBox application introspection.
6+
*
7+
* Provides the MCP server registration, resources, prompts, and tool discovery
8+
* for the cbMCP module.
9+
*/
10+
class extends="bxModules.bxai.models.mcp.MCPServer" {
11+
12+
/**
13+
* Initialize the ColdBox MCP server.
14+
*/
15+
function init() {
16+
super.init(
17+
name = "cbMCP",
18+
description = "An MCP Server for ColdBox AI Tools",
19+
version = "@build.version@+@build.number@",
20+
cors = "*",
21+
statsEnabled = true,
22+
force = true
23+
)
24+
25+
this.scan( "cbMCP.models.tools" )
26+
registerResources()
27+
registerPrompts()
28+
29+
return this
30+
}
31+
32+
/**
33+
* Register the ambient read-only resources exposed by the server.
34+
*/
35+
private void function registerResources() {
36+
this.registerResource(
37+
uri : "coldbox://app/settings",
38+
name : "ColdBox Application Settings",
39+
description : "All active ColdBox application configuration settings",
40+
mimeType : "application/json",
41+
handler : () => {
42+
var settings = application.cbController.getConfigSettings()
43+
var safe = {}
44+
for ( var key in settings ) {
45+
var val = settings[ key ]
46+
if ( isSimpleValue( val ) || isArray( val ) || isStruct( val ) ) {
47+
safe[ key ] = val
48+
}
49+
}
50+
return safe
51+
}
52+
)
53+
54+
this.registerResource(
55+
uri : "coldbox://app/modules",
56+
name : "Loaded ColdBox Modules",
57+
description : "All currently activated HMVC modules with their key metadata",
58+
mimeType : "application/json",
59+
handler : () => {
60+
var modules = application.cbController.getSetting( "modules" )
61+
return modules
62+
.keyArray()
63+
.sort( "text", "asc" )
64+
.map( name => {
65+
var m = modules[ name ]
66+
return {
67+
name : name,
68+
version : m.version ?: "",
69+
description : m.description ?: "",
70+
entryPoint : m.entryPoint ?: "",
71+
author : m.author ?: "",
72+
activated : m.activated ?: false
73+
}
74+
} )
75+
}
76+
)
77+
78+
this.registerResource(
79+
uri : "coldbox://app/routes",
80+
name : "ColdBox Route Definitions",
81+
description : "All registered URL routes with their patterns and handler targets",
82+
mimeType : "application/json",
83+
handler : () => {
84+
var routes = application.cbController.getRoutingService().getRouter().getRoutes()
85+
return routes.map( r => {
86+
return {
87+
pattern : r.pattern ?: "",
88+
handler : r.handler ?: "",
89+
action : r.action ?: "",
90+
name : r.name ?: "",
91+
methods : r.methods ?: [],
92+
module : r.module ?: "",
93+
namespace : r.namespace ?: ""
94+
}
95+
} )
96+
}
97+
)
98+
99+
this.registerResource(
100+
uri : "coldbox://app/handlers",
101+
name : "Registered ColdBox Handlers",
102+
description : "All registered event handlers (controllers) in the application",
103+
mimeType : "application/json",
104+
handler : () => {
105+
var handlers = listToArray( application.cbController.getSetting( "registeredHandlers" ) )
106+
handlers.sort( "text", "asc" )
107+
return handlers
108+
}
109+
)
110+
}
111+
112+
/**
113+
* Register the prompt classes for the server.
114+
*/
115+
private void function registerPrompts() {
116+
new cbMCP.models.prompts.ApplicationPrompts().register( this )
117+
new cbMCP.models.prompts.HandlerPrompts().register( this )
118+
new cbMCP.models.prompts.CacheBoxPrompts().register( this )
119+
new cbMCP.models.prompts.InterceptorPrompts().register( this )
120+
}
121+
122+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
3+
* www.ortussolutions.com
4+
* ---
5+
* MCP prompts for ColdBox application overview workflows.
6+
*/
7+
class extends="BasePrompt" {
8+
public void function register( required any mcpServer ) {
9+
arguments.mcpServer.registerPrompt(
10+
name : "coldbox_app_overview",
11+
description : "Generates a comprehensive overview of this ColdBox application",
12+
handler : function( struct args = {} ) {
13+
var ctrl = application.cbController
14+
var appName = ctrl.getSetting( "appName" )
15+
var modules = ctrl.getSetting( "modules" ).keyArray().sort( "text", "asc" )
16+
return "Provide a comprehensive overview of this ColdBox application. Here is what I know so far:\nApp Name : #appName#\nModules : #modules.toList()#\n\nUse the available MCP tools (get_coldbox_settings, get_application_structure, get_router_settings, get_interceptors, etc.) to gather additional details, then summarise the architecture, key modules, routing strategy, and any notable configuration."
17+
}
18+
)
19+
}
20+
}

models/prompts/BasePrompt.bx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
3+
* www.ortussolutions.com
4+
* ---
5+
* Base prompt helpers for cbMCP prompt classes.
6+
*/
7+
class {
8+
}

0 commit comments

Comments
 (0)