mcpClient

Creates an MCP (Model Context Protocol) client that connects to an MCP server over HTTP or STDIO. Returns a client, or an array of clients when a configFile describing several servers is passed.

mcpClient(configData) → returns any

Argument Reference

configData struct
Required

Struct with a transport key (type http with a url, or type stdio with a command and args), or a configFile path to a JSON file describing several servers. Optional keys include clientInfo, capabilities, initializationTimeout, requestTimeout and consumer functions such as loggingConsumer.

Compatibility

RustCFML:

Uses a different signature: mcpClient(name), where name is a server declared under mcpServers in .cfconfig.json. Returns the same client handle as mcpConnect(). Resolving a name requires serve mode with a loaded configuration; in a CLI run, use mcpConnect() with an explicit command or url.

Links more information about mcpClient

Examples
Sample code invoking the mcpClient function

Declare servers once in .cfconfig.json and reference them by name.

// .cfconfig.json
// {
//   "mcpServers": {
//     "files":  { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"] },
//     "remote": { "url": "https://example.com/mcp" }
//   }
// }

client = mcpClient( "files" );
tools  = client.tools();
client.close();

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub