BLE MCP Server 标志

BLE MCP Server

社区
es617

Bluetooth Low Energy (BLE) MCP server for Claude Code and other MCP-compatible agents.

发布者es617
代码仓库ble-mcp-server
语言Python
复刻数
2
星标数
18
可用工具
0
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    BLE MCP Server 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 18 个星标和 2 个复刻。

BLE MCP Server

MCP License: MIT Python BLE

A stateful Bluetooth Low Energy (BLE) Model Context Protocol (MCP) server for developer tooling and AI agents. Works out of the box with Claude Code, VS Code with Copilot, and any MCP-compatible runtime. Defaults to stdio (no HTTP, no open ports), with optional SSE and Streamable HTTP transports for remote access and multi-session use. Uses bleak for cross-platform BLE on macOS, Windows, and Linux.

Example: Let Claude Code scan for nearby BLE devices, connect to one, read characteristics, and stream notifications from real hardware.

Demo

7-minute video walkthrough — scanning a real BLE device, discovering services, reading values, and promoting flows into plugins.


Why this exists

You have a BLE device. You want an AI agent to talk to it — scan, connect, read sensors, send commands, stream data. This server makes that possible.

It gives any MCP-compatible agent a full set of BLE tools: scanning, connecting, reading, writing, subscribing to notifications — plus protocol specs and device plugins, so the agent can reason about higher-level device behavior instead of just raw UUIDs and bytes.

The agent calls these tools, gets structured JSON back, and reasons about what to do next — no human in the loop for each BLE operation.

What agents can do with it:

  • Develop and debug — connect to your device, explore its services, read characteristics, test commands, and diagnose issues conversationally. "Why is this sensor returning zeros?" becomes a question you can ask.
  • Iterate on new hardware — building a BLE device? Attach a protocol spec so the agent understands your commands and data formats as you evolve them.
  • Automate testing — write device-specific plugins that expose high-level actions (e.g., device.start_stream, device.run_self_test), then let the agent run test sequences: enable a sensor, collect samples, validate values, report results.
  • Explore — point the agent at a device you’ve never seen. It discovers services, probes characteristics, and builds up protocol documentation from scratch.
  • Build BLE automation — agents controlling real hardware for real tasks: reading environmental sensors on a schedule, managing a fleet of BLE beacons, triggering actuators based on conditions.

Who is this for?

  • Embedded engineers — faster iteration on BLE protocols, conversational debugging, automated test sequences
  • Hobbyists and makers — explore BLE devices without writing boilerplate; let the agent help reverse-engineer simple protocols
  • QA and test engineers — build repeatable BLE test suites with plugin tools, run them from CI or agent sessions
  • Support and field engineers — diagnose BLE device issues interactively without specialized tooling
  • Researchers — automate data collection from BLE sensors, explore device capabilities systematically

Quickstart (Claude Code)

bash
pip install ble-mcp-server

# Register the MCP server with Claude Code (read-only by default)
claude mcp add ble -- ble_mcp

Then in Claude Code, try:

"Scan for nearby BLE devices and connect to the one whose name starts with Arduino."

The server is read-only by default. Writes and plugins can control real hardware and execute code, and are opt-in via environment variables. See Safety for details.


What the agent can do

Once connected, the agent has full BLE capabilities:

  • Scan for nearby devices, with optional name or service UUID filters
  • Connect to a device and discover its services and characteristics
  • Read and write characteristic values (writes require BLE_MCP_ALLOW_WRITES)
  • Subscribe to notifications and collect streaming data — single events, polling, or batch draining
  • Attach protocol specs to understand device-specific commands and data formats
  • Use plugins for high-level device operations (e.g., sensortag.read_temp) instead of raw reads/writes
  • Create specs and plugins for new devices, building up reusable knowledge across sessions

The agent handles multi-step flows automatically. For example, "read the temperature from my SensorTag" might involve scanning, connecting, discovering services, attaching a spec, enabling the sensor, and reading the value — without you specifying each step.

At a high level:

Raw BLE → Protocol Spec → Plugin

You can start with raw BLE tools, then move up the stack as your device protocol becomes understood and repeatable. See Concepts for how the pieces fit together.


Install (development)

bash
# Editable install from repo root
pip install -e .

# Or with uv
uv pip install -e .

MCP is a protocol — this server works with any MCP-compatible client. Below are setup instructions for the most common ones.

Add to Claude Code

bash
# Minimal (read-only)
claude mcp add ble -- ble_mcp

# Or run as a module
claude mcp add ble -- python -m ble_mcp_server

# Enable writes
claude mcp add ble -e BLE_MCP_ALLOW_WRITES=true -- ble_mcp

# Enable writes with an allowlist of characteristic UUIDs
claude mcp add ble \
  -e BLE_MCP_ALLOW_WRITES=true \
  -e BLE_MCP_WRITE_ALLOWLIST="2a00,12345678-1234-1234-1234-123456789abc" \
  -- ble_mcp

# Enable all plugins
claude mcp add ble -e BLE_MCP_PLUGINS=all -- ble_mcp

# Enable specific plugins only
claude mcp add ble -e BLE_MCP_PLUGINS=sensortag,hello -- ble_mcp

# Debug logging
claude mcp add ble -e BLE_MCP_LOG_LEVEL=DEBUG -- ble_mcp

Add to VS Code / Copilot

Add to your project's .vscode/mcp.json (or create it):

json
{
  "servers": {
    "ble": {
      "type": "stdio",
      "command": "ble_mcp",
      "args": [],
      "env": {
        "BLE_MCP_ALLOW_WRITES": "true",
        "BLE_MCP_PLUGINS": "all"
      }
    }
  }
}

Adjust env to match your needs — remove BLE_MCP_ALLOW_WRITES for read-only mode, or set BLE_MCP_PLUGINS to specific plugin names.

Add to Cursor

Add to your project's .cursor/mcp.json (or create it):

json
{
  "mcpServers": {
    "ble": {
      "command": "ble_mcp",
      "args": [],
      "env": {
        "BLE_MCP_ALLOW_WRITES": "true",
        "BLE_MCP_PLUGINS": "all"
      }
    }
  }
}

Environment variables

VariableDefaultDescription
BLE_MCP_ALLOW_WRITESdisabledSet to true, 1, or yes to enable ble.write.
BLE_MCP_WRITE_ALLOWLISTemptyComma-separated UUID allowlist for writable characteristics (checked only when writes are enabled).
BLE_MCP_PLUGINSdisabledPlugin policy: all to allow all, or name1,name2 to allow specific plugins. Unset = disabled.
BLE_MCP_LOG_LEVELWARNINGPython log level (DEBUG, INFO, WARNING, ERROR). Logs go to stderr.
BLE_MCP_TRACEenabledJSONL tracing of every tool call. Set to 0, false, or no to disable.
BLE_MCP_TRACE_PAYLOADSdisabledInclude value_b64/value_hex in traced args (stripped by default).
BLE_MCP_TRACE_MAX_BYTES16384Max payload chars before truncation (only applies when TRACE_PAYLOADS is on).
BLE_MCP_TOOL_SEPARATOR_Character used to separate tool name segments. Set to . if your client supports dots in tool names. Default changed to _ because most clients (Cursor, Claude Desktop) reject dots.
BLE_MCP_MAX_SESSIONS1Maximum concurrent MCP sessions (only meaningful for SSE and Streamable HTTP transports).
BLE_MCP_MAX_CONNECTIONS3Maximum active BLE connections per session.
BLE_MCP_MAX_SCANS5Maximum active scans per session.
BLE_MCP_MAX_SUBSCRIPTIONS_PER_CONN10Maximum notification subscriptions per connection.
BLE_MCP_AUTH_TOKENunsetPassword for OAuth approval page on HTTP transports. Required unless --no-auth is used. Ignored for stdio.

Tools

See Concepts for how everything fits together, and the Tools Reference for detailed input/output schemas.

CategoryTools
BLE Coreble_scan_start, ble_scan_get_results, ble_scan_stop, ble_connect, ble_disconnect, ble_connection_status, ble_discover, ble_mtu, ble_read, ble_write, ble_read_descriptor, ble_write_descriptor, ble_subscribe, ble_unsubscribe, ble_wait_notification, ble_poll_notifications, ble_drain_notifications
Introspectionble_connections_list, ble_subscriptions_list, ble_scans_list, ble_tasks_list, ble_tasks_cancel
Protocol Specsble_spec_template, ble_spec_register, ble_spec_list, ble_spec_attach, ble_spec_get, ble_spec_read, ble_spec_search
Tracingble_trace_status, ble_trace_tail
Pluginsble_plugin_template, ble_plugin_list, ble_plugin_reload, ble_plugin_load

Protocol Specs

Specs are markdown files that describe a BLE device's protocol — services, characteristics, commands, and data formats. They live in .ble_mcp/specs/ and teach the agent what a device can do beyond raw UUIDs and bytes.

Without a spec, the agent can still discover services and read characteristics. With a spec, it knows what the values mean and what commands to send.

You can create specs by telling the agent about your device — paste a datasheet, describe the protocol, or just let it explore and document what it finds. The agent generates the spec file, registers it, and references it in future sessions. You can also write specs by hand.

See Concepts for details on spec format and how the agent uses them.


Plugins

Plugins add device-specific shortcut tools to the server. Instead of the agent composing raw read/write sequences, a plugin provides high-level operations like sensortag.read_temp or ota.upload_firmware.

The agent can also create plugins (with your approval). It explores a device, writes a plugin based on what it learns, and future sessions get shortcut tools — no manual coding required.

To enable plugins:

bash
# Enable all plugins
claude mcp add ble -e BLE_MCP_PLUGINS=all -- ble_mcp

# Enable specific plugins only
claude mcp add ble -e BLE_MCP_PLUGINS=sensortag,ota -- ble_mcp

Editing an already-loaded plugin only requires ble_plugin_reload — no restart needed.

Background tasks

Plugins can start background asyncio tasks for continuous monitoring — periodic scans, data collection loops, etc. The plugin template includes commented examples for this pattern.

Background tasks are registered with the server via state.register_task(name, task), making them visible to the agent:

  • ble_tasks_list — shows all running background tasks with status
  • ble_tasks_cancel — stops a task by ID (safety net for runaway tasks)

Plugin notifications

Plugins can send MCP log notifications to the client via state.on_log_cb(level, message). This allows plugins to proactively alert the agent about events — device arrival, threshold crossed, anomaly detected — without waiting for a tool call.

See Concepts for the plugin contract, metadata matching, and how specs and plugins work together.


Tracing

Every tool call is traced to .ble_mcp/traces/trace.jsonl and an in-memory ring buffer (last 2000 events). Tracing is on by default — set BLE_MCP_TRACE=0 to disable.

Event format

Two events per tool call:

jsonl
{"ts":"2025-01-01T00:00:00.000Z","event":"tool_call_start","tool":"ble.read","args":{"connection_id":"c1","char_uuid":"2a00"},"connection_id":"c1"}
{"ts":"2025-01-01T00:00:00.050Z","event":"tool_call_end","tool":"ble.read","ok":true,"error_code":null,"duration_ms":50,"connection_id":"c1"}
  • connection_id is extracted from args when present
  • value_b64 and value_hex are stripped from traced args by default (enable with BLE_MCP_TRACE_PAYLOADS=1)

Inspecting the trace

Use ble.trace.status to check config and event count, and ble.trace.tail to retrieve recent events — no need to read the file directly.


Platform BLE permissions

macOS

No special setup is needed for most cases. On macOS 12+, the Terminal app (or whichever terminal you use) must have Bluetooth permission. Go to System Settings > Privacy & Security > Bluetooth and ensure your terminal is listed and enabled. If running from an IDE, the IDE itself may need the permission.

Windows

Requires Windows 10 version 1709 (Fall Creators Update) or later. No extra drivers needed — bleak uses the native WinRT Bluetooth APIs. Just make sure Bluetooth is turned on in Settings.

Linux

Requires BlueZ 5.43+. Your user must have permission to access the D-Bus Bluetooth interface. The simplest approach:

bash
# Add your user to the bluetooth group
sudo usermod -aG bluetooth $USER
# Then log out and back in

If you are running in a container or headless environment, ensure dbus and bluetoothd are running.


Example session

The repo includes a simulated BLE peripheral you can run on a second machine (e.g. a Raspberry Pi) to try things end-to-end — no real hardware needed. See examples/demo-device/ for setup.

"Scan for BLE devices and connect to DemoDevice. Read the battery level, then start a data collection."

The agent will:

  1. Scan for nearby devices and find DemoDevice
  2. Connect and discover its services
  3. Check for a matching protocol spec — if one exists, attach it to understand the device's protocol
  4. Check for a matching plugin — if one exists, use its shortcut tools
  5. If no spec or plugin exists, explore the device using raw BLE tools, or ask you for guidance
  6. Read the battery level, configure the data service, and start collection

The example includes a pre-built protocol spec and plugin — copy them into .ble_mcp/specs/ and .ble_mcp/plugins/ to skip the exploration phase, or let the agent create its own from scratch.


Try without an agent

You can test the server interactively using the MCP Inspector — no Claude or other agent needed:

bash
npx @modelcontextprotocol/inspector python -m ble_mcp_server

Open the URL with the auth token from the terminal output. The Inspector gives you a web UI to call any tool, see responses, and observe MCP notifications (like disconnect alerts) in real time.


Transports

The server supports three MCP transports. stdio is the default and recommended for most use cases — zero configuration, no network exposure. HTTP transports are available for remote access and multi-client scenarios.

TransportCommandSessionsUse case
stdio (default)ble_mcpSingleCLI tools, IDE integrations
SSEble_mcp --transport sseMultipleOlder MCP clients, web-based tools
Streamable HTTPble_mcp --transport streamable-httpMultipleNewer MCP clients, production deployments

HTTP transport options

bash
# SSE on default port (OAuth enabled by default)
ble_mcp --transport sse

# Streamable HTTP on custom host/port
ble_mcp --transport streamable-http --host 0.0.0.0 --port 9000

# No auth (for local testing with MCP Inspector, etc.)
ble_mcp --transport streamable-http --no-auth

# Allow up to 3 concurrent sessions
BLE_MCP_MAX_SESSIONS=3 ble_mcp --transport streamable-http

For SSE, clients connect via GET /sse and post messages to /messages/. For Streamable HTTP, the endpoint is /mcp.

Session isolation: each MCP session gets its own BLE state — connections, scans, and subscriptions are not shared between sessions. Two sessions can independently scan or connect to the same device (if the BLE hardware and device allow it).

Authentication

HTTP transports require BLE_MCP_AUTH_TOKEN to be set. This token serves as the password for the OAuth 2.0 approval page — when a client connects, it goes through the standard OAuth flow and the user must enter this password to approve access.

bash
# Set a password and start the server
BLE_MCP_AUTH_TOKEN=mysecret ble_mcp --transport streamable-http

The OAuth flow (handled automatically by Claude Desktop and other MCP clients):

  1. Client discovers the server's OAuth metadata at /.well-known/oauth-authorization-server
  2. Client registers itself via dynamic client registration (/register)
  3. User is redirected to an approval page where they enter the BLE_MCP_AUTH_TOKEN password
  4. Client exchanges the authorization code for access/refresh tokens

All OAuth state (clients, tokens) is stored in memory and lost on restart — clients simply re-authenticate.

Claude Desktop setup (remote via tunnel):

bash
# Terminal 1: start the server
BLE_MCP_AUTH_TOKEN=mysecret ble_mcp --transport streamable-http --host 0.0.0.0

# Terminal 2: expose via cloudflared
cloudflared tunnel --url http://localhost:8000

In Claude Desktop, add a remote MCP server with the tunnel URL + /mcp path (e.g. https://abc123.trycloudflare.com/mcp). Claude Desktop handles the OAuth flow — you just enter the password when prompted.

No auth (local testing only):

For local testing with MCP Inspector or similar tools, you can disable auth entirely:

bash
ble_mcp --transport streamable-http --no-auth

Without BLE_MCP_AUTH_TOKEN or --no-auth, the server refuses to start on HTTP transports.

stdio transport ignores all auth settings — it doesn't need auth because the client launches the server as a subprocess.

Note: uvicorn and starlette are required for HTTP transports. They are already transitive dependencies of the mcp package, but you can install them explicitly with pip install ble-mcp-server[http].


Architecture

  • Multiple transports — stdio (default), SSE, and Streamable HTTP
  • Per-session isolation — each MCP session gets its own BLE state
  • Stateful — connections and subscriptions persist in memory
  • Safe by default — writes gated by env flags + allowlist
  • Agent-friendly — structured outputs, buffered notifications
  • Graceful shutdown — disconnects all clients on exit

Known limitations

  • Real hardware is asynchronous; agent runtimes mostly aren't. Devices disconnect, notifications arrive out of band, and state changes while the agent is thinking. Most agent runtimes are optimized for clean request/response loops. The server bridges this with polling tools, buffered notification queues, and MCP log notifications for disconnects, incoming data, and scan results — but MCP log notifications are client-dependent (they work in MCP Inspector; Claude Code and Claude Desktop currently ignore them). The agent can always detect disconnects on the next tool call and poll for notifications explicitly — the log messages are a best-effort heads-up, not a guarantee. Custom MCP clients (e.g., an edge agent using the MCP SDK directly) can receive and act on these notifications.

  • stdio is single-session. The stdio transport handles one MCP session at a time. For multi-session use, switch to SSE or Streamable HTTP transport with --transport sse or --transport streamable-http.


Safety

This server connects an AI agent to real hardware. That's the point — and it means the stakes are higher than pure-software tools.

Plugins execute arbitrary code. When plugins are enabled, the agent can create and run Python code on your machine with full server privileges. Review agent-generated plugins before loading them. Use BLE_MCP_PLUGINS=name1,name2 to allow only specific plugins rather than all.

Writes affect real devices. A bad write to the wrong characteristic can brick a device, trigger unintended behavior, or disrupt other connected systems. Keep writes disabled unless you need them. Use BLE_MCP_WRITE_ALLOWLIST to restrict which characteristics are writable.

Use tool approval deliberately. When your MCP client prompts you to approve a tool call, consider whether you want to allow it once or always. "Always allow" is convenient but means the agent can repeat that action without further confirmation.

This software is provided as-is under the MIT license. You are responsible for what the agent does with your hardware.


License

This project is licensed under the MIT License — see LICENSE for details.

Acknowledgements

This project is built on top of the excellent bleak library for cross-platform BLE in Python.

安装

TypingMind
前提条件:

Node.js 18+

{
  "mcpServers": {
    "es617-ble-mcp-server": {
      "command": "uvx",
      "args": [
        "ble-mcp-server"
      ]
    }
  }
}

将 BLE MCP Server MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 BLE MCP Server 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请勿关闭终端窗口或停止其中的连接器进程。
3

将 BLE MCP Server 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 BLE MCP Server MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "es617-ble-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "ble-mcp-server"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 BLE MCP Server MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 BLE MCP Server MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 BLE MCP Server 帮我完成这项任务吗?
BLE MCP Server
当然,我看过了。
以下是我使用 BLE MCP Server 得到的结果。

常见问题

BLE MCP Server MCP 服务器有什么用途?

BLE MCP Server 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 BLE MCP Server MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您无需为每个模型单独配置 MCP 服务器,就能在 Claude、ChatGPT、Gemini 或您在 TypingMind 中配置的其他 AI 模型中使用 BLE MCP Server。

为什么在 TypingMind 中使用 BLE MCP Server MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是最出色的大语言模型聊天前端之一。连接 BLE MCP Server 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 BLE MCP Server MCP 连接到 TypingMind?

BLE MCP Server 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

BLE MCP Server MCP 在 TypingMind 中提供哪些工具?

BLE MCP Server 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 BLE MCP Server MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行选择模型提供商,并自行管理 API 密钥、提示词和 MCP 配置。如果 BLE MCP Server 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