Skip to main content
Glama
irrumi
by irrumi

stm32_patch_user_code

Insert or replace custom code within STM32CubeMX USER CODE BEGIN/END markers, leaving generated init functions untouched. Safely patch C/C++ sources in specified sections.

Instructions

Args: file, section (e.g. PD, 2, WHILE, 4), content, mode (replace/append). Writes only between /* USER CODE BEGIN x / and / USER CODE END x */. Must fail loudly if the markers are missing or unbalanced, and must never touch generated init functions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesRelative or absolute path to C/C++ source file
modeNoMode: replace or appendreplace
contentYesCode content to insert between markers
sectionYesSection tag identifier (e.g. 0, 1, 2, WHILE, PV, PD, Includes)

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4.4/5.0
Behavior5/5

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

The description goes well beyond the schema by disclosing that writes are strictly confined to marked regions, that it must fail loudly on missing/unbalanced markers, and that generated init functions must never be touched. Since no annotations are provided, this behavioral disclosure is especially valuable for an agent deciding whether the operation is safe.

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

Conciseness5/5

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

The description is compact and information-dense: it lists the arguments, states the exact write boundary, and specifies failure and safety constraints in only two sentences. Every sentence earns its place with no filler.

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?

The description covers the essential invocation details, marker behavior, and failure constraints for a moderately complex patching tool. It does not describe return values or handling of non-existent files, but for a write-oriented tool with no output schema these are minor gaps given the strong behavioral guarantees provided.

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 description coverage is 100%, so the baseline is 3. The description adds value by giving concrete section examples (PD, 2, WHILE, 4), clarifying the mode options, and tying the content parameter to insertion between markers, which enriches the otherwise minimal schema descriptions.

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 clearly states the tool writes content only between USER CODE BEGIN/END markers, giving a specific verb and resource. This distinguishes it from sibling tools like stm32_generate_code and stm32_flash, which perform broader generation or flashing operations.

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

Usage Guidelines3/5

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

The usage context is implied: use this tool to safely modify user-editable sections in STM32-generated files. However, it does not explicitly name alternatives or state when not to use it, such as when regenerating code or modifying generated initialization logic.

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