mcpNotify

Pushes an MCP notification to connected clients from anywhere: an ordinary page, a cfthread, or a scheduled job. This is the emit-from-anywhere ergonomic that wsPublish provides for WebSockets. The server argument is optional inside a handler (it defaults to the server the call is running on). When to is given, the notification is delivered only to that session; otherwise it is delivered to every session of the server that has a stream open. Returns the number of sessions reached. Always recorded into the mcp test log so the CFML test suite can assert on it with no client attached.

mcpNotify( server [, method [, params [, to]]] ) → returns numeric

This function requires RustCFML.  Not supported on Lucee, Adobe ColdFusion, etc.

Argument Reference

server string

The MCP server to notify, e.g. "/mcp/docs". Inside a handler this defaults to the server of the current call.

method string
Required

The notification method name, e.g. "notifications/resources/updated". Required.

params any

A struct of parameters to attach to the notification, converted to JSON for the wire.

to string

An optional session id. When set, the notification is delivered only to that session instead of every open session of the server.

Links more information about mcpNotify

Examples
Sample code invoking the mcpNotify function

From any page or background job, publish a resource-changed notification to all open sessions of a server.

mcpNotify( server = "/mcp/docs", method = "notifications/resources/updated"
         , params = { uri = "doc://pages/intro" } );

Expected Result: Returns the number of sessions the notification reached.

Use mcpSessions() to get live ids, then target one of them with the to argument.

var sessions = mcpSessions( "/mcp/docs" );
mcpNotify( server = "/mcp/docs", method = "notifications/announcement"
         , params = { text = "redeployed" }, to = sessions[ 1 ] );

Expected Result: Returns 1 when the target session had a stream open.

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

Fork me on GitHub