关于 MsgPack (LsMsgPack)
一个 MCP 服务和命令行工具,可将 MsgPack 数据解码为 AI 和人都能读懂的文本,并读取 VS Code 或 Visual Studio 调试中暂停程序的变量字节。面向需要排查 MsgPack 数据的开发者。
主要功能
- 01解码 MsgPack 并输出带注释的 JSON
- 02解析 LsMsgPack 索引模式与类型 id
- 03读取调试中变量的字节数据
- 04将数据读入已编译的 .NET 类进行比对
- 05按偏移量定位字节并搜索值
- 06支持命令行使用
适用场景
- 01在调试时检查暂停程序中的 MsgPack 载荷
- 02排查 MsgPack 数据与 .NET 类属性不匹配的问题
- 03在终端或 AI 助手中查看二进制消息内容
MCP 相关
该项目是 MCP 服务,向 MCP 客户端提供 msgpack_decode、msgpack_debug_read 等工具,用于解码数据和读取调试会话中的字节。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
LsMsgPack MCP 服务
面向 AI Agent 的 MsgPack。MCP 服务和命令行工具,可将 MsgPack 数据解码为 AI(或终端中的用户)可读的文本,还可读取程序在 VS Code 或 Visual Studio 调试器中暂停时某个变量的字节。
大模型读取的是文本,而不是字节。十六进制或 base64 每个字节都要消耗多个 token,手动解码既慢又容易出错。有些数据仅凭字节根本无法解码:LsMsgPack 的索引架构会将属性名称写成索引,而架构引用只保存架构的 16 字节 ID。此工具使用 LsMsgPack 库本身(即 MsgPack Explorer 的代码)解码数据,并将其写成带注释的 JSON:
MsgPack "doc1" 247 bytes from payload (byte[], Launch Api).
Structure: indexed schema (inline, 3 types) followed by the body
No errors, 0 warnings or comments.
Schema (inline): type ids and property ids in the body are indexes into these lists.
#0 Invoice: Id, Customer, Billing, Lines, Date, Reference, Tags
#1 Address: Street, Number, City
#2 Line: Product, Quantity, Price
Objects (JSON with // comments: a type name comes from a type id, a name with ~ is inferred from the schema; dictionary keys that are not strings are not quoted):
{ // Invoice~
"Id": 1234,
"Customer": "Alice",
"Billing": { "Street": "Main street", "Number": 12, "City": "Amsterdam" }, // Address~
"Lines": [ // 2 items
{ "Product": "Apples", "Quantity": 3, "Price": 1.25 }, // Line~, Price: decimal
{ "Product": "Pears", "Quantity": 2, "Price": 0.99 } // Line~, Price: decimal
],
"Date": "2026-10-05T12:30:00Z", // timestamp
"Reference": "5bad8f0fcbd99f46a16570867728950e", // bin, 16 bytes, as Guid 0f8fad5b-d9cb-469f-a165-70867728950e
"Tags": ["fruit", "fresh"] // 2 items
}
它可以读取任意 MsgPack 数据,不仅限于 LsMsgPack 写入的数据。错误信息会附带偏移量,错误后读取的值也会标记出来。
安装
需要 .NET 运行时 8 或更高版本。
dotnet tool install -g LsMsgPack.Mcp # the command is lsmsgpack-mcp
从源代码构建:dotnet publish LsMsgPackMcpServer -c Release -o <folder>,然后运行 dotnet <folder>/LsMsgPackMcp.dll,代替 lsmsgpack-mcp。
添加到 Agent
| 客户端 | 方法 |
|---|---|
| VS Code(Copilot Agent 模式) | 如果已安装 MsgPack Explorer 扩展,无需操作:扩展会注册名为 “MsgPack (LsMsgPack)” 的服务。 |
| Claude Code | claude mcp add lsmsgpack -- lsmsgpack-mcp |
| Visual Studio 2022(17.14+) | %USERPROFILE%\.mcp.json(或解决方案旁的 .mcp.json):{ "servers": { "lsmsgpack": { "type": "stdio", "command": "lsmsgpack-mcp" } } } |
| Claude Desktop、Cursor、Windsurf 等 | { "mcpServers": { "lsmsgpack": { "command": "lsmsgpack-mcp" } } } |
在 VS Code 中,MsgPack: Copy MCP Server Configuration... 会复制以下配置:如果已安装该工具,则复制工具的配置;否则复制扩展附带的服务配置(其路径中包含扩展版本号,因此更新后请重新复制)。
工具
| 工具 | 功能 |
|---|---|
msgpack_debug_status | 安装了 MsgPack 扩展的 IDE、它们的调试会话,以及程序暂停的位置。 |
msgpack_debug_locals | 暂停的堆栈帧中的变量及其类型。可能容纳字节的变量会特别标记。 |
msgpack_debug_read | 读取暂停程序中某个表达式的字节并进行解码。可读取 byte[]、流(可定位的流会恢复到原位置)、Memory<byte>、List<byte>、HttpContent 以及 base64 或十六进制字符串。在 VS Code 中,也支持 JavaScript Uint8Array/Buffer 和 Python bytes。如果有效负载引用了 schemaStore,则会从程序的 SchemaStore 中读取架构。saveTo 还会将字节写入文件。 |
msgpack_decode | 解码 data(十六进制、base64 或字节值)、file,或之前解码的 doc。schemas 接受 SchemaStore.Export(或单个架构),用于架构引用。 |
msgpack_read_as_class | 将数据读取到已编译 .NET 程序集中的类(assembly:构建输出中的 .dll,type:类),并报告不匹配的内容:类中不存在的属性(附带“你是否想输入”提示)、无法转换的值、没有架构条目的类、未找到的类型 ID,并附上对象的路径(报告差异)。还会显示读取到的对象。程序集会在单独的进程中加载:此操作会运行类的构造函数和 setter。 |
msgpack_explain_offset | 说明偏移处的字节:包含该字节的项目、对象成员、标头和内容字节,以及它周围的字节。 |
msgpack_search | 查找包含文本或值的项目,并显示偏移量和对象路径。 |
每个解码后的有效负载都会获得一个文档 ID(doc1、doc2……),供后续调用使用。可使用以下选项缩小和切换输出:
view:objects(默认)、items(带偏移量的 MsgPack 编码)或both。path(例如Lines[2])、from/to(字节范围)、maxNodes、maxString。offsets会添加每个值的偏移量。issues接受errors、all或none。endian和continueOnError(默认开启)。
调试
VS Code(MsgPack Explorer)和 Visual Studio(MsgPack Debugger Extension)的 MsgPack 扩展会监听 127.0.0.1。它们会将端口和随机令牌写入锁定文件 ~/.lsmsgpack/ide(%USERPROFILE%\.lsmsgpack\ide)。MCP 服务会使用启动它的 IDE;否则会使用工作目录位于其工作区中的 IDE(如果有多个 IDE 正在运行,ide 会选择其中一个)。
- 默认情况下,只读取变量和成员路径(
buffer、this._payload、response.Content、items[2].Data),不会调用方法。IDE 设置可以允许使用任意表达式:VS Code 中的lsmsgpack.mcp.allowAnyExpression(仅用户设置),Visual Studio 中的“工具” > “选项” > “MsgPack Explorer”。 - 无法定位的流会通过读取来消耗,因此 IDE 会先询问用户。
- IDE 设置可以关闭桥接:VS Code 中的
lsmsgpack.mcp.enabled,以及 Visual Studio 中同一选项页面。
命令行
lsmsgpack-mcp decode payload.msgpack # the objects
lsmsgpack-mcp decode payload.msgpack --view items # the items with offsets and encodings
lsmsgpack-mcp decode --data "82 a4 4e 61 6d 65 ..." # bytes as text
lsmsgpack-mcp explain payload.msgpack 0x7b # what the byte at 0x7b is
lsmsgpack-mcp search payload.msgpack Amsterdam
lsmsgpack-mcp read-as payload.msgpack --assembly bin/Debug/net8.0/MyApp.dll --type Order # what doesn't match the class
lsmsgpack-mcp debug status | debug locals | debug read <expression>
lsmsgpack-mcp --help 会列出选项。不带参数时,它会通过 stdin/stdout 运行 MCP 服务。
更多信息:docs/Mcp.md。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。