Skip to content

The 9Mod MCPBoard uses the UART-MCP protocol for communication between the STM32 MCU and the Ai-WV01-32S AI module. This document describes the frame format, tool registration/call flow, and error codes.

TIP

For the complete UART-MCP protocol documentation, refer to UART-MCP Protocol and User Guide.


1. UART Configuration

ParameterValue
Baud Rate115200 (default, configurable 300~2000000)
Data Bits8
Stop Bits1
ParityNone
Frame Terminator\r\n (CR+LF)

WARNING

Every JSON command must end with \r\n, otherwise the AI module will not recognize it.


2. JSON Frame Format

2.1 Common Frame Structure

All messages are JSON-format with these top-level fields:

FieldTypeRequiredDescription
rolestringYesSender: "AI board" or "MCU"
msgTypestringYesMessage type (see below)
datastring/objectDependsMessage content

2.2 Message Types (msgType)

msgTypeDirectionDescription
statusAI → MCUStatus notification (startup, WiFi, wake, etc.)
mcp_setAI → MCUMCP control command (AI calls a tool)
mcp_checkAI → MCUMCP query command
MCP TextAI → MCUAI subtitle text
tool_listMCU → AIRegister MCP tool definitions
ctrl_resultMCU → AITool execution result
volumeBidirectionalVolume set/query
wake-upMCU → AIWake up AI module
uart_baudrateMCU → AIBaud rate change

3. AI Module → MCU Messages

3.1 Status Notifications

The AI module sends status changes to the MCU:

json
{"role":"AI board","msgType":"status","data":"<status info>"}

Common status values:

data valueDescription
AI StartAI device started
1.WiFi connect OKWiFi connected
2.WakeUPModule woken up
3.SleepModule sleeping
4.NetCFGNetwork configuration mode
5.NetERRNetwork error
6.OTAUPDATEOTA started
7.OTA OKOTA successful
8.OTA ERROTA failed
OKCommand executed successfully
ERROR:<message>Command execution failed

3.2 MCP Control Commands (Tool Call)

The AI module sends a tool call request:

json
{"role":"AI board","msgType":"mcp_set","tools":"<tool_name>","data":{"<param>":<value>}}

Example — AI calling the LED control tool:

json
{"role":"AI board","msgType":"mcp_set","tools":"led","data":{"enable":true}}

3.3 MCP Query Commands

The AI module queries a tool's status:

json
{"role":"AI board","msgType":"mcp_check","tools":"<tool_name>"}

Example — Query LED status:

json
{"role":"AI board","msgType":"mcp_check","tools":"led"}

3.4 Subtitle Text

AI responses are delivered as subtitle text, suitable for OLED display:

json
{"role":"AI board","msgType":"MCP Text","data":"The current temperature is 25.3°C"}

4. MCU → AI Module Messages

4.1 Registering MCP Tools

The MCU sends tool definitions to the AI module. Each tool includes a name, description, properties, and methods.

This is automatically handled by the emMCP library's emMCP_RegistrationTools() function. The underlying JSON format is:

json
<command_prefix>{"role":"MCU","msgType":"tool_list","data":[
  {
    "tool_name":"<tool_name>",
    "description":"<description>",
    "properties":{
      "<prop_name>":{"description":"<desc>","type":"<type>"}
    },
    "methods":{
      "<method_name>":{"description":"<desc>","parameters":{
        "<param_name>":{"description":"<desc>","type":"<type>","required":true}
      }}
    }
  }
]}

Restrictions

  • Tool names must not use Speaker or Light (system reserved)
  • Tool names should only contain [a-z0-9_]
  • Maximum number of tools configurable via MCP_SERVER_TOOL_NUMBLE_MAX (default: 4)

4.2 Tool Control Result

After executing the tool callback, the MCU returns the result to the AI:

json
{"role":"MCU","msgType":"ctrl_result","data":"<result JSON string>"}

Success example:

json
{"role":"MCU","msgType":"ctrl_result","data":"{\"result\":\"ok\"}"}

4.3 Tool Query Result

json
{"role":"MCU","msgType":"ctrl_result","data":"<query result JSON>"}

Example — Radar status query:

json
{"role":"MCU","msgType":"ctrl_result","data":"{\"detected\":true}"}

5. MCP Tool Registration and Call Flow

5.1 Tool Registration Flow

5.2 Tool Control Flow

5.3 Tool Query Flow


6. Error Codes

When the AI module detects a protocol error, it returns ERROR:<message>:

Error MessageDescriptionSeveritySolution
ERROR:Tools NULLTool list is empty🟢Create tools and call RegistrationTools
ERROR:Invalid JSON formatData is not valid JSON🔴Check JSON format
ERROR:Invalid roleMissing role field🔴Check JSON for "role"
ERROR:Invalid msgTypeMissing msgType field🔴Check JSON for "msgType"
ERROR:Invalid MCPMissing MCP keyword🔴Check JSON for "MCP"
ERROR:Invalid toolsMissing tools keyword🔴Check JSON for "tools"
ERROR:Invalid tool_nameMissing tool_name🔴Check JSON for "tool_name"
ERROR:tool_name already existsName conflict or reserved name🔴Change tool name, avoid Speaker/Light
ERROR:Failed to save toolsFailed to save tools🔴Restart module and re-register
ERROR:Failed to allocate memoryMemory allocation failed🔴Restart module
ERROR:Failed to parse toolsTool data not valid JSON🔴Check JSON format of tool definitions
ERROR:params is nullMCP command missing params🟡Ask AI to re-send the command
ERROR:tools call failedInternal tool retrieval failed🟡Ask AI to re-send the command
ERROR:TimeoutMCU did not respond in time🟡Ensure result is returned within 5 seconds

For the complete error code list, refer to UART-MCP Error Messages.


7. Data Flow Example: Complete Conversation

A complete voice-controlled LED on/off session:

[User]  → Voice →  "Turn on the LED"
[AI]    → UART → {"role":"AI board","msgType":"mcp_set","tools":"led","data":{"enable":true}}
[MCU]   → Internal →  Parse via emMCP → Call led.setRequestHandler
[MCU]   → GPIO →  HAL_GPIO_WritePin(PC13, SET)
[MCU]   → UART → {"role":"MCU","msgType":"ctrl_result","data":"{\"result\":\"ok\"}"}
[AI]    → Voice →  "LED turned on"

Further Reading

Released under the MIT License.