Whatever message this page gives is out now! Go check it out!

Application-Scope Lifecycle

Last update:
May 18, 2026
Once initialized, your MCP server should live for the full lifetime of the ColdFusion application.

Overview

Once initialized, your MCP server should live for the full lifetime of the ColdFusion application. This ensures:
  • Tools and prompts are loaded once, not on every request.
  • Per-server caches and internal state (if any) are preserved.
  • Clients can safely assume a server is available as long as the app is running.

Where to Store the Server

The most common pattern is:
  • application.mcpServer — the shared MCP server instance
  • Optionally, application.mcpConfig — a struct holding config metadata (roots, URLs, etc.)
This makes the server accessible from:
  • Other CFCs through application.mcpServer
  • Utility layers that need to connect server and client logic

Handling Restart and Reinitialization

When the application restarts (deployment, config change, CF restart):
  • onApplicationStart() runs again.
  • The MCP server is rebuilt and stored in the application scope.
  • Existing MCP clients (if they persist anywhere) should be aware they may need to re-initialize.
Best practice:
  • Build clients per operation or per session rather than storing a long-lived client with stale references.
  • Or, if you cache clients, ensure they can detect a dead server and gracefully reconnect.

Shutting Down or Cleaning Up

Most MCP server implementations are designed as in-process objects; they clean up automatically when the application is unloaded.
If your server:
  • Opens external resources (connections, files, background tasks)
  • Spawns local processes (for STDIO tools)
Then you should provide a shutdown hook:

function onApplicationEnd(appScope) {
    if (structKeyExists(appScope, "mcpServer") && isCustomFunction(appScope.mcpServer.shutdown)) {
        try {
            appScope.mcpServer.shutdown();
        } catch (any e) {
            writeLog(file="mcp", type="warn", text="Error during MCP server shutdown: #e.message#");
        }
    }
}
      
This is optional and depends on your actual server implementation.

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page