disconnect_g1_device
Terminate the active BLE connection to a G1 device, clean up resources, stop the heartbeat mechanism, and reset connection state. Returns disconnection status and device details.
Instructions
Disconnect from the current G1 device.
Returns:
Dict[str, Any]: JSON response with disconnection status including:
- result: "success" or "error"
- disconnected: Boolean indicating disconnection state
- device_name: Name of previously connected device (if successful)
- error: Error message if disconnection failed
Note:
This closes the BLE connection to the currently connected device,
cleans up resources, stops the heartbeat mechanism, and resets connection state.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"title": "disconnect_g1_deviceArguments",
"type": "object"
}
Implementation Reference
- mcp_server.py:187-224 (handler)Main tool handler for disconnect_g1_device. Validates connection, calls ble_manager.disconnect(), and returns status.@server.tool() async def disconnect_g1_device() -> Dict[str, Any]: """Disconnect from the current G1 device. Returns: Dict[str, Any]: JSON response with disconnection status including: - result: "success" or "error" - disconnected: Boolean indicating disconnection state - device_name: Name of previously connected device (if successful) - error: Error message if disconnection failed Note: This closes the BLE connection to the currently connected device, cleans up resources, stops the heartbeat mechanism, and resets connection state. """ if not ble_manager.is_connected: return { "result": "error", "disconnected": False, "error": "Not connected to any device" } device_name = ble_manager.target_device.name if ble_manager.target_device else "Unknown" try: await ble_manager.disconnect() return { "result": "success", "disconnected": True, "device_name": device_name } except Exception as e: logger.error(f"Disconnection failed: {e}") return { "result": "error", "disconnected": False, "error": f"Disconnection failed: {str(e)}" }
- g1_uart_manager.py:345-370 (helper)Core disconnect implementation in NordicBLEUARTManager class. Stops monitoring task, disconnects BLE client, and resets all connection state variables.async def disconnect(self): """Disconnect from the current device""" # Stop connection monitoring if self.connection_monitor_task: self.connection_monitor_task.cancel() self.connection_monitor_task = None if self.client and self.is_connected: try: await self.client.disconnect() logger.info("Disconnected from device") except Exception as e: logger.error(f"Error during disconnect: {e}") # Always clean up state self.is_connected = False self.client = None self.uart_service = None self.tx_characteristic = None self.rx_characteristic = None self.target_device = None self.connection_start_time = None self.last_activity_time = None self.last_heartbeat = None self.reconnect_attempts = 0
- mcp_server.py:187-187 (registration)@server.tool() decorator registers the disconnect_g1_device function with the FastMCP server.@server.tool()