|
9 | 9 |
|
10 | 10 | from mcp.types import Tool |
11 | 11 |
|
12 | | -from ble_mcp_server.helpers import ALLOW_WRITES, WRITE_ALLOWLIST, _err, _ok, _retry |
| 12 | +from ble_mcp_server.helpers import ALLOW_WRITES, WRITE_ALLOWLIST, _coerce_bool, _err, _ok, _retry |
13 | 13 | from ble_mcp_server.state import BleState, Subscription, check_allowlist, normalize_uuid |
14 | 14 |
|
15 | 15 | logger = logging.getLogger("ble_mcp_server") |
@@ -128,7 +128,7 @@ def _decode_value(args: dict[str, Any]) -> bytes | dict[str, Any]: |
128 | 128 | "default": 10, |
129 | 129 | }, |
130 | 130 | "pair": { |
131 | | - "type": "boolean", |
| 131 | + "type": ["boolean", "string"], |
132 | 132 | "description": "Pair (bond) during connect. Works on Linux and Windows, not macOS.", |
133 | 133 | "default": False, |
134 | 134 | }, |
@@ -220,7 +220,7 @@ def _decode_value(args: dict[str, Any]) -> bytes | dict[str, Any]: |
220 | 220 | "value_b64": {"type": "string", "description": "Base64-encoded value to write."}, |
221 | 221 | "value_hex": {"type": "string", "description": "Hex-encoded value to write."}, |
222 | 222 | "with_response": { |
223 | | - "type": "boolean", |
| 223 | + "type": ["boolean", "string"], |
224 | 224 | "description": "Use write-with-response (default true).", |
225 | 225 | "default": True, |
226 | 226 | }, |
@@ -396,7 +396,7 @@ async def handle_scan_stop(state: BleState, args: dict[str, Any]) -> dict[str, A |
396 | 396 | async def handle_connect(state: BleState, args: dict[str, Any]) -> dict[str, Any]: |
397 | 397 | address = args["address"] |
398 | 398 | timeout = _clamp(float(args.get("timeout_s", 10)), 1, 60) |
399 | | - pair = bool(args.get("pair", False)) |
| 399 | + pair = _coerce_bool(args.get("pair", False)) |
400 | 400 |
|
401 | 401 | entry = state.create_client(address, timeout, pair=pair) |
402 | 402 | client = entry.client |
@@ -547,7 +547,7 @@ async def handle_write(state: BleState, args: dict[str, Any]) -> dict[str, Any]: |
547 | 547 | return result |
548 | 548 | data = result |
549 | 549 |
|
550 | | - with_response = args.get("with_response", True) |
| 550 | + with_response = _coerce_bool(args.get("with_response", True)) |
551 | 551 | await _retry(lambda: entry.client.write_gatt_char(char_uuid, data, response=with_response)) |
552 | 552 | return _ok() |
553 | 553 |
|
|
0 commit comments