connect_ur
Connect to Universal Robots collaborative robots by providing the robot's IP address to enable motion control, status monitoring, and program execution.
Instructions
根据用户提供的IP连接UR IP:机器人地址
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes |
Implementation Reference
- The handler function for the 'connect_ur' MCP tool. It connects to a Universal Robots robot at the specified IP using the URBasic library, manages global robot lists, checks RTDE connection status, and returns success or failure messages.@mcp.tool() def connect_ur(ip: str): """根据用户提供的IP连接UR IP:机器人地址""" try: host = ip global robot_list, robotModle_list if robot_list.get(ip, "unknown") != "unknown": robot_list[ip].robotConnector.close() return return_msg(f"优傲机器人连接失败: {ip}") robotModle = URBasic.robotModel.RobotModel() robot = URBasic.urScriptExt.UrScriptExt(host=host, robotModel=robotModle) robot_list[ip] = robot robotModle_list[ip] = robotModle if robot_list.get(ip, "unknown") == "unknown" or not robot_list[ ip].robotConnector.RTDE.isRunning(): return return_msg(f"优傲机器人连接失败: {ip}") logger.info(f"连接成功。IP:{host}") return return_msg(f"连接成功。IP:{host}") except Exception as e: logger.error(f"优傲机器人连接失败: {str(e)}") return return_msg(f"优傲机器人连接失败: {str(e)}")
- src/nonead_universal_robots_mcp/server.py:187-213 (registration)The @mcp.tool() decorator registers the connect_ur function as an MCP tool.@mcp.tool() def connect_ur(ip: str): """根据用户提供的IP连接UR IP:机器人地址""" try: host = ip global robot_list, robotModle_list if robot_list.get(ip, "unknown") != "unknown": robot_list[ip].robotConnector.close() return return_msg(f"优傲机器人连接失败: {ip}") robotModle = URBasic.robotModel.RobotModel() robot = URBasic.urScriptExt.UrScriptExt(host=host, robotModel=robotModle) robot_list[ip] = robot robotModle_list[ip] = robotModle if robot_list.get(ip, "unknown") == "unknown" or not robot_list[ ip].robotConnector.RTDE.isRunning(): return return_msg(f"优傲机器人连接失败: {ip}") logger.info(f"连接成功。IP:{host}") return return_msg(f"连接成功。IP:{host}") except Exception as e: logger.error(f"优傲机器人连接失败: {str(e)}") return return_msg(f"优傲机器人连接失败: {str(e)}")
- Helper function link_check that invokes connect_ur when robot connection is missing or inactive.def link_check(ip): """检查连接状态,若连接断开或不存在,则建立连接""" if robot_list.get(ip, "unknown") == "unknown" or not robot_list[ ip].robotConnector.RTDE.isRunning(): return connect_ur(ip) return '连接成功'
- Input schema defined by type hint ip: str and docstring describing the IP parameter.def connect_ur(ip: str): """根据用户提供的IP连接UR IP:机器人地址"""