get_serial_number
Retrieves the serial number of a Universal Robots cobot by providing its IP address.
Instructions
获取指定IP机器人的序列号 IP:机器人地址
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes |
Implementation Reference
- The handler function that executes the 'get_serial_number' tool logic. It checks connection via link_check, then calls ur_serial_number() on the DashboardClient and returns the result.
@mcp.tool() def get_serial_number(ip: str): """获取指定IP机器人的序列号 IP:机器人地址""" try: if '连接失败' in link_check(ip): return return_msg(f"与机器人的连接已断开。") robot_list[ip].robotConnector.DashboardClient.ur_serial_number() logger.info(f"IP为{ip}的优傲机器人的序列号为: {robot_list[ip].robotConnector.DashboardClient.last_respond}") return return_msg( f"IP为{ip}的优傲机器人的序列号为: {robot_list[ip].robotConnector.DashboardClient.last_respond}") except Exception as e: logger.error(f"获取序列号失败: {str(e)}") return return_msg(f"获取序列号失败: {str(e)}") - src/nonead_universal_robots_mcp/server.py:230-231 (registration)The @mcp.tool() decorator registers this function as an MCP tool named 'get_serial_number'.
@mcp.tool() def get_serial_number(ip: str): - Helper function used by get_serial_number to format return messages as JSON strings.
def return_msg(txt: str): return json.dumps(txt, indent=2, ensure_ascii=False) - Helper function used by get_serial_number to verify/establish a connection to the robot.
def link_check(ip): """检查连接状态,若连接断开或不存在,则建立连接""" if robot_list.get(ip, "unknown") == "unknown" or not robot_list[ ip].robotConnector.RTDE.isRunning(): return connect_ur(ip) return '连接成功'