Keil Debug MCP
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., "@Keil Debug MCP diagnose the last hard fault and show the faulting line"
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.
Keil Debug MCP (KDM)
MCP server cho AI agent (Claude Code, Devin...) đọc và ghi trạng thái vi điều khiển ARM Cortex-M trong phiên debug Keil uVision đang mở, qua giao diện UVSOCK của Keil. Chip vẫn chạy khi đọc và ghi; KDM không tự dừng chip.
Thiết kế đầy đủ: docs/PLAN.md. Ghi chú UVSC và số đo trên board thật: docs/uvsc_api_notes.md.
Làm được gì
Đọc biến toàn cục và static, struct, mảng struct (kiểu lấy từ DWARF của
.axf), thanh ghi lõi, call stack, vùng nhớ, thanh ghi ngoại vi theo SVD.watch: lấy mẫu nhiều biến tới 20 Hz (gộp biến SRAM gần nhau vào một lần đọc); luật trongwatch.toml, flight recorder, baseline.diagnose_fault: giải mã CFSR/HFSR, khung stack lúc lỗi, chỉ ra file:dòng.kdm_statuskiểmfirmware_match: file.axftrên đĩa có khớp firmware trong chip không.Mức
write:write_var,write_memory,test_step(ghi lệnh test, chờ điều kiện, lấy mẫu; tự dừng khẩn khi vi phạm luật hoặc hết giờ) vàestop.Nhật ký bug (
journal) và log phiên.
Related MCP server: ude-mcp
Yêu cầu
Windows 10/11.
Keil MDK 5 có
UV4\UVSC64.dll(đã thử uVision 5.31, ST-Link, STM32F103C8).Python 3.11 trở lên, 64-bit (để nạp
UVSC64.dll).
Header UVSC (UVSC_C.h, UVSOCK.h, gói Arm apnt_198) không cần khi chạy và không kèm trong repo vì thuộc bản quyền Arm. Chỉ cần khi sửa src/kdm/backends/uvsc/bindings.py.
Cài đặt
git clone https://github.com/anhzudeptrai2/keilc-debug-mcp.gitcd keilc-debug-mcppy -3 -m venv .venv.\.venv\Scripts\python.exe -m pip install -e ".[test]"Muốn đúng các phiên bản thư viện đã thử: cài requirements.lock trước (pip install -r requirements.lock) rồi chạy lệnh trên.
Bật UVSOCK trong Keil
Edit > Configuration > Other > UVSOCK (TCP/IP) Settings: tick
Enable, khởi động lại uVision. Nếu Windows Firewall hỏi, không cho truy cập từ mạng.Mở project, nối board, bấm Start/Stop Debug Session.
KDM tự đọc số cổng từ cấu hình Keil (uvsc_port = "auto"); có thể đặt cố định trong profile. Chi tiết: docs/uvsc_api_notes.md mục 8 và 14.
Gắn vào dự án Keil
.\.venv\Scripts\kdm.exe init "C:\path\to\your-keil-project".\.venv\Scripts\kdm.exe doctor --project "C:\path\to\your-keil-project"init tạo .kdm/ (profile.toml, watch.toml, journal.md), CLAUDE.md và thêm .gitignore cho dự án; không ghi đè file đã có.
Lệnh | Việc làm |
| Tạo |
| Tìm mọi |
| Kiểm tra Python/DLL, Keil, profile, axf, SVD |
| Thử kết nối và in |
| In sự kiện log mới nhất |
| Chạy MCP server qua stdio |
Dùng với Claude Code
claude mcp add --scope user kdm -- "C:\path\to\keilc-debug-mcp\.venv\Scripts\python.exe" -m kdm.serverKDM tìm
.kdm/từ thư mục làm việc đi lên. Muốn cố định dự án: thêm--env KDM_PROJECT=C:\path\to\your-keil-projectvào trước tênkdmtrong lệnh trên, hoặc truyềnproject_dirkhi gọi tool.Quyền: chép templates/claude_settings.json vào settings của Claude Code. Tool đọc được cho phép sẵn; tool điều khiển, ghi và
read_periph(vì cóforce) ở chế độ hỏi.Quy trình debug chung: chép templates/CLAUDE.user.md vào
~/.claude/CLAUDE.md.
Dùng với Devin (Devin Desktop)
Chép templates/devin_mcp_config.json thành .devin\mcp_config.local.json trong thư mục mở bằng Devin, sửa hai đường dẫn, rồi kiểm bằng devin mcp list. File này chứa đường dẫn trên máy bạn: đừng commit nó vào repo dự án.
Mức quyền và ghi
Mặc định level = "read". Mức cao hơn do bạn bật trong .kdm/profile.toml của dự án:
[safety]
level = "write" # read | control | write
write_regions = ["0x20000000-0x20004FFF"] # chỉ SRAM
write_allow = ["app.cmd", "app.test_cm"] # hoặc tiền tố "app.*"; rỗng = không hạn chế biến
estop = "app.cmd = 99" # lệnh dừng khẩn; biến phải nằm trong write_allowcontrolthêm halt/run/step/reset/breakpoint,writethêm các tool ghi. Danh sách tool MCP đổi theo mức quyền.Luôn từ chối ghi Flash và option bytes (
0x00000000-0x1FFFFFFF), ngoại vi (0x40000000-0x5FFFFFFF) và vùng hệ thống (0xE0000000trở lên), kể cả khi nằm trongwrite_regions.KDM không bao giờ tự halt để ghi. Mỗi lần ghi được đọc lại để kiểm (
verified) và ghi vào log phiên.test_step: ghi lần lượt các lệnh, chờwait_until, lấy mẫu; vi phạm luật mức error/critical trongwatch.tomlhoặc hết giờ thì gọiestop.Chưa kiểm uVision ghi một word 32-bit bằng một lần truy cập bus hay nhiều lần. Biến cho agent ghi nên có kiểu không quá 32 bit và firmware phải chịu được việc giá trị đổi bất kỳ lúc nào.
Trạng thái
Phần | Trạng thái |
27 tool MCP, resource, prompt, đổi danh sách tool theo mức quyền | Chạy qua stdio; đã dùng với Claude Code và Devin Desktop |
Đọc qua Keil ( | Chạy với uVision 5.31 thật khi chip đang chạy; tự nối lại khi mất kết nối |
Struct, mảng struct, static | Qua DWARF của |
| Đã đo 60 s trên project thật (mỗi lời gọi UVSC khoảng 30 ms) |
Ghi: | Đã thử trên board STM32F103C8 khi chip đang chạy |
Fault lab ( | Đã chạy trên STM32F103C8: lỗi NULL, Thumb, bus, chia 0, không căn hàng, tràn stack, ISR kẹt, clock tắt đều nhận đúng loại và đúng dòng |
halt/run/step/reset/breakpoint, | Có trong giao diện và chip giả; backend Keil chưa làm |
Chip | Mới thử STM32F103C8 (Cortex-M3); có profile |
Thử không cần Keil
Đặt biến môi trường KDM_FAKE_BACKEND trỏ tới file JSON mô tả chip giả (cấu trúc: xem target_spec trong tests/conftest.py và docstring của backends/fake.py). Chỉ dùng để phát triển; dữ liệu không đến từ phần cứng.
Test
.\.venv\Scripts\python.exe -m pytestTest dùng chip giả và DLL giả nên không cần Keil hay board; CI chạy cùng bộ test trên Windows.
An toàn và riêng tư
Mọi biểu thức đi qua
safe_expr; backend chỉ nhận bản in lại đã kiểm.Thanh ghi dữ liệu/FIFO bị chặn trên mọi đường đọc, kể cả qua con trỏ,
read_memory, luật và điều kiện breakpoint.KDM không nạp Flash và không ghi ngoại vi.
Kết quả tool (giá trị biến, đoạn source, đường dẫn) được gửi tới nhà cung cấp mô hình AI. Kiểm tra NDA trước khi dùng cho dự án công ty; tắt đoạn source bằng
[privacy] source_snippets = false.
Giấy phép
MIT, xem LICENSE.
Keil, uVision và UVSC là của Arm Limited. Repo này không kèm phần mềm, DLL hay header của Arm; bạn cần cài Keil MDK với giấy phép của riêng bạn.
Available Tools
16 toolsbaselineC
Lưu giá trị lúc chạy đúng (save) hoặc so với hiện tại (diff).
Inputs: name (required), action (required), exprs, group, +1 more.
call_stackARead-only
Call stack (và biến cục bộ nếu locals=true). Chỉ khi chip đang dừng.
Inputs: locals, max_frames.
diagnose_faultA
Phân tích HardFault/MemManage/BusFault/UsageFault: loại lỗi, file:dòng, nguyên nhân xếp hạng. Lưu báo cáo.
Inputs: no named parameters.
journalB
Nhật ký bug: read lúc đầu phiên; append khi tìm ra nguyên nhân (người dùng duyệt).
Inputs: action (required), fix, rule, limit, +5 more.
kdm_statusARead-only
Trạng thái kết nối, project, chip, firmware_match, lỗi, freeze/watchdog, mức quyền. Tự kết nối. Gọi đầu tiên.
Inputs: project_dir.
lookupCRead-only
Tra đúng một trong: symbol, pattern (+kind), addr -> hàm/dòng, file_line -> addr.
Inputs: addr, kind, symbol, pattern, +1 more.
read_logCRead-only
Đọc sự kiện trong log phiên của KDM theo bộ lọc.
Inputs: tool, event, limit, since, +1 more.
read_memoryBRead-only
Đọc khối nhớ (<= 4096 byte), trả hex theo word. Vùng có tác dụng phụ khi đọc bị chặn.
Inputs: addr (required), length (required), width.
read_outputCRead-only
Output debug: printf qua ITM, cửa sổ serial, Event Recorder.
Inputs: since, channel, max_lines.
read_periphA
Thanh ghi ngoại vi giải mã theo SVD, vd ["TIM2", "USART1.SR"]. force=true (mức control + reason) mới đọc thanh ghi có tác dụng phụ.
Inputs: names (required), force, reason.
read_registersARead-only
Thanh ghi lõi (cần halt) và/hoặc thanh ghi lỗi SCB đã giải mã (đọc được khi chạy).
Inputs: set.
read_varsBRead-only
Đọc biến/biểu thức chỉ đọc (vd "g_motor.duty", "buf[3]", "p->state"). Mảng dài được tóm tắt.
Inputs: exprs (required), fmt, max_depth, max_elems.
recorderB
Flight recorder chạy nền: giữ lịch sử biến ngay trước lúc lỗi; dump để xem.
Inputs: action (required), group, rate_hz, window_s.
rtos_tasksBRead-only
Danh sách task RTOS, trạng thái, ưu tiên, stack.
Inputs: no named parameters.
snapshotCRead-only
Biến + ngoại vi + kết quả luật tức thời trong một lần gọi (nhóm khai báo trong watch.toml).
Inputs: exprs, group, periph.
watchBRead-only
Lấy mẫu biến theo thời gian khi chip chạy: thống kê, vi phạm luật; until dừng khi điều kiện đúng.
Inputs: exprs, group, until, duration_ms, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 16 tools
The large family of read_* tools is mostly differentiated by data source (variables, memory blocks, core registers, SVD-decoded peripherals, ITM/serial output, session log), so an agent can pick correctly. Minor overlap remains between read_vars and read_memory, and between watch (time-sampled) and snapshot (instant sample of vars+peripherals+rules), which require reading descriptions carefully to separate.
Several conventions coexist: verb_noun (read_output, read_vars, diagnose_fault), bare nouns (baseline, journal, recorder, watch, snapshot), prefixed status (kdm_status), and noun phrases (rtos_tasks, call_stack, read_log). Individual names are readable but there is no single predictable pattern.
16 tools is at the upper end of the comfortable range, but a full embedded-debug workflow legitimately needs status, inspection, tracing, and fault analysis surfaces. Each tool appears to map to a distinct debugging need rather than being filler.
Inspection, tracing, and fault analysis are well covered (vars, memory, registers, peripherals, watch, recorder, call stack, diagnose_fault, journal). However, the surface is read-only: there are no execution-control tools (halt/run/step/reset), no breakpoint management, and no variable/memory write, which are core debugger operations an agent will likely need.
Maintenance
Related MCP Connectors
Drive real devices from your AI Coding tool. Embed a client SDK (Unity, Godot, Flutter, iOS/macOS, Android, React Native, Web) in your app, then capture screenshots, traverse the UI tree, inject taps and key events, and run automated test tasks on the physical device over a secure relay.
Shared debugging memory for AI coding agents
AI-native programming language and toolchain for accountable, verifiable agent-driven development.
Design circuits, simulate and verify embedded firmware, and lay out PCBs with AI agents.
Related MCP Servers
AlicenseNot gradedqualityDmaintenanceEnables AI assistants to debug ARM Cortex-M targets via GDB and OpenOCD, supporting attach, breakpoints, stepping, register/memory inspection, and SVD peripheral decoding.MIT- AlicenseNot gradedqualityCmaintenanceEnables AI agents to control TriCore/AURIX debug sessions, including workspace loading, target connection, flashing, run control, breakpoints, and reading variables, registers, memory, and call stacks via the UDE Object Model.1MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to compile, debug, sample, and inspect MCU firmware through J-Link/pyOCD or a mock engine, including breakpoints, watchpoints, single-stepping, register access, and flash dump operations.MIT
- AlicenseAqualityBmaintenanceAn MCP server that lets AI tools drive Keil uVision debugging sessions for ARM Cortex-M targets, enabling expression/variable reads, memory access, run control, breakpoints, and trace capture.448MIT