connect_ur
Establish a connection to UR robots by providing their IP address. Enables remote control and interaction with collaborative industrial robots via the nUR MCP Server, simplifying robot management through natural language commands.
Instructions
根据用户提供的IP连接UR IP:机器人地址
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes |
Implementation Reference
- The core handler function for the 'connect_ur' MCP tool. It establishes a connection to a Universal Robots (UR) robot using the URBasic library, initializes the robot model and script extension, verifies RTDE connection and remote control mode, and manages global robot_list and robotModle_list dictionaries.@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}") robot_list[ip].robotConnector.DashboardClient.ur_is_remote_control() remote = robot_list[ip].robotConnector.DashboardClient.last_respond.lower() print(f"remote:{remote}") if remote != 'true' and not remote.startswith('could not understand'): disconnect_ur(ip) return return_msg(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:147-147 (registration)The @mcp.tool() decorator registers the connect_ur function as an MCP tool.@mcp.tool()
- Helper function link_check that calls connect_ur if the robot connection is not active.def link_check(ip): """检查连接状态,若连接断开或不存在,则建立连接""" if robot_list.get(ip, "unknown") == "unknown" or not robot_list[ ip].robotConnector.RTDE.isRunning(): return connect_ur(ip) return '连接成功'