SMP版本(3.13.1)上使用自定义MCP工具

更新时间:2025-12-17 10:07:41下载pdf

1.添加工具信息与描述

// robot move forward/backward tool
TUYA_CALL_ERR_GOTO(WUKONG_MCP_TOOL_ADD(
"device.robot.move",
"Controls the robot to move forward or backward. "
"This tool can be triggered by natural language commands such as: "
"'往前走' (move forward), '往后退' (move backward), "
"'向前' (forward), '向后' (backward), '前进' (advance), '后退' (go back), "
"'往前' (go forward), '往后' (go backward).\n"
"Parameters:\n"
"- direction (string): The direction to move. "
"Accepts 'forward' or 'backward' (English), or natural language commands like "
"'往前走', '往后退', '向前', '向后', '前进', '后退', '往前', '往后'. "
"The tool will automatically map natural language to 'forward' or 'backward'.\n"
"Response:\n"
"- Returns true if the robot successfully moved in the requested direction.",
swimming_robot_move,
NULL,
MCP_PROP_STR("direction", "The direction to move. Accepts 'forward'/'backward' or natural language like '往前走'/'往后退'/'向前'/'向后'/'前进'/'后退'.")), err)

2.编写回调函数

STATIC OPERATE_RET swimming_robot_move(CONST MCP_PROPERTY_LIST_T *properties, MCP_RETURN_VALUE_T 
{
    OPERATE_RET rt = OPRT_OK;
    TAL_PR_DEBUG("swimming robot move start \r\n");

    // Parse properties to get direction
    for (INT_T i = 0; i < properties->count; i++) 
	{
        MCP_PROPERTY_T *prop = properties->properties[i];
		TAL_PR_DEBUG("swimming move[%d]: name = %s,type = %d, description = %s, has_default = %d\r\n",i,prop->name,prop->type,prop->description,prop->has_default);
    }

    return OPRT_OK;
}

3.对开发板说:往前走,然后看回调有没有打印LOG

[12-17 17:39:48 ty D][449][tuya_ai_toy_mcp.c:149] swimming robot move start

[12-17 17:39:48 ty D][449][tuya_ai_toy_mcp.c:155] swimming move[0]: name = direction,type = 2, description = The direction to move. Accepts ‘forward’/‘backward’ or natural language like ‘往前走’/‘往后退’/‘向前’/‘向后’/‘前进’/‘后退’., has_default = 1