Skip to main content
Glama
dglab-mcp

dglab-mcp

by zakotoys

@zakotoys/dglab-mcp

npm CI codecov License: GPL-3.0

English | 简体中文 | 日本語

一个以安全为先的 Model Context Protocol 服务器,用于 DG-LAB Coyote V2/V3 硬件。它通过本地 stdio 进程将 Claude Desktop、Cursor、OpenCode、Codex 或任何 MCP 客户端连接到 DG-LAB 4 V4 WebSocket 中继。

安全第一

本软件控制的是向人体传递真实电刺激的设备。请仅在知情同意、有真人监督且实体设备触手可及的情况下使用。

  • 默认上限:30/200(DGLAB_MAX_INTENSITY);更高的目标会被拒绝。

  • 默认步进限制:每条向上命令为 5(DGLAB_MAX_STEP)。

  • 看门狗:在 20 秒内没有命令或心跳时,输出会被设为零。

  • 紧急停止:dglab_emergency_stop 会清除所有设备和排队中的任务。

Related MCP server: InstrMCP

功能

  • 通过标准 MCP 工具进行自然语言控制。

  • 与 DG-LAB 4 移动应用进行 QR 配对;无需电脑蓝牙。

  • 实时的电池、连接、通道和任务遥测。

  • 内置预设、自定义波形和热加载的 .pulse 文件。

  • 硬性安全上限、步进保护、遥测门控、每通道队列以及全局控制租约。

环境要求

  • Node.js 22 或更高版本。

  • iOS 或 Android 上的 DG-LAB 4,并已通过蓝牙配对 Coyote V2 或 V3。

  • Claude Desktop、Cursor、OpenCode、Codex、MCP Inspector 或其他 MCP 客户端。

快速开始

Claude Desktop、Cursor、OpenCode 或 Codex

在客户端的配置中使用以下 MCP 服务器命令:

{
  "command": "npx",
  "args": ["-y", "@zakotoys/dglab-mcp@latest"]
}

对于有此需要的 Windows 客户端,请使用 cmd:

{
  "command": "cmd",
  "args": ["/c", "npx", "-y", "@zakotoys/dglab-mcp@latest"]
}

将上面的对象嵌入到客户端的 MCP 服务器映射中。示例:

Claude Desktop(claude_desktop_config.json):

{
  "mcpServers": {
    "dglab": {
      "command": "npx",
      "args": ["-y", "@zakotoys/dglab-mcp@latest"]
    }
  }
}

Cursor(~/.cursor/mcp.json 或 .cursor/mcp.json):

{
  "mcpServers": {
    "dglab": {
      "command": "npx",
      "args": ["-y", "@zakotoys/dglab-mcp@latest"]
    }
  }
}

OpenCode(opencode.json):

{
  "mcp": {
    "dglab": {
      "type": "local",
      "command": ["npx", "-y", "@zakotoys/dglab-mcp@latest"]
    }
  }
}

Codex(~/.codex/config.toml):

[mcp_servers.dglab]
command = "npx"
args = ["-y", "@zakotoys/dglab-mcp@latest"]

MCP Inspector

npx @modelcontextprotocol/inspector -y @zakotoys/dglab-mcp@latest

通过 stdio 连接,然后调用 dglab_connect 以显示配对 QR 码。

配对设备

  1. 从你的 MCP 客户端调用 dglab_connect。

  2. 使用 DG-LAB 4 应用扫描返回的 QR 码,或打开其会话链接。

  3. 调用 dglab_get_status,确认 Coyote 已配对且遥测数据为最新。

  4. 从低强度开始,例如使用 target: 3 调用 dglab_set_intensity,然后播放波形。完成后调用 dglab_disconnect;它会先停止输出。

可以同时连接多个应用和设备。需要时传入 clientId 和 slotId;仅当恰好有一个兼容的 Coyote 可用时,才接受省略 target 的操作。

MCP 工具

工具

用途

dglab_connect

启动或复用中继会话并返回 QR 码。

dglab_disconnect

停止所有输出并销毁会话。

dglab_get_status

读取中继、安全、设备、通道和任务状态。

dglab_set_intensity

