get_time
Retrieves the uptime in seconds of a Universal Robots cobot by providing its IP address. Helps monitor robot runtime without teach pendant.
Instructions
根据用户提供的IP,获取指定机器人的开机时长(秒) IP:机器人地址
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes |
Implementation Reference
- The MCP tool handler function for 'get_time'. It takes an IP address, checks connection, and returns the robot's uptime in seconds by calling robotModle_list[ip].RobotTimestamp().
@mcp.tool() def get_time(ip: str) -> str: """根据用户提供的IP,获取指定机器人的开机时长(秒) IP:机器人地址""" try: if '连接成功' not in link_check(ip): return return_msg(f"与机器人的连接已断开。IP:{ip}") logger.info(f"{robotModle_list[ip].RobotTimestamp():.2f}") return return_msg(f"{robotModle_list[ip].RobotTimestamp():.2f}") except Exception as e: logger.error(f"获取开机时长失败: {str(e)}") return return_msg(f"获取开机时长失败: {str(e)}") - src/nonead_universal_robots_mcp/server.py:246-246 (registration)The tool is registered via the @mcp.tool() decorator, where 'mcp' is a FastMCP instance from the MCP framework.
@mcp.tool() - URBasic/robotModel.py:140-141 (helper)The RobotTimestamp() method on RobotModel class returns the 'timestamp' value from self.dataDir dictionary, which represents robot uptime.
def RobotTimestamp(self): return self.dataDir['timestamp'] - The return_msg helper function that wraps the result string in a JSON response.
def return_msg(txt: str): return json.dumps(txt, indent=2, ensure_ascii=False) - The link_check helper function that verifies the robot connection is active before executing the tool.
def link_check(ip): """检查连接状态,若连接断开或不存在,则建立连接""" if robot_list.get(ip, "unknown") == "unknown" or not robot_list[ ip].robotConnector.RTDE.isRunning(): return connect_ur(ip) return '连接成功'