Skip to content

Commit 59be80c

Browse files
committed
Accept string-typed boolean parameters ("true" instead of true).
1 parent 18ab747 commit 59be80c

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.1.3
4+
5+
### Fixed
6+
- Accept string-typed boolean parameters (`"true"` instead of `true`). Affected fields: `pair`, `with_response`.
7+
38
## 0.1.2
49

510
### Fixed

ble_mcp_server/handlers_ble.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from mcp.types import Tool
1111

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
1313
from ble_mcp_server.state import BleState, Subscription, check_allowlist, normalize_uuid
1414

1515
logger = logging.getLogger("ble_mcp_server")
@@ -128,7 +128,7 @@ def _decode_value(args: dict[str, Any]) -> bytes | dict[str, Any]:
128128
"default": 10,
129129
},
130130
"pair": {
131-
"type": "boolean",
131+
"type": ["boolean", "string"],
132132
"description": "Pair (bond) during connect. Works on Linux and Windows, not macOS.",
133133
"default": False,
134134
},
@@ -220,7 +220,7 @@ def _decode_value(args: dict[str, Any]) -> bytes | dict[str, Any]:
220220
"value_b64": {"type": "string", "description": "Base64-encoded value to write."},
221221
"value_hex": {"type": "string", "description": "Hex-encoded value to write."},
222222
"with_response": {
223-
"type": "boolean",
223+
"type": ["boolean", "string"],
224224
"description": "Use write-with-response (default true).",
225225
"default": True,
226226
},
@@ -396,7 +396,7 @@ async def handle_scan_stop(state: BleState, args: dict[str, Any]) -> dict[str, A
396396
async def handle_connect(state: BleState, args: dict[str, Any]) -> dict[str, Any]:
397397
address = args["address"]
398398
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))
400400

401401
entry = state.create_client(address, timeout, pair=pair)
402402
client = entry.client
@@ -547,7 +547,7 @@ async def handle_write(state: BleState, args: dict[str, Any]) -> dict[str, Any]:
547547
return result
548548
data = result
549549

550-
with_response = args.get("with_response", True)
550+
with_response = _coerce_bool(args.get("with_response", True))
551551
await _retry(lambda: entry.client.write_gatt_char(char_uuid, data, response=with_response))
552552
return _ok()
553553

ble_mcp_server/helpers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
# ---------------------------------------------------------------------------
3838

3939

40+
def _coerce_bool(value: Any) -> bool:
41+
"""Coerce a value to bool, handling string representations."""
42+
if isinstance(value, str):
43+
return value.lower() not in ("false", "0", "")
44+
return bool(value)
45+
46+
4047
def _ok(**kwargs: Any) -> dict[str, Any]:
4148
return {"ok": True, **kwargs}
4249

server.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"url": "https://github.com/es617/ble-mcp-server.git",
77
"source": "github"
88
},
9-
"version": "0.1.2",
9+
"version": "0.1.3",
1010
"packages": [
1111
{
1212
"registryType": "pypi",
1313
"identifier": "ble-mcp-server",
14-
"version": "0.1.2",
14+
"version": "0.1.3",
1515
"transport": {
1616
"type": "stdio"
1717
},

0 commit comments

Comments
 (0)