Skip to main content
Glama

跨会话状态:保存/读取上次调试上下文

session_state

Persist and restore Keil debug session state (symbol files, breakpoints, serial settings) to a JSON file for cross-session continuity, with actions like show, save, load, and clear.

Instructions

把「这次调试是怎么配起来的」落盘成 state.json,供下个会话接续,解决 MCP 工具无状态、会话一断上下文全丢的问题(最典型的是符号文件漂移:接着上次调试却加载了别的 .axf,表达式集体解析失败)。记录内容:默认工程、符号文件、调试会话标记、内部断点/数据断点清单、串口端口与波特率、SVD 器件、snapshot_diff 基线等。action:show(默认,看当前上下文与磁盘态差异)/ save(落盘,旧文件自动备份为 .bak)/ load(读回;apply=true 才执行可恢复动作)/ clear(删除,需 confirm=true)。两条约定:① 只存观察到的,采不到的字段标 available=false 与原因,不填默认值假装成功;② load 默认只对比不应用,apply=true 也只恢复主机侧可逆项(目前仅符号文件切换),断点/内存/运行态等目标侧状态永不自动重放。路径可用 path 指定,或用环境变量 MDKDEBUG_STATE_FILE,默认 ~/.mdkdebug/state.json。 【输出控制】本工具返回体可能较大,额外接受三个可选参数:compact=true(精简)/ max_lines=N(限制列表条数)/ full=true(强制全量)。默认都不传=行为不变;被裁掉的内容一定会在返回体的 output 字段里如实上报(truncated/dropped/trimmed/hint),不会静默丢数据。也可用环境变量 MDKDEBUG_COMPACT=1 / MDKDEBUG_MAX_LINES=N 设全局默认。 【参数】必填: 无;可选: action, path, apply, confirm, compact, max_lines, full 【调用示例】{} 【风险】中——会改变目标状态或占用共享资源(调试态/串口/Keil 实例),必要时可回退。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fullNo强制返回全量:忽略 compact/max_lines 与对应环境变量的默认值。当上面两项让你只看到部分数据、而你要据此下结论时,用它取回完整结果。
pathNo
applyNo
actionNoshow
compactNo精简返回体:去掉空值字段,把列表元素中取值完全相同的字段提到 output.shared,并把 usage/note/hints 之类**说明性**长文本截断到 200 字符(数值与内容字段不动)。被裁掉的东西都会列在 output 里,绝不静默丢弃。不传则不改行为(受 MDKDEBUG_COMPACT 影响)。
confirmNo
max_linesNo限制返回的列表条数(只作用于元素为对象的列表,如 results/items/tools):最多 N 条,其余丢弃并在 output.truncated/dropped/hint 里如实上报。0 或省略=不限(受 MDKDEBUG_MAX_LINES 影响)。

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.8

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

All annotations are false (readOnlyHint, openWorldHint, idempotentHint, destructiveHint), so the description carries the full behavioral burden — and it over-delivers. It discloses the destructive clear action (requires confirm=true), reversal path (.bak backup, '必要时可回退'), the honesty convention (unobservable fields marked available=false, never faked to default), and the output-truncation guarantee (truncated/dropped/trimmed/hint always reported, data never silently dropped). The only tension is clear-action vs destructiveHint=false, but the confirm gate, .bak backup, and re-creatable state file make this guarded destructive behavior, so I do not treat it as a contradiction.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is dense but well-sectioned (purpose, content, actions, conventions, path, output-control, params, risk) and front-loaded with the core purpose and the key problem it solves. The output-control section is verbose relative to its importance, and the section markers are a bit processor-like, but every section carries genuinely useful information for a 7-parameter complex tool, so it earns its length.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (7 params, 4 actions, env-var fallbacks, output truncation, risk) the description covers nearly everything: purpose, recorded content, all action semantics, two behavioral conventions, path resolution, output control, and a medium-risk disclosure. An output schema exists so return-shape details are covered. The one gap is a call example of {} that gives the agent no concrete invocation template — a minor omission against an otherwise complete definition.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is only 43% — action, path, apply, confirm have titles but no descriptions. The description compensates for exactly these gaps: it enumerates action values (show/save/load/clear) with semantics, explains apply=true recovery scope, requires confirm=true for clear, and gives path resolution (path param vs MDKDEBUG_STATE_FILE env var vs ~/.mdkdebug/state.json default). The schema already documents compact/max_lines/full. This is solid supplementation of the weaker schema fields, though not exhaustive on every parameter.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb+resource: persist/load debug configuration (state.json) to carry context across MCP sessions, and names the concrete problem it solves (symbol file drift, .axf mismatch causing expression failures). It lists the exact recorded content (project, symbol file, breakpoints, serial port, SVD device, snapshot_diff baseline), which clearly differentiates it from siblings like get_status, wait_state, target_info, and direct debug mutators (set_breakpoint, run, reset). Purpose is unambiguous and distinct.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives a clear lifecycle guide: show (default) to inspect current-vs-disk difference, save with .bak auto-backup, load with apply=false for compare-only and apply=true for recoverable items, clear requiring confirm=true. It explicitly states when load applies versus not (host-side reversible items only; target-side state never auto-replayed). It does not name sibling alternatives or state when NOT to use the tool, but given no sibling overlaps with cross-session persistence, the per-action guidance is strong enough to earn a 4.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.