stm32-rag-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., "@stm32-rag-mcpWhat is the GPIO_MODER register for STM32F407?"
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.
STM32 RAG MCP
一个以 Claude Code 插件 形式交付的 STM32 文档知识库。它从本地 datasheet 和 reference manual 中检索原文证据,通过 MCP 返回文档、revision、PDF 页码、章节、寄存器和 source SHA-256,再由 Claude 基于证据回答或生成代码。
当前版本是 evidence-first、lexical-first RAG:本地检索无需 embedding 模型或远程向量库;Claude Code 仍负责最终自然语言回答。证据不足时系统明确 abstain,不猜寄存器、地址或页码。
当前语料
系列 | 类型 | 文档 | 文件 | 页数 |
STM32F1 | datasheet | STM32F103C8 |
| 117 |
STM32F1 | reference manual | RM0008 Rev 21 |
| 1,136 |
STM32F4 | datasheet | STM32F405/407 |
| 203 |
STM32F4 | reference manual | RM0090 Rev 9 |
| 1,718 |
本地验证语料合计 4 份 PDF、3,174 页、42,839,844 bytes。download_manifest.csv 保存 SHA-256、实际镜像来源和 ST 官方文档页面。当前 PDF 来自公开镜像,索引不会把它们描述成“自动同步的最新版”;更新文档后必须重新校验 revision、SHA 和 citation。
仓库语料说明: 当前公开仓库已经包含上述 4 份 PDF,方便首次安装直接构建索引。PDF 仍应视为 ST 文档的再分发内容;更新或替换文件前请确认其来源和再分发许可。SQLite 索引是可再生构建产物,不提交到仓库。
Related MCP server: MCP Manuels
架构
STM32 PDF
-> SHA/provenance registry
-> PyMuPDF page/block parser
-> TOC + model-scope propagation
-> section/register-aware chunks
-> SQLite metadata + FTS5 BM25
-> exact technical-token rerank + abstention
-> MCP evidence tools
-> Claude Code answer with citations核心特点:
page-first:保留 physical PDF page、PDF label、可见页脚和异常标记;
scope-aware:区分 RM0090 的 F42/F43 RCC 章节与 F405/F407 RCC 章节;
register-aware:支持
GPIO_MODER/GPIOA_MODER到GPIOx_MODER的规范化,同时区分 F1 的GPIOx_CRL/CRH;deterministic:SQLite FTS5
unicode61 tokenchars '_'、固定重排和 index fingerprint;fail loud:PDF、schema、parser、chunker 或 corpus fingerprint 变化时拒绝旧索引;
read-only MCP:运行时不下载、不建库、不修改 PDF。
安装依赖
项目使用 uv.lock 固定依赖。已验证运行时:CPython 3.13.13、PyMuPDF 1.28.2、MCP 2.1.1。
uv sync --frozen --extra dev准备 PDF 与构建索引
克隆仓库后,4 份验证语料位于 reference_manual/,可先校验路径、大小和 SHA-256:
uv run stm32-rag doctor --corpus reference_manual --manifest download_manifest.csv --json预期输出 ok: true,包含 4 documents、3,174 pages 和 42,839,844 bytes。manifest 中的 source 是原始镜像地址,official_page 是 ST 官方文档页;它们用于 provenance 记录,不会在正常启动时自动访问网络。
如果需要重新下载或替换 PDF,下载器只会在显式执行时联网,并将结果写入被 .gitignore 排除的 download_results.csv:
uv run python download_stm32_docs.py下载完成后必须重新校验 manifest 中记录的文件路径、字节数和 SHA-256;下载器报告 failed 时会以非零状态退出。确认语料完整后,构建本地 SQLite FTS5 索引:
uv run stm32-rag index \\
--corpus reference_manual \\
--manifest download_manifest.csv \\
--db assets/stm32-index.sqlite3 \\
--index-manifest assets/index-manifest.json \\
--json索引构建会在临时数据库中完成 integrity check 和 fingerprint 校验,成功后才原子替换 assets/stm32-index.sqlite3。索引不会提交到 GitHub;更新 PDF、parser、chunker 或 retrieval policy 后都应重新构建。
构建完成后再次检查索引:
uv run stm32-rag doctor \\
--corpus reference_manual \\
--manifest download_manifest.csv \\
--db assets/stm32-index.sqlite3 \\
--jsonCLI 查询
uv run stm32-rag search --db assets/stm32-index.sqlite3 --corpus reference_manual --manifest download_manifest.csv --chip STM32F407 --query GPIO_MODER --jsonuv run stm32-rag search --db assets/stm32-index.sqlite3 --corpus reference_manual --manifest download_manifest.csv --chip STM32F407 --query "USART_CR1 TE bit" --json不存在或跨系列不兼容的寄存器会返回 abstained: true,不会静默取消 chip filter。
重建索引
更新 PDF、parser 或 chunker 后运行:
uv run stm32-rag index --corpus reference_manual --manifest download_manifest.csv --db assets/stm32-index.sqlite3 --index-manifest assets/index-manifest.json --jsonindex builder 在临时 SQLite 中完成事务、integrity check 和 fingerprint 校验后再原子替换目标文件;失败不会破坏旧索引。
Claude Code 插件
插件组件:
.claude-plugin/plugin.json.mcp.jsonskills/stm32-docs/SKILL.mdMCP tools:
search_stm32_docs、get_register、search_peripheral
验证插件:
claude plugin validate C:/Users/Administrator/rag_embedding --strict本地开发加载:
claude --plugin-dir C:/Users/Administrator/rag_embedding启动后在 Claude Code 中检查 /mcp,技能命令为:
/stm32-rag:stm32-docs.mcp.json 使用 ${CLAUDE_PLUGIN_ROOT} 定位只读 corpus/index,使用 ${CLAUDE_PLUGIN_DATA} 保存 uv 环境/cache。首次在新安装位置启动时,uv 可能从 lockfile 安装 Python 依赖;它不会自动下载 STM32 PDF、生成 SQLite 索引或下载 embedding 模型。公开仓库中的 .mcp.json 需要在本地语料和索引准备完成后使用。
MCP 工具
search_stm32_docs
综合查询,可传:query、chip、family、document_type、peripheral、register、top_k。
get_register
精确寄存器查询,必须传 chip 和 register。适合地址 offset、reset value、bit field 和清除语义。
search_peripheral
外设范围查询,必须传 chip 和 peripheral,可附加具体问题。
三个工具都只返回 evidence/citations,不返回一个伪装成权威的本地生成答案。
Citation 语义
每条 evidence 包含:
document / DocID / revision / type / family;
source path、SHA-256、mirror URL、ST official page;
physical PDF pages、PDF labels、source footers;
section path、register、chip scope;
warnings 和 page anomalies。
RM0008 p.67–80 是重要异常:PDF physical/page label 仍为 67–80,但可见页脚错误写成 67/80…80/80。系统保留 canonical page 与 source footer,并标记 embedded_total_mismatch。
评测与测试
uv run pytest -q当前测试覆盖:
corpus 路径、SHA、页数和 downloader 无副作用 import;
RM0008 页码异常;
RM0090 scope 与无效 TOC anchor;
F4 datasheet 横向页;
register chunk 跨页与确定性 ID;
SQLite schema、FTS5、只读和 stale-index 防护;
CLI、MCP in-memory client 和真实 stdio 子进程;
eval/golden_queries.json的 20 个正例 + 5 个负例 hard gate。
正例要求 Recall@5 / citation hit 至少 90%;当前 20/20 正例首条命中定义页,5/5 负例 abstain。
已知限制
当前检索模式为
lexical,未打包 embedding 模型或 learned reranker;接口扩展点已保留,但响应不会谎称 hybrid。F4 datasheet p.14–15、62–70 为旋转横向表格。系统保留原文/rotation 并标记
table_layout_degraded;精确 pin/Alternate Function 查询会优先匹配非降级 pinout 表,无法建立可靠映射时显式 abstain。尚未加入 SVD 结构化寄存器数据库、Errata、Application Note、HAL/LL、示例代码或其他 STM32 family。
download_stm32_docs.py只在显式执行时联网,并写download_results.csv;它不会覆盖 verified corpus manifest。MVP 正常运行不调用 downloader。
项目计划
完整背景和后续路线见 STM32_RAG_MCP_Project_Plan.md。本版优先兑现计划中的核心目标:从 STM32 文档找到可靠证据、保留页码和来源,并通过 MCP 供 Claude 主动查询。
Available Tools
3 toolsget_registerBRead-onlyIdempotent
Retrieve the definition and cited evidence for one STM32 register.
A concrete chip model is required so similarly named registers from incompatible STM32 families or subfamilies are not silently mixed.
| Name | Required | Description | Default |
|---|---|---|---|
| chip | Yes | ||
| query | No | ||
| top_k | No | ||
| register | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| query | Yes | |
| filters | Yes | |
| results | Yes | |
| warnings | Yes | |
| abstained | Yes | |
| abstain_reason | Yes | |
| retrieval_mode | Yes | |
| schema_version | Yes | |
| index_fingerprint | Yes | |
| retrieval_policy_version | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Annotations already declare the operation as read-only, idempotent, and non-destructive, so the description does not need to restate those. It adds useful context about chip-model specificity and the 'cited evidence' aspect of the return, but it does not disclose more about retrieval behavior or limitations beyond that.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is short, front-loaded with the core purpose, and adds a necessary usage constraint in the second sentence. Every sentence earns its place with no wasted words.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The description covers the main purpose and the key chip/register requirement, and an output schema exists to document return values. However, it is incomplete for the optional parameters and does not position the tool relative to its siblings, so an agent may not fully understand how to use query and top_k correctly.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, so the description must carry the burden. It clarifies the role of 'chip' and 'register' implicitly, but it completely ignores the 'query' and 'top_k' parameters, leaving their purpose and interaction with the 'cited evidence' behavior unclear.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states a specific verb ('Retrieve') and a specific resource ('definition and cited evidence for one STM32 register'). It clearly indicates this is about a single register, which distinguishes it from the broader search siblings, though it does not explicitly name those alternatives.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description gives a clear usage precondition: a concrete chip model is required to avoid mixing similarly named registers. However, it does not provide guidance about when to prefer this tool over the sibling tools search_stm32_docs or search_peripheral, leaving that to inference.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
search_peripheralBRead-onlyIdempotent
Search one STM32 peripheral with chip-specific scope and citations.
| Name | Required | Description | Default |
|---|---|---|---|
| chip | Yes | ||
| query | No | ||
| top_k | No | ||
| peripheral | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| query | Yes | |
| filters | Yes | |
| results | Yes | |
| warnings | Yes | |
| abstained | Yes | |
| abstain_reason | Yes | |
| retrieval_mode | Yes | |
| schema_version | Yes | |
| index_fingerprint | Yes | |
| retrieval_policy_version | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Annotations already declare readOnlyHint=true, idempotentHint=true, and destructiveHint=false, so the safety profile is covered. The description adds useful context by noting chip-specific scoping and citations, but it does not disclose operational details such as pagination, failure modes, or result boundaries beyond the annotations.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single efficient sentence with no filler. It front-loads the action and resource and packs the scope and citation behavior into one clause.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple read-only search tool, the annotations and output schema cover safety and return-value concerns. However, the description still leaves parameter semantics for query/top_k and usage differentiation from siblings under-specified, creating moderate gaps for correct invocation.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, and the description does not explain the semantics of query or top_k. It only loosely implies that chip and peripheral are the search scope; the free-text query and result-limit parameters remain effectively undocumented.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('Search'), the resource ('one STM32 peripheral'), and key constraints ('chip-specific scope and citations'). This is specific enough to distinguish it from broader doc or register lookups, though it does not explicitly contrast with sibling tools like search_stm32_docs or get_register.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance is given about when to use this tool versus search_stm32_docs or get_register. The phrase 'one STM32 peripheral' implies a narrow scope, but the description never states conditions, exclusions, or alternatives.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
search_stm32_docsARead-onlyIdempotent
Search STM32 datasheets and reference manuals and return cited evidence.
Use chip/family/document_type filters whenever known. The tool does not generate an answer; it returns source snippets, page-level citations, model scope, warnings, and an explicit abstention state.
| Name | Required | Description | Default |
|---|---|---|---|
| chip | No | ||
| query | Yes | ||
| top_k | No | ||
| family | No | ||
| register | No | ||
| peripheral | No | ||
| document_type | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| query | Yes | |
| filters | Yes | |
| results | Yes | |
| warnings | Yes | |
| abstained | Yes | |
| abstain_reason | Yes | |
| retrieval_mode | Yes | |
| schema_version | Yes | |
| index_fingerprint | Yes | |
| retrieval_policy_version | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Beyond the read-only/idempotent annotations, the description reveals critical behavior: it returns source snippets, page-level citations, model scope, warnings, and an explicit abstention state, and it explicitly does not generate an answer. This helps the agent set expectations about abstention and citation-style output. No contradiction with annotations.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is three tightly written sentences with no filler. It front-loads the core action, then provides filter guidance and a clear behavioral boundary. Every sentence earns its place.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the output schema exists and annotations cover safety, the description covers the main invocation needs: what it searches, what it returns, and how to tighten filters. The mention of an abstention state covers no-match behavior implicitly. A slight gap is not explaining how register/peripheral filters relate to the siblings, but that is not essential for a correct call.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema has 0% description coverage, so the description must compensate. It mentions chip, family, and document_type as useful filters, but does not explain query, top_k, register, or peripheral semantics. Titles and defaults give minimal clues, so the description only partially compensates for the missing schema documentation.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description opens with a specific verb and resource: 'Search STM32 datasheets and reference manuals and return cited evidence.' It also clarifies what the tool is not ('does not generate an answer'), which distinguishes it from generative Q&A tools. Sibling tools get_register and search_peripheral are narrower, so the broad scope is enough to differentiate.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description gives actionable guidance: 'Use chip/family/document_type filters whenever known,' which helps an agent improve result relevance. It does not explicitly name alternatives or state when-not-to-use, but the purpose clearly implies this is the tool for evidence-based documentation searches. No misleading or missing context.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
3 tool updates
v0.1.0- First observed
get_register - First observed
search_peripheral - First observed
search_stm32_docs
TDQS
Scored across 3 tools
General search_stm32_docs overlaps semantically with get_register and search_peripheral, since a broad docs search could return register or peripheral content. The specialized tools are clearly scoped, but agents may still hesitate between the general and resource-specific search paths.
All tool names follow a consistent verb_noun snake_case pattern: search_stm32_docs, get_register, and search_peripheral. The two search tools share a predictable prefix, and get_register fits the same structural style.
Three tools is compact but well-scoped for a documentation RAG server: general docs search, register lookup, and peripheral search. Each tool covers a distinct retrieval need without unnecessary padding.
Core retrieval workflows are covered: broad documentation search, register-level lookup, and peripheral-scoped search with citations. Minor gaps exist around discovering available chip models or document lists, but agents can likely work around them using the general search tool.
Maintenance
Related MCP Connectors
Page-cited retrieval for embedded docs, datasheets, MISRA, CMSIS, and RTOS references.
Cited, versioned knowledge for agents: retrieve sourced passages and propose owner-approved fixes.
Retrieve citation-ready technical context and coordinate evidence-backed work between AI agents.
Cited product-compliance ground truth for AI agents. Never generates; always cites.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceProvides project documentation, database schema, business rules, and search capabilities as context for Claude Code, enabling more accurate code generation and query writing.-
- AlicenseNot gradedqualityDmaintenanceEnables Claude Desktop to read and search through PDF technical manuals, answering questions in natural language with citations.MIT
- FlicenseNot gradedqualityBmaintenanceEnables querying hardware manuals (PDF/HTML) using local RAG with ChromaDB and embeddings, allowing Claude Code to look up pinouts, registers, and specifications.-
- AlicenseAqualityBmaintenanceProvides deterministic, read-only retrieval of authoritative EU legal materials, including legislation, case law, and EDPB/EDPS documents, with exact text, structural identifiers, and provenance.16MIT