在安全验证后设置 A/B 通道目标。

dglab_adjust_intensity

应用带符号的、经安全检查的通道增量。

dglab_list_waveforms

列出内置和外部波形。

dglab_play_waveform

播放指定的命名波形,持续一段有界时间。

dglab_play_custome_waveform

编译并播放渐变/保持/脉冲/静音段。

dglab_stop_channel

停止任务并重置一个通道。

dglab_emergency_stop

立即停止所有通道和任务。

dglab_heartbeat

续期活动控制租约。

非零输出要求已配对、受支持且具有已知遥测数据的 Coyote。错误使用稳定的错误码,例如 NOT_CONNECTED、AMBIGUOUS_TARGET、SAFETY_LIMIT 和 INVALID_WAVEFORM。

配置

所有变量均为可选:

变量

默认值

说明

DGLAB_MAX_INTENSITY

30

0-200 刻度上的绝对输出上限。

DGLAB_MAX_STEP

5

每条命令允许的最大向上调整量。

DGLAB_HEARTBEAT_TIMEOUT_MS

20000

控制租约的看门狗超时。

DGLAB_MAX_WAVEFORM_DURATION_MS

10000

最大波形持续时间。

DGLAB_RELAY_URL

wss://trex.dungeon-lab.cn/v4

DG-LAB V4 中继端点。

DGLAB_PULSE_DIR

~/.dglab-mcp/pulses

外部 .pulse 文件的目录。

有效通道上限是配置的限制与应用或设备通告的所有限制中的最小值。

外部波形

将官方格式的 .pulse 文件直接放入 DGLAB_PULSE_DIR:

~/.dglab-mcp/pulses/
  waves.pulse
  my-favourite.pulse

每次 list/play 调用都会重新扫描该目录。文件大小限制为 64 KiB,目录最多接受 100 个文件。名称与内置 id 和标签的匹配不区分大小写和分隔符,但匹配是精确的而非模糊的。

开发

npm install
npm run ci          # typecheck, lint, coverage, build, and pack check
npm run build       # compile dist/ and make the CLI executable
npm test
npm run lint:fix

测试套件使用模拟的 V4 中继和模拟的 DG-LAB 应用,因此不需要硬件。

发布

GitHub Actions 使用 npm Trusted Publishing 和来源证明发布匹配的 vX.Y.Z 标签,然后创建带有自动生成的变更日志说明的 GitHub Release。如果工作流重新运行,现有的 Release 将保持不变。将 npm 包的 Trusted Publisher 配置为:

  • 提供方:GitHub Actions

  • 组织/用户:zakotoys

  • 仓库:dglab-mcp

  • 工作流文件名:publish.yml

  • 环境:留空

  • 允许的操作:npm publish

对于新的检出,请在登录 npm 组织后,一次性初始化这个 scoped 公共包:

npm login
npm publish --access public

然后从干净的检出中发布后续版本:

npm version patch   # or minor / major
git push origin main --follow-tags

该工作流会运行完整的 CI 套件,并且仅在标签与 package.json 中的版本匹配时才发布。

范围

本项目仅通过 DG-LAB 4 V4 中继支持 Coyote V2/V3。旧版 V3 中继、直接 BLE、HTTP 传输、GUI、原始帧和 Opossum 输出控制不在当前范围内。

许可证

GPL-3.0

Available Tools

11 tools
dglab_adjust_intensityAdjust channel intensityA

Apply a signed intensity delta to one channel. Positive deltas are limited to +5 per call and to the effective ceiling; negative deltas are unrestricted.

Inputs: delta (required), channel (required), slotId, clientId.

dglab_connectConnect DG-LAB relayA
Idempotent

Start (or reuse) the DG-LAB 4 V4 relay session. Returns the pairing QR code (PNG), the app socket URL, and the session link. Scan the QR code or open the link with the DG-LAB 4 mobile app to pair. Safe to call again to fetch pairing info for an existing session.

Inputs: no named parameters.

dglab_disconnectDisconnect relay sessionA
DestructiveIdempotent

Emergency-stop every device, then destroy the relay session and all cached pairing state.

Inputs: no named parameters.

dglab_emergency_stopEmergency stopA
DestructiveIdempotent

Immediately stop every channel and waveform task on every paired app and device, bypassing all queues. Cannot be undone by pending commands.

Inputs: no named parameters.

dglab_get_statusGet DG-LAB statusA
Read-onlyIdempotent

Read relay state, the safety lease, paired apps, devices (battery, Bluetooth state, A/B intensity, channel condition, mute, comfort limits, effective ceilings), and waveform tasks. Set refresh to re-query device lists from the apps first.

Inputs: slotId, refresh, clientId.

dglab_heartbeatRenew safety leaseA
Read-onlyIdempotent

Renew the control lease (timeout 20000ms) to keep output enabled while idle. When no output is active this succeeds as a no-op. If the lease ever expires, all outputs are stopped automatically.

Inputs: no named parameters.

dglab_list_waveformsList waveformsA
Read-onlyIdempotent

List built-in Coyote presets and external .pulse waveforms with ids, labels, source, and natural duration. The pulse directory is rescanned on every call, so newly added or changed files appear immediately.

Inputs: no named parameters.

dglab_play_custom_waveformPlay custom waveformA

Compile and play semantic waveform segments (ramp, hold, pulse, silence) on one channel. Total duration is capped at 10000ms. Requires a safe nonzero intensity on the channel; never changes intensity.

Inputs: channel (required), segments (required), slotId, clientId.

dglab_play_waveformPlay named waveformA

Play a named waveform (built-in preset or hot-loaded .pulse file; matching is case/separator-insensitive across ids and English/Chinese names) on one channel. Optionally repeat or truncate it to durationMs (max 10000ms). Requires a safe nonzero intensity on the channel; never changes intensity. Playback replaces the channel's current waveform task.

Inputs: name (required), channel (required), slotId, clientId, +1 more.

dglab_set_intensitySet channel intensityA
Idempotent

Set one output channel (A or B) to an absolute target on the 0-200 scale. The target must not exceed the effective ceiling (software cap DGLAB_MAX_INTENSITY=30 tightened by device limits) and increases are limited to steps of 5. Reductions and 0 are always allowed.

Inputs: target (required), channel (required), slotId, clientId.

dglab_stop_channelStop channelA
DestructiveIdempotent

Clear all waveform tasks and reset the intensity of one channel to 0.

Inputs: channel (required), slotId, clientId.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 11 tools

    Disambiguation5/5

    Each tool targets a distinct concern: session lifecycle, status, channel stopping, absolute vs. relative intensity, waveform discovery, file-based vs. custom playback, emergency stop, and lease renewal. Even similar tools like set_intensity and adjust_intensity are clearly separated by absolute vs. delta semantics.

    Naming Consistency4/5

    All tools share the dglab_ prefix and mostly follow a verb_object pattern: connect, disconnect, stop_channel, set_intensity, play_waveform. The main deviation is dglab_heartbeat, which is a noun rather than a verb_object command, but it remains predictable and readable within the set.

    Tool Count5/5

    Eleven tools is well-scoped for a device-control server. Each tool covers a meaningful part of session management, safety, intensity control, and waveform playback without excessive fragmentation.

    Completeness4/5

    The tool surface covers the full control lifecycle: connect, disconnect, status, intensity, waveform playback, emergency stop, and lease renewal. A minor gap is that status exposes settings like mute and comfort limits, but there are no direct tools to modify those settings.

    Maintenance

    ActivitySlowing
    ResponsivenessLimited data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      AI-native oscilloscope control. A pure-Python MCP service that lets LLM agents control Keysight EDUX1052G oscilloscopes via a compact DSL.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      MCP server for quantum device physics laboratory instrumentation control, enabling LLMs to interact with physics instruments and measurement systems through QCodes and JupyterLab.
      39
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      MCP server that lets AI assistants control Siglent SDG waveform generators over a local network using natural language, supporting signal generation, modulation, sweep, burst, and arbitrary waveforms.
      20
      240 npm
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables natural language control of a live GNU Radio SDR flowgraph, allowing users to tune frequencies, adjust gain, capture IQ samples, analyze spectra, and detect signals through an MCP-compatible client.
      2
      MIT