Picotool MCP服务器
MCP(模型上下文协议)服务器,为Claude Code提供通过以下方式与Raspberry Pi Pico设备(RP2040/RP2350)交互的功能 picotool 命令行工具。
✨ 特性
- 🔍 设备信息:查询连接的Pico设备以获取详细的硬件和固件信息
- 📁 二进制分析:分析UF2、ELF和BIN文件,无需闪存到设备
- 🧩 引脚映射:从固件中提取引脚分配信息
- 🔄 设备重启:以编程方式在应用程序和BOOTSEL模式之间重新启动设备
- 🎯 设备选择:按USB总线、地址、VID/PID或序列号过滤设备
- 🔧 版本检查:获取picotool版本信息以进行故障排除
- 🗂️ 分区管理:查看RP2350分区表信息和布局
- 🏛️ 多架构:支持RP2350设备上的ARM和RISC-V内核
- ⚡ 快速集成:内置
uv用于闪电般快速的依赖关系管理 - 🛡️ 稳健的错误处理:妥善处理断开连接的设备和文件错误
- 📊 综合数据:访问设备信息、构建元数据、内存布局等
🚀 快速开始
先决条件
安装
# Clone the repository
git clone https://github.com/DavidMenting/picotool-mcp-server.git
cd picotool-mcp-server
# Install dependencies with uv
uv syncClaude桌面集成
将此配置添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json\ 视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"picotool": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/picotool-mcp-server",
"run",
"python",
"-m",
"picotool_mcp_server"
]
}
}
}备注:替换 /absolute/path/to/picotool-mcp-server 以及此存储库的实际路径。独立使用
您也可以直接运行服务器:
uv run python -m picotool_mcp_server🛠️ 可用工具
picotool_info
获取有关连接的Pico设备的全面信息或分析二进制文件。 可以自动强制运行设备进入BOOTSEL模式 -无需按下物理按钮!
参数
| 参数 | 类型 | 描述 | 默认值 |
|---|---|---|---|
target | string | 要分析的文件路径,对于已连接的设备为空 | "" |
basic | boolean | 包括基本信息 | true |
metadata | boolean | 包括所有元数据块 | false |
pins | boolean | 包含引脚信息 | false |
device | boolean | 包含设备信息 | false |
debug | boolean | 包含设备调试信息 | false |
build | boolean | 包含构建属性 | false |
all | boolean | 包含所有信息 | false |
force | 布尔值 | 自动将运行中的设备重新启动到BOOTSEL模式 (不需要物理按钮) | false |
force_no_reboot | boolean | 强制设备重置,但不要重新启动回应用程序模式 | false |
bus | string | 按USB总线号筛选设备 | - |
address | string | 按USB设备地址筛选设备 | - |
vid | string | 按供应商ID筛选 | - |
pid | string | 按产品ID筛选 | - |
serial | string | 按序列号筛选 | - |
例子
自动检测正在运行的设备并获取信息(最常见的用例):
{
"force": true,
"all": true
}从已处于BOOTSEL模式的设备获取基本信息:
{
"basic": true
}获取全面的设备信息:
{
"all": true
}分析固件文件:
{
"target": "/path/to/firmware.uf2",
"pins": true,
"build": true
}强制运行中的设备提供信息(对开发有用):
{
"force": true,
"all": true
}按序列号查询特定设备:
{
"serial": "20C110CE49017709",
"device": true,
"pins": true
}样本输出
Partition 1
Program Information
name: my-project
version: 1.0.0
description: My Pico Project
features: USB stdin / stdout
target chip: RP2350
image type: ARM Secure
Fixed Pin Information
0: UART0 TX
1: UART0 RX
2: I2C0 SDA
3: I2C0 SCL
Device Information
type: RP2350
revision: A2
flash size: 16384K
current cpu: ARMpicotool_reboot
将连接的Pico设备重新启动到应用程序模式或BOOTSEL模式,以进行开发工作流程。
参数
| 参数 | 类型 | 描述 | 默认值 |
|---|---|---|---|
all_devices | boolean | 重新启动所有连接的设备 | false |
usb_mass_storage | boolean | 重新启动到USB大容量存储模式(BOOTSEL) | false |
partition | string | 重新启动到特定分区 | - |
cpu | string | 指定要启动的CPU(RP2350为ARM/RISC-V) | - |
force | boolean | 强制未处于BOOTSEL模式的设备重置 | false |
force_no_reboot | boolean | 强制设备重置,但不重新启动 | false |
bus | string | 按USB总线号筛选设备 | - |
address | string | 按USB设备地址筛选设备 | - |
vid | string | 按供应商ID筛选 | - |
pid | string | 按产品ID筛选 | - |
serial | string | 按序列号筛选 | - |
例子
重新启动到BOOTSEL模式(用于固件闪烁):
{
"usb_mass_storage": true,
"force": true
}重新启动回到应用程序模式:
{}重新启动所有连接的设备:
{
"all_devices": true
}重新启动到特定分区(RP2350):
{
"partition": "1",
"force": true
}使用特定CPU(RP2350)重新启动:
{
"cpu": "RISC-V",
"usb_mass_storage": true
}picotool_version
获取picotool版本信息以进行故障排除和诊断。
参数
此工具不接受任何参数,它只返回已安装的picotool版本。
示例
{}样本输出
picotool v2.0.0 (d4c9a39)picotool_partition_info
从RP2350设备获取分区表信息。RP2040设备没有分区表。
参数
| 参数 | 类型 | 描述 | 默认值 |
|---|---|---|---|
family_id | string | 要显示分区的目标家族ID(例如“rp2350-arm-s”、“rp2350 riscv”) | - |
force | boolean | 强制未处于BOOTSEL模式的设备重置 | false |
force_no_reboot | boolean | 强制设备重置,但不重新启动 | false |
bus | string | 按USB总线号筛选设备 | - |
address | string | 按USB设备地址筛选设备 | - |
vid | string | 按供应商ID筛选 | - |
pid | string | 按产品ID筛选 | - |
serial | string | 按序列号筛选 | - |
例子
获取完整分区表:
{}显示ARM安全系列的分区信息:
{
"family_id": "rp2350-arm-s"
}强制正在运行的设备显示分区信息:
{
"force": true
}样本输出
un-partitioned_space : S(rw) NSBOOT(rw) NS(rw), uf2 { absolute }
partitions:
0(A) 00002000->00201000 S(rw) NSBOOT(rw) NS(rw), id=0000000000000000, "A", uf2 { rp2350-arm-s, rp2350-riscv }, arm_boot 1, riscv_boot 1
1(B w/ 0) 00201000->00400000 S(rw) NSBOOT(rw) NS(rw), id=0000000000000001, "B", uf2 { rp2350-arm-s, rp2350-riscv }, arm_boot 1, riscv_boot 1指定了家庭ID:
Family ID 'rp2350-arm-s' can be downloaded in partition 0:
00002000->00201000📋 支持设备
- RP2040:原装Raspberry Pi Pico、Pico W和兼容板
- RP2350:基于Raspberry Pi Pico 2和兼容RP2350的板
🔧 发展
设置开发环境
# Install development dependencies
uv sync --dev
# Install pre-commit hooks (optional)
pre-commit install代码质量
# Format code
uv run black .
# Lint code
uv run ruff check .
# Type checking
uv run mypy src/测试
# Run tests (when implemented)
uv run pytest
# Test the server manually
uv run python -c "
import asyncio
from src.picotool_mcp_server.picotool import PicotoolWrapper
async def test():
picotool = PicotoolWrapper()
version = await picotool.version()
print(f'Picotool version: {version}')
asyncio.run(test())
"🐛 故障排除
常见问题
服务器启动失败:
- 确保
picotool已安装并位于您的PATH中 - 验证是否正在使用Python 3.10+
- 检查一下
uv已安装
未找到设备:
- 以BOOTSEL模式连接Pico设备(插入时按住BOOTSEL)
- 验证设备是否出现在系统中(检查USB设备列表)
- 尝试
picotool info直接确认设备检测
权限错误:
- 在Linux上,您可能需要为Pico设备添加udev规则
- 确保您的用户有权访问USB设备
调试日志记录
服务器记录重要事件。检查Claude Desktop的MCP服务器日志:
macOS: ~/Library/Logs/Claude/mcp-server-picotool.log
🤝 贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 进行更改
- 运行测试和梳理(
uv run black . && uv run ruff check .) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🔗 相关项目
______________________________________________________________________
*内置于❤️ Raspberry Pi Pico社区*
