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

Registering Server with Client

Last update:
May 18, 2026
Once you have an application-level MCP server (local) or endpoint (remote), you need to register and connect it from your ColdFusion MCP client.

Overview

There are two main patterns:
  • ColdFusion acting as an MCP server for an external host (e.g., IDE, agent framework).
  • ColdFusion acting as an MCP client consuming a remote MCP server.
Below we focus on the second pattern—CF as a client—since that’s where most app code lives.

Building a Client Transport

First, define the transport:
HTTP / SSE Transport (Remote Server)

transport = mcpTransportBuilder("http")
    .url("https://remote.mcpservers.org/fetch/mcp")
    .header("Authorization", "Bearer #application.mcpAuthToken#")
    .build();
      
STDIO Transport (Local Process)

transport = mcpTransportBuilder("stdio")
    .command("/usr/local/bin/node")
    .args(["/path/to/server.js"])
    .environment({ apiKey: "sk-xxx" })
    .build();
      
Respect the same security principles:
  • No hard-coded secrets in code.
  • Use environment variables or secure storage for credentials.
  • Use HTTPS for remote servers.

Creating the MCP Client

Once you have a transport, build a client that speaks MCP:

mcpClient = mcpClientBuilder()
    .transport(transport)
    .capabilities({
        tools     : true,
        prompts   : true,
        resources : true
    })
    .build();
      
The client’s capabilities indicate what the client is prepared to use. The actual intersection with the server’s capabilities is established during initialize.

Client Initialization Flow

A typical client flow per operation:
  • Build transport
  • Build client
  • Initialize MCP session
  • Use tools/prompts/resources
  • Shutdown (optional, if the client is not long-lived)
Example utility function:

public any function getMcpClient() {
    // Could be per-request, per-session, or cached with a timeout
    var transport = mcpTransportBuilder("http")
        .url(application.mcpEndpointUrl)
        .header("Authorization", "Bearer #application.mcpAuthToken#")
        .build();

    var client = mcpClientBuilder()
        .transport(transport)
        .capabilities({ tools: true, prompts: true, resources: true })
        .build();

    client.initialize({
        protocolVersion: "2025-03-26",
        clientInfo: {
            name    : "cf-app",
            version : "1.0.0"
        }
    });

    return client;
}
      
The initialization call (initialize) is usually handled under the hood by the client builder; if not, make sure you call it exactly once per client before listing or calling tools.

Registering the Application Server with a Client

If your ColdFusion app both hosts an MCP server and uses it via a client (for internal routing, or for test harnesses), you can connect them directly.
Assuming:
  • application.mcpServer is your server instance.
  • Your MCP client builder supports a “local server” transport.
Example pattern:

function getLocalMcpClient() {
    if (!structKeyExists(application, "mcpServer")) {
        throw(type="MCP.NotInitialized", message="MCP server not initialized.");
    }

    var transport = mcpTransportBuilder("local")
        .server(application.mcpServer)
        .build();

    var client = mcpClientBuilder()
        .transport(transport)
        .capabilities({ tools: true, prompts: true, resources: true })
        .build();

    client.initialize({
        protocolVersion: "2025-03-26",
        clientInfo: {
            name    : "cf-local-client",
            version : "1.0.0"
        }
    });

    return client;
}
      
This method lets you:
  • Reuse the same tool implementations for internal and external use.
  • Test tools without an external MCP host.
  • Keep the server in the application scope and clients short-lived and stateless.

Using a Registered Client in Your Code

Once you have getMcpClient(), calling tools becomes straightforward:

function getWeatherForCity(required string city) {
    var client = getMcpClient();

    var response = client.tools.call(
        name      = "getWeather",
        arguments = { city = city }
    );

    if (response.isError) {
        // Handle tool-level error
        writeLog(file="mcp", type="error", text="getWeather error: #response.errorMessage#");
        throw(type="MCP.ToolError", message=response.errorMessage);
    }

    return response.content[1].text;
}
      
From the rest of your application’s perspective, the MCP tool call looks like a normal function call with a structured response.

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