Skip to content

Device Pairing

import { Aside, Tabs, TabItem } from ‘@astrojs/starlight/components’;

Pairing establishes a trusted relationship between devices, enabling secure communication. mcbluetooth includes a smart pairing agent that handles all Bluetooth pairing methods.

Before pairing, discover available devices:

bt_scan adapter="hci0" timeout=10 mode="both"

Scan modes:

  • classic — Traditional Bluetooth (BR/EDR)
  • ble — Bluetooth Low Energy only
  • both — Both types (default)
bt_pair adapter="hci0" address="AA:BB:CC:DD:EE:FF"
``` bt_pair adapter="hci0" address="..." pairing_mode="interactive" ```

Returns immediately with status. If confirmation needed, use bt_pair_confirm to respond.

bt_pair adapter="hci0" address="..." pairing_mode="auto"

Automatically accepts all pairing requests. Use only in trusted environments.

bt_pair adapter="hci0" address="..." pairing_mode="elicit"

Uses MCP elicitation to prompt the user directly (if the MCP client supports it).

Bluetooth uses different pairing methods based on device capabilities:

MethodDescriptionAgent Action
Just WorksNo user interactionAuto-accepted
Numeric ComparisonConfirm 6-digit code matchesShow code, await confirmation
Passkey EntryEnter code shown on other devicePrompt for passkey
Legacy PINEnter 4-6 digit PINPrompt for PIN

When pairing requires confirmation:

# Check for pending requests
bt_pairing_status
# Confirm with passkey (if needed)
bt_pair_confirm adapter="hci0" address="..." passkey=123456 accept=true
# Or reject
bt_pair_confirm adapter="hci0" address="..." accept=false
bt_list_devices adapter="hci0" filter="paired"
bt_unpair adapter="hci0" address="AA:BB:CC:DD:EE:FF"

This removes the device from known devices and deletes all pairing information.

bt_connect adapter="hci0" address="AA:BB:CC:DD:EE:FF"
bt_disconnect adapter="hci0" address="AA:BB:CC:DD:EE:FF"

Trusted devices can connect automatically without explicit authorization:

bt_trust adapter="hci0" address="..." trusted=true
bt_trust adapter="hci0" address="..." trusted=false

Prevent a device from connecting:

bt_block adapter="hci0" address="..." blocked=true
bt_block adapter="hci0" address="..." blocked=false
bt_device_info adapter="hci0" address="AA:BB:CC:DD:EE:FF"

Returns:

{
"address": "AA:BB:CC:DD:EE:FF",
"name": "Bose NCH700",
"alias": "My Headphones",
"paired": true,
"bonded": true,
"trusted": true,
"connected": true,
"uuids": ["0000110b-...", "0000110e-..."],
...
}
bt_device_set_alias adapter="hci0" address="..." alias="My Headphones"
# Put headphones in pairing mode first!
# Scan for them
bt_scan adapter="hci0" timeout=15
# Pair
bt_pair adapter="hci0" address="C8:7B:23:55:68:E8"
# Trust for auto-reconnect
bt_trust adapter="hci0" address="C8:7B:23:55:68:E8" trusted=true
# Connect
bt_connect adapter="hci0" address="C8:7B:23:55:68:E8"
# Scan and pair
bt_scan adapter="hci0"
bt_pair adapter="hci0" address="AA:BB:CC:DD:EE:FF"
# Both devices may show confirmation prompts - accept on both
# After pairing, OBEX profiles become available
bt_obex_status
  • Ensure the device is in pairing mode
  • Check device isn’t already paired (try bt_unpair first)
  • Verify adapter is powered and pairable
  • Device may have reached its pairing limit
  • Try resetting Bluetooth on the other device
  • Delete the pairing on both sides and retry
# Check for pending requests
bt_pairing_status
# Cancel if stuck
bt_pair_confirm adapter="hci0" address="..." accept=false
  • Profile incompatibility (e.g., device doesn’t support expected audio profile)
  • Check device UUIDs with bt_device_info
  • Try connecting specific profile with bt_connect_profile