PPK2 MCP Server
Controls and collects data from Nordic Semiconductor Power Profiler Kit II (PPK2) hardware, enabling current measurement, DUT power supply, logic channel capture, and offline power analysis such as activity segmentation and battery life estimation.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PPK2 MCP Server measure sleep current for 30 seconds"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
PPK2 MCP Server
Nordic Semiconductor Power Profiler Kit II (PPK2) 的 Model Context Protocol (MCP) 服务器。 让 LLM 直接完成功耗剖析:控制硬件采集电流(500 nA–2000 mA @ 100 kSa/s + 8 路逻辑口)、 给 DUT 供电(源表 0.8–5 V),采集数据落盘 npz,再做离线分析——统计、功耗分段、 电池续航估算,回答"睡眠电流多少 / 活动占空比多少 / 一节 CR2032 能跑多久"。
开发方式:DDD(四层 + 依赖倒置),见
docs/PLAN.md协议逆向与真机验证笔记:
docs/NOTES.md(真机 18 项自检 0 FAIL)19 个 MCP 工具:连接/配置/采集落盘/离线分析
采样数据只落盘(npz),工具返回摘要 + 包络 + 路径,绝不内联数组
协议层自研(规避 GPLv2 的 ppk2-api),对照 Nordic 官方开源 app 逐条验证, 增加了官方 app 同款的模 64 计数器丢样检测(IRNAS 库没有)
快速开始
cd /Users/andylos/mcp_gen/PPK2
python3 -m venv .venv
.venv/bin/pip install -e . pytest
.venv/bin/python -m pytest tests/ # 56 个测试:mock 设备全栈 + MCP 协议级
.venv/bin/python scripts/probe_device.py # 真机端到端自检(18 项)
PPK2_MOCK=1 .venv/bin/ppk2-mcp # 无硬件演示(mock 设备)PPK2 经 USB CDC 串口连接(免驱);插入后绿灯亮即可,无需其他配置。
macOS 上会出现两个 cu.usbmodem* 口,服务器自动探测 0x19 应答识别命令口。
Related MCP server: PPK2 MCP Server
配置(环境变量)
变量 | 默认 | 说明 |
| 自动发现 | 指定串口(跳过探测) |
|
| 采集 npz 保存目录 |
|
|
|
|
| 普通操作超时(秒) |
| 关 |
|
接入 MCP 客户端
ZCode(.zcode/settings.json)或 Claude Desktop:
{
"mcpServers": {
"ppk2": {
"command": "/Users/andylos/mcp_gen/PPK2/.venv/bin/python",
"args": ["-m", "ppk2_mcp.server"],
"cwd": "/Users/andylos/mcp_gen/PPK2",
"env": {
"PPK2_DATA_DIR": "/Users/andylos/mcp_gen/PPK2/data"
}
}
}
}工具总览(19 个)
分组 | 工具 |
系统/连接 (5) |
|
配置 (5) |
|
采集 (4) |
|
离线分析 (5) |
|
典型工作流
list_devices -> connect -> set_mode(AMPERE) # 或 SOURCE + set_source_voltage(3300)
capture(5.0) # 采集 5s,返回摘要+1000 点包络+路径
analyze_capture("cap_x", start_s=1, end_s=2) # 子窗统计(µC 电量 / µJ 能量)
detect_activity_segments("cap_x", threshold_ua=50, min_duration_s=0.01)
estimate_battery_life(capture_id="cap_x", capacities_mah=[120, 240])
read_logic_channels("cap_x", channel=0, mode="edges") # 逻辑口与电流同步采样DUT 供电流程:SOURCE 模式下 set_source_voltage(3300) → set_dut_power(true)
→ capture(...) → set_dut_power(false)。图表语义与官方 app 一致:SPM 模式
显示的仍是负载电流,电压即设定值。
架构(DDD)
interfaces(server.py 组合根,19 工具)
└── application(PPK2Service 用例编排,不变式校验)
└── domain(值对象/换算器+尖峰滤波状态机/分析服务纯函数/Port 接口)
└── infrastructure 实现 Port:串口协议+设备网关 / npz 仓库 / mock 设备依赖方向自外向内;domain 零 IO 零框架。测试金字塔:领域纯函数 → 协议编解码 (真机元数据 fixture)→ mock 设备全栈用例 → FastMCP 协议级内存会话。
已知边界
设备未校准(
Calibrated: 0)时按官方缺省系数换算,工具响应带告警; 校准请在官方 nRF Connect Power Profiler 中完成模式切换/DUT 上电后设备有预热延迟,首采样本数可能偏低——响应带告警,建议重采
raw_command发 0x20(RESET)会触发 USB 重枚举,服务器自动清理会话, 需重新 connect长采集(start/stop)无时长上限,但 npz 体积 ≈500 KB/s,注意磁盘
Available Tools
19 toolsanalyze_captureA
离线分析历史采集:全窗或 [start_s,end_s] 子窗的统计+包络(无需连接设备)。
返回 mean/min/max/median/charge(µC)/energy(µJ)与包络。
Inputs: capture_id (required), end_s, start_s, envelope_points.
captureA
定长采集(阻塞,≤60s):采样→落盘 npz→返回统计+包络+路径。
这是功耗分析的主入口。返回 stats(mean/min/max/charge/energy)、 envelope(~1000 点 min/max/mean 概览)、meta(含丢样数)与文件路径。 capture_id 仅限字母数字._-。
Inputs: capture_id, duration_s.
connectA
连接 PPK2 并读取元数据(校准系数、Calibrated 标志、VDD)。
port 缺省自动发现。连接后可用 get_status 查看校准状态。
Inputs: port.
detect_activity_segmentsB
功耗分段(阈值滞回):按 threshold_ua 分 active/sleep 段。
返回每段起止/均值/电量与 active 占空比——回答"睡眠电流多少、 活动占空比多少"类问题。min_duration_s 过滤毛刺段。
Inputs: capture_id (required), threshold_ua (required), end_s, start_s, +1 more.
disconnectA
断开串口(采样中会先停止)。
Inputs: no named parameters.
estimate_battery_lifeB
电池续航估算:按均值电流对若干容量(mAh)估算小时/天。
数据来源二选一:capture_id(自动取窗口均值电流)或直接给 mean_ua。 capacities_mah 缺省 [120, 240, 500, 1000, 2400]。
Inputs: end_s, mean_ua, start_s, capture_id, +1 more.
get_capture_statusA
进行中采集的实时状态:已采样本数/丢失数/速率/时长。
Inputs: no named parameters.
get_statusB
会话快照:连接/身份/模式/VDD/采集进行中状态/校准标志。
Inputs: no named parameters.
list_capturesA
列出历史采集(npz 元数据表:时长/速率/丢样/路径),按时间倒序。
Inputs: no named parameters.
list_devicesA
扫描串口并探测 PPK2(以 0x19 元数据应答识别命令口)。
返回候选端口列表;无硬件时返回空列表(可用 PPK2_MOCK=1 演示)。
Inputs: no named parameters.
raw_commandA
逃生舱:发送原始命令字节(hex,如 "19" 读元数据)并回收响应。
含 0x20(RESET,会触发 USB 重枚举)时必须 confirm=true。 采样进行中不可用。
Inputs: data_hex (required), confirm.
read_logic_channelsB
8 路逻辑输入口分析(与电流同步采样)。
mode="stats":高电平占比/边沿数;mode="edges":分页边沿表 (offset/limit,level_after 判向)。channel 0-7。
Inputs: channel (required), capture_id (required), mode, end_s, +3 more.
set_dut_powerB
DUT 电源开关(SOURCE 模式下接通/切断输出,等价官方 app 电源按钮)。
Inputs: on (required).
set_modeA
设置测量模式:AMPERE(电流表,外部供电)或 SOURCE(源表,PPK2 给 DUT 供电)。
SOURCE 模式采集前还需 set_source_voltage。
Inputs: mode (required).
set_resistor_rangeA
锁定量程 0-4(0 最灵敏 ~nA 级,4 最大 ~A 级);默认自动量程。
rng=null 恢复自动(固件无原生恢复命令,通过重切当前模式实现)。
Inputs: rng (required).
set_source_voltageA
设置电压(mV,800-5000,域外自动夹紧)。
SOURCE 模式:稳压器实际输出;AMPERE 模式:作为电流换算的 VDD 估计值。
Inputs: millivolts (required).
set_spike_filteringB
硬件尖峰滤波开关(官方默认开;影响换程尖峰的平滑)。
Inputs: on (required).
start_captureA
启动长采集(后台,不阻塞;可>60s)。之后用 get_capture_status 查看, stop_capture 结束并落盘。
Inputs: no named parameters.
stop_captureB
停止长采集并落盘,返回与 capture 相同的摘要。
Inputs: capture_id.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 19 tools
Each tool targets a distinct action or resource: discovery vs. connection, device configuration setters, capture lifecycle, and post-capture analysis. The only adjacent pair is capture vs. start/stop_capture, but the blocking <=60s vs. background long-capture distinction is explicit, so misselection is unlikely.
Names are uniformly snake_case and almost all follow verb_noun or verb_object patterns (list_captures, set_mode, get_capture_status). Minor deviations like connect, disconnect, capture, and raw_command are conventional and readable rather than inconsistent.
19 tools is on the higher side but reasonable for a full-featured PPK2 client spanning device discovery, configuration, capture, analysis, and logic channels. No obvious redundant tool exists, though the capture lifecycle could be seen as slightly expansive.
The surface covers the core lifecycle: discover, connect, configure, capture (short and long), monitor, stop, analyze, segment, estimate battery, and read logic channels. Minor gaps like deleting/exporting captures, explicit sample-rate control, or calibration writes are mostly addressable via raw_command.
Maintenance
Related MCP Connectors
Home energy for AI assistants: live Power flow, Energy history, solar forecast, and device control.
AI-powered life cycle assessment and modelling: connect to LCA databases, build and analyze systems
Protocol-native energy infrastructure orchestration for AI data centers. Provides 46 MCP tools across 8 grid protocols (IEC-61850, DNP3, Modbus, OCPP, OpenADR, IEEE 2030.5, IEC 60870-5-104, ICCP) with 5 core API primitives: connect, dispatch, settle, comply, and intel. Enables AI agents to programmatically interact with substations, grid interfaces, and energy assets for real-time workload-grid coordination.
Create RF signal projects from prompts, inspect graphs, and export IQ data.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceMCP server for Nordic Semiconductor's Power Profiler Kit II (PPK2), enabling current measurement and device control via 12 tools from Claude.1MIT
- FlicenseAqualityDmaintenanceEnables MCP clients to control a Nordic PPK2 for power profiling: configure source/measurement modes, set voltage, power DUT, measure current/power/energy, and capture logic channels.6-
- FlicenseNot gradedqualityCmaintenanceEnables MCP clients to list, inspect, probe, capture, and analyze current measurements from the Nordic Power Profiler Kit II, returning aggregates and file paths rather than raw samples.-
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to capture, measure, and decode USB logic-analyzer signals, including 16-channel streaming and sigrok protocol decoding for UART, I2C, SPI, CAN, and other protocols.MIT