Skip to main content

Overview

MCP (Model Context Protocol) is an open standard introduced by Anthropic for integrating AI systems with external tools, data sources, and applications. MCP routes enable AI assistants like Claude, ChatGPT, or custom LLM applications to interact with your Coreflux broker—reading MQTT data, executing LoT actions, and controlling IoT devices.
Think of MCP as a universal adapter for AI. Just like USB-C lets you connect any device to any port, MCP lets any AI assistant connect to any tool or data source. With MCP routes, your Coreflux broker becomes an AI-accessible tool that assistants can query, control, and automate.

In This Page

SectionDescription
Basic SyntaxDefine an MCP route
ConfigurationServer command, arguments, and client name
Configuration ExamplesFilesystem, custom, and Node.js server setups
MCP Server ExamplesNode.js and Python MCP servers for IoT
Calling MCP ToolsExecute MCP tools from LoT Actions
Tool DiscoveryDiscover available tools via MQTT system topics
Use CasesCommon MCP integration patterns
Protocol OverviewUnderstanding tools, resources, and prompts
Best PracticesSecurity, resource management, and error handling

Basic Syntax

The MCP route type exposes your Coreflux broker as an MCP server, allowing AI assistants to:
  • Access MQTT data and topic structures
  • Execute LoT actions and queries
  • Interact with connected devices
  • Provide intelligent automation and responses

Basic Syntax

DEFINE ROUTE MCPServer WITH TYPE MCP
    ADD MCP_CONFIG
        WITH SERVER_COMMAND "npx"
        WITH SERVER_ARGUMENTS "-y, @modelcontextprotocol/server-filesystem"
        WITH CLIENT_NAME "CorefluxBroker"

MCP Configuration

MCP_CONFIG Parameters

SERVER_COMMAND
string
MCP server command to execute (e.g., npx, python, node).
SERVER_ARGUMENTS
string
Comma-separated server arguments (e.g., -y, @modelcontextprotocol/server-filesystem).
CLIENT_NAME
string
MCP client identifier. Default: CorefluxBroker.

Configuration Examples

Enable AI access to file operations:
DEFINE ROUTE MCPFilesystem WITH TYPE MCP
    ADD MCP_CONFIG
        WITH SERVER_COMMAND "npx"
        WITH SERVER_ARGUMENTS "-y, @modelcontextprotocol/server-filesystem, /data"
        WITH CLIENT_NAME "CorefluxFS"

MCP Server Examples

The MCP ecosystem includes servers for various platforms and services. These examples show how to connect popular MCP servers to your Coreflux broker for IoT integration.
Node.js-based MCP servers can be run directly using npx. These are the most common and include official Anthropic servers.
ServerLoT ConfigurationIoT Use Case
FilesystemSERVER_COMMAND "npx" with SERVER_ARGUMENTS "-y, @modelcontextprotocol/server-filesystem, /data"Read sensor logs, manage config files
Google DriveSERVER_COMMAND "npx" with SERVER_ARGUMENTS "-y, @modelcontextprotocol/server-gdrive"Cloud backup of IoT data
SlackSERVER_COMMAND "npx" with SERVER_ARGUMENTS "-y, @modelcontextprotocol/server-slack"Send alerts to team channels
MemorySERVER_COMMAND "npx" with SERVER_ARGUMENTS "-y, @modelcontextprotocol/server-memory"Persist context across AI sessions
FetchSERVER_COMMAND "npx" with SERVER_ARGUMENTS "-y, @modelcontextprotocol/server-fetch"Access external APIs and web data
Windows ControlSERVER_COMMAND "npx" with SERVER_ARGUMENTS "-y, mcp-control"Automate HMI/SCADA systems
Example: Slack Alerts for IoT Events
DEFINE ROUTE MCPSlack WITH TYPE MCP
    ADD MCP_CONFIG
        WITH SERVER_COMMAND "npx"
        WITH SERVER_ARGUMENTS "-y, @modelcontextprotocol/server-slack"
        WITH CLIENT_NAME "CorefluxSlack"

Calling MCP Tools

Once an MCP route is defined, you can call its tools from within LoT Actions using the CALL MCP syntax. This enables AI-powered automation triggered by MQTT events.

Basic Syntax

The standard syntax to invoke an MCP tool from an Action:
CALL MCP "RouteName.ToolName"
    WITH (arg1 = value1, arg2 = value2)
    RETURN AS {result_variable}
ComponentFormatDescription
Route.Tool"RouteName.ToolName"Route name and tool name separated by a dot
WITHWITH (name = value, ...)Named arguments in parentheses
RETURN ASRETURN AS {varname}Capture the result in a variable

Complete Example

This Action monitors a temperature sensor and uses an MCP tool to send a Slack message when the temperature exceeds a threshold:
DEFINE ACTION TemperatureAlert
ON TOPIC "sensors/+/temperature" DO
    SET "temp" WITH (GET JSON "value" IN PAYLOAD AS DOUBLE)
    SET "sensor_id" WITH TOPIC POSITION 2
    
    IF {temp} > 80 THEN
        CALL MCP "MCPSlack.send-message"
            WITH (channel = "alerts", message = "🔥 Sensor " + {sensor_id} + " at " + {temp} + "°C")
            RETURN AS {result}
        
        PUBLISH TOPIC "alerts/temperature/sent" WITH "Sensor: " + {sensor_id} + " Temp: " + {temp} + " Result: " + {result}
    END IF

Syntax Variations

Some tools don’t require arguments:
CALL MCP "MCPSystem.get-status"
    RETURN AS {status}
Pass multiple named parameters:
CALL MCP "MCPFilesystem.write-file"
    WITH (path = "/data/log.txt", content = {payload}, append = true)
    RETURN AS {write_result}
Build dynamic values using expressions:
CALL MCP "MCPSlack.send-message"
    WITH (message = "Device " + {device_id} + " reported: " + {value} + " at " + TIMESTAMP "UTC")
    RETURN AS {chat_result}

Tool Discovery

When an MCP route connects to a server, Coreflux automatically discovers all available tools and publishes them to MQTT system topics. This allows you to dynamically query what tools are available.

System Topics

TopicDescription
$SYS/Coreflux/Routes/{RouteName}/ToolsSummary of all tools for a route
$SYS/Coreflux/Routes/{RouteName}/Tools/{ToolName}Detailed info for a specific tool

Tools Summary Payload

Subscribe to the summary topic to see all available tools:
{
  "route_name": "MCPSlack",
  "route_type": "MCP",
  "total_tools": 8,
  "tools": ["send-message", "list-channels", "get-channel-history", "add-reaction", ...],
  "timestamp": "2025-12-31T12:00:00.000Z"
}

Individual Tool Payload

Each tool publishes detailed metadata including parameters and usage examples:
{
  "name": "send-message",
  "route_name": "MCPSlack",
  "tool_type": "MCP",
  "description": "Send a message to a Slack channel",
  "parameters": {
    "channel": { "type": "string", "required": true },
    "message": { "type": "string", "required": true }
  },
  "usage_example": "CALL MCP \"MCPSlack.send-message\" WITH (channel = {channel}, message = {message}) RETURN AS {result}",
  "capability": {
    "execution_count": 42,
    "average_latency_ms": 150.25,
    "reliability_percent": 98.5
  },
  "timestamp": "2025-12-31T12:00:00.000Z"
}

Subscribing to Tool Discovery

Use MQTT Explorer or any MQTT client to discover available tools:
What to FindTopic Pattern
All tools for a specific route$SYS/Coreflux/Routes/MCPSlack/Tools
Details for a specific tool$SYS/Coreflux/Routes/MCPSlack/Tools/send-message
All tools across all MCP routes$SYS/Coreflux/Routes/+/Tools/#
Tool discovery topics are retained messages, so the information is immediately available when you subscribe—you don’t need to wait for the next update.

Use Cases

Enable AI assistants to query MQTT topics and provide intelligent insights about your IoT data. The AI can analyze patterns, detect anomalies, and summarize system status in natural language.
Allow operators to control devices through natural language commands processed by AI. Instead of writing LoT code, operators can say “turn off pump 3” and the AI translates it to the appropriate MQTT publish.
Let AI systems analyze data patterns and trigger automated actions through LoT. The AI can make intelligent decisions based on historical data and current conditions.
Provide AI with access to system documentation and configuration for intelligent support. The AI can answer questions about your setup and suggest configurations.

Integration Architecture

MCP Routes allow the Coreflux Broker to connect to external MCP servers as a client. This enables LoT Actions to call tools provided by any MCP server—file systems, cloud services, communication platforms, and more.

How It Works

  1. Define MCP Routes - Each route connects to an external MCP server
  2. Discover Tools - The broker discovers available tools from each server
  3. Call from Actions - Use CALL MCP in LoT Actions to invoke any tool
  4. Reusable Connections - Multiple actions can share the same MCP route
MCP as a Connection Type. Just like database routes or REST API routes, MCP routes provide a reusable connection that any action can leverage. Define the route once, use it everywhere.

Best Practices

  • Limit MCP access to specific topics and actions
  • Use authentication for MCP server connections
  • Monitor AI-initiated actions through logging
  • Implement rate limiting for AI requests
  • Configure appropriate timeouts for MCP operations
  • Limit concurrent AI sessions if needed
  • Monitor memory usage of MCP server processes
  • Implement graceful fallbacks when AI is unavailable
  • Log MCP communication errors for debugging
  • Set up alerts for repeated failures

Troubleshooting

  • Verify SERVER_COMMAND path is correct
  • Check SERVER_ARGUMENTS syntax (comma-separated)
  • Ensure required packages are installed (npx, node, python)
  • Check system PATH includes required executables
  • Verify MCP server is running and responsive
  • Check network/firewall settings
  • Increase timeout values if server startup is slow
  • Check server logs for errors
  • Verify the requested tool is available
  • Check permissions for the operation
  • Review server logs for detailed error messages
  • Ensure broker has required access rights

Next Steps