Skip to content
xhw949Public

About

只读 MCP server:通过 Keil MDK 的 UVSC64.dll / UVSOCK 读取调试工程中的 C 符号、变量、表达式与目标内存,让 Claude Desktop / Claude Code 调试时无需切回 Keil 界面即可读取数据(attach 模式优先,无写/烧录/复位能力)。

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Keil UVSC MCP

只读 stdio MCP server,通过 Keil 安装目录中的 UVSC64.dll / UVSOCK 读取当前调试工程的 C 符号和目标内存。把 Keil 的符号查看和内存读取能力暴露给 MCP client(Claude Desktop、Claude Code 等),让 AI 能在调试时直接读取变量、表达式和内存,而无需切回 Keil 界面。

当前版本:0.2.0。

安全边界

  • 没有写变量、写内存、复位、运行控制、编译、下载或烧录工具。
  • 日常推荐 attach 模式:工具不会自动进入/退出 Debug,也不覆盖当前 Keil 工程。
  • 读取失败不等于变量为零——工具会如实返回错误,调用方不应把读失败当作零值。

工具

  • keil_uvsc_info:返回 UVSC/UVSOCK 版本、Keil 路径发现结果和 configuration_source。
  • keil_connect / keil_disconnect / keil_reconnect:管理 UVSOCK 连接。
  • keil_load_project / keil_show_window:加载工程、显示 Keil 窗口(仅 auto 模式有意义)。
  • keil_get_status:当前 Debug 状态、目标是否运行。
  • keil_read_variable / keil_read_variables:按符号名读取单个/多个变量。
  • keil_eval_expression:求值 C 表达式。
  • keil_read_memory:按地址读取内存。

运行态通常可以读取变量;需要多个变量在同一时刻的一致快照时,先在 Keil 中停在断点上再读。

Keil 路径自动发现

按以下顺序查找包含 UV4.exe 和 UVSC64.dll 的 UV4 目录:

  1. keil_connect.keil_path 参数;
  2. KEIL_UV4_PATH 环境变量;
  3. KEIL_UV4_DIR 环境变量;
  4. Keil 注册表项;
  5. C:\Keil_v5\UV4、C:\Keil\UV4、D:\Keil_v5\UV4、D:\Keil\UV4、D:\tools\keil\UV4 等常见路径。

keil_uvsc_info 会返回 configuration_source、实际路径与加载错误,方便排查路径问题。

连接模式

attach(推荐)

Keil 中开启 Edit → Configuration → Other → UVSOCK,端口 4823;打开自己的工程并进入 Debug。然后:

{"mode":"attach","port":4823}

mode 省略时默认 attach,port 省略时默认 4823。attach 模式忽略 project_file,不会覆盖当前 Keil 工程,适合不同同事的不同工程路径。

Keil 重启或连接失效后可用 keil_disconnect / keil_reconnect。

auto

mode=auto 才会由 MCP 启动专用 Keil 进程,并可使用 project_file 打开工程。不会自动进入 Debug、下载或复位。

构建

依赖 .NET Framework 4.x 的 64 位 C# 编译器(csc.exe,Windows 自带)。

powershell -NoProfile -ExecutionPolicy Bypass -File .\build.ps1

产出:

  • bin\KeilUvscMcp.exe(稳定配置名,MCP 配置指向它即可,后续覆盖升级无需改配置);
  • bin\KeilUvscMcp-0.2.0.exe(版本化副本)。

注意:src\Program.cs 若在本机被 Claude Code 的 Write/Edit 落盘,会带 %TSD-Header-###% 加密头,csc.exe 读到的是密文会编译失败(CS1040 / CS0116)。用 bash 明文重写该文件后再构建即可。

在 MCP client 中配置

Claude Desktop(%APPDATA%\Claude\claude_desktop_config.json):

{
  "mcpServers": {
    "keil-uvsc": {
      "command": "D:\path\to\keil-uvsc-mcp\bin\KeilUvscMcp.exe"
    }
  }
}

Claude Code(.mcp.json 或全局配置):

{
  "mcpServers": {
    "keil-uvsc": {
      "command": "D:\path\to\keil-uvsc-mcp\bin\KeilUvscMcp.exe"
    }
  }
}

或指向仓库自带的 run.ps1(缺 exe 时会自动构建再启动)。

前提

  • Windows x64;
  • 已安装 Keil MDK(含 UV4.exe 和 UVSC64.dll);
  • Keil 中已开启 UVSOCK(Edit → Configuration → Other → UVSOCK,端口 4823);
  • 已打开工程并进入 Debug 模式(attach 模式下)。

自测

powershell -NoProfile -ExecutionPolicy Bypass -File .\test-protocol.ps1

许可

源码按 MIT 许可发布。UVSC64.dll 和 UVSOCK SDK 属 Keil(Arm),请从合法的 Keil 安装获取,不分发。

About

只读 MCP server:通过 Keil MDK 的 UVSC64.dll / UVSOCK 读取调试工程中的 C 符号、变量、表达式与目标内存,让 Claude Desktop / Claude Code 调试时无需切回 Keil 界面即可读取数据(attach 模式优先,无写/烧录/复位能力)。

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages