fw-context-mcp
The fw-context-mcp server gives AI assistants a compiler-accurate, indexed understanding of embedded C/C++ firmware (parsed via libclang and compile_commands.json), enabling precise code exploration without reading raw source files.
Search & Discovery
search_code— Full-text FTS5 search over indexed symbols with progressive fallbacklookup_symbol— Find symbols by exact name or prefix (e.g.,uart_finds all UART symbols)smart_search— Natural language → FTS5 keywords via Ollama for multi-phase searchsemantic_search— Concept-based search using pre-computed embeddings (e.g., "power saving modes")
Code Understanding
get_source— Exact function/method/enum body using libclang extentsget_symbol_context— One-shot rich context: body + callers + callees + LLM analysisget_file_map— Structural overview of all symbols in a file, grouped by kindexplain_symbol— Plain-English explanation of a symbol's purpose, inputs, outputs, and side effectsget_file_analysis— Pre-computed LLM summary of an entire source file's responsibilities
Call Graph & Dependencies
find_callers— Direct callers of a function, including indirect function pointer callsfind_all_callers_recursive— Transitive callers (BFS up to configurable depth) for impact analysisfind_callees_recursive— Transitive callees to understand a function's dependenciesfind_call_path— Shortest call path between two functionsfind_references— All references: calls, reads, member accesses, and pointer assignmentsfind_dead_code— Functions never called, classified asdeadorpossibly_deadfind_hotspots— Most-called functions ranked by caller countfind_wrapper_callers— Wrapper/adapter classes that call methods of a driver classfind_indirect_call_sites— Where a function pointer field or variable is actually invokedfind_indirect_targets— Which functions are assigned to a function pointer field or parametertrace_data_flow— How a data type flows through function signatures to a target function
C++ Class & Template Analysis
get_inheritance_chain— Base and derived classes with optional full transitive hierarchyget_class_members— All methods, fields, constructors, and nested types of a class/structget_method_overrides— Virtual dispatch chain: what a method overrides and what overrides itget_template_instances— All concrete instantiations of a class or function template
Index Maintenance
get_active_build— Index health, staleness status, and background reindex progresslist_projects— All indexed firmware projects with statisticsreindex_file— Re-parse a single file after editing for fast incremental updatesreset_index— Delete the entire index to prepare for a full rebuildcheck_ollama— Verify Ollama availability and configured model installation
Allows AI assistants to understand and navigate Arduino firmware codebases by indexing them via compile_commands.json.
Provides optional natural-language search and symbol explanation capabilities by leveraging local LLMs via Ollama.
Allows AI assistants to understand and navigate PlatformIO-based embedded firmware projects.
Click on "Install 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., "@fw-context-mcpWhat does modem_parser_oob_init do?"
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.
fw-context
Build-aware code intelligence for AI coding agents working on embedded C and C++ firmware.
fw-context builds a persistent semantic index from compile_commands.json and the libclang AST, then exposes it to coding agents through MCP. Instead of reconstructing your firmware through repeated file reads and text searches, the agent can query the program structure produced by the active build configuration.
It helps agents answer questions such as:
Which implementation is active in this build?
Who calls this function, directly or indirectly?
Where is this callback registered?
Which function-pointer assignments can reach this call site?
Which code is excluded by preprocessing?
What will be affected if this API changes?
How does execution flow from an ISR to application code?
The goal is not to give the model more source code. It is to give it the smallest useful, build-aware context needed for the current task.
Results from a real firmware review
In the included firmware review case study, fw-context was used on an nRF52/Mbed OS project containing approximately 67,000 lines of C and C++:
115 changed files reviewed by 8 parallel subagents
19 findings across memory safety, concurrency, API use and dead code
9 findings that depended on semantic relationships not available from ordinary text search alone
approximately 54,000 context tokens used by fw-context queries
an estimated 5.8 million tokens for the equivalent broad
grepand file-reading workflow
The case study includes the review output, methodology and per-tool token analysis so the claims can be inspected rather than treated as a black-box benchmark.
Related MCP server: Semantic Code Search MCP Server
Quick start
Prerequisites
Python 3.11 or newer
libclang
a project that can produce
compile_commands.jsonan MCP-capable coding agent such as Claude Code or OpenCode
Ollama is optional. It is used only for local semantic enrichment and symbol explanations; the core compiler-derived index does not require it.
Install via pip (recommended)
pip install fw-context-mcpInstall the current source version
git clone https://github.com/turbyho/fw-context-mcp.git ~/.fw-context/src
cd ~/.fw-context/src
make installRegister fw-context with the supported coding agents detected in your project:
fw-context initBuild and index the firmware:
cd /path/to/your/firmware
fw-context index --buildThen restart the coding agent and ask it questions about the project. The index is persistent and incremental; after the initial run, changed translation units are reprocessed instead of rebuilding the entire index.
See the Quick Start and Installation Guide for platform-specific setup and supported build systems.
What fw-context changes
Without a semantic project index, an AI coding agent usually starts by opening files, searching for names, following includes and trying to infer relationships that are implicit in the build. In embedded firmware this reconstruction is often the dominant part of the task.
That approach can fail in predictable ways:
reviewing source files that are not part of the active build
following the wrong preprocessor branch
missing callback registrations and indirect calls
selecting an inactive driver or platform implementation
treating declarations found by text search as reachable code
consuming large amounts of context on vendor code and unrelated files
fw-context moves much of that reconstruction into a reusable compiler-derived index. The agent can request exact symbol bodies, callers, callees, references, active macros, callback relationships, inheritance edges and other targeted information without reading whole source trees.
Why embedded firmware is different
In many application-level projects, the source files visible in the repository are reasonably close to the program being executed. Embedded C and C++ projects often have a much larger gap between the source tree and the resulting program.
The active firmware depends on factors such as:
compiler flags and preprocessor definitions
target, board and product configuration
include paths and generated headers
Kconfig and Devicetree selections
selected driver and HAL implementations
templates, inheritance and virtual dispatch
callbacks, interrupt handlers and function pointers
vendor SDK and RTOS configuration
A repository may therefore contain several plausible implementations of the same subsystem while only one is compiled for the selected target. An agent can reason convincingly about the wrong implementation unless it first reconstructs the build context correctly.
How it works
fw-context indexes the project through the same compilation database used by build tooling and language servers.
flowchart LR
CCJ[compile_commands.json] & SRC[(source files)] --> LIBCLANG[libclang<br/>AST parser]
LIBCLANG --> SYMBOLS[symbols<br/>name, kind, USR<br/>signature, source body<br/>docstring, tokens] & FILES[files<br/>path, language<br/>ifdef-filtered content<br/>project/SDK sources] & REFS[refs & call graph<br/>fp_assignments<br/>indirect_call_sites] & INHERIT[inheritance<br/>& overrides<br/>virtual dispatch] & MACROS[macros<br/>raw & expanded values<br/>FTS5 searchable] & ENRICH[optional enrichment<br/>embeddings & summaries<br/>hotspot cache]
SYMBOLS & FILES & REFS & INHERIT & MACROS & ENRICH --> MCP[MCP server<br/>35 tools]
MCP --> LLM[AI coding agent]The index contains:
symbol definitions, signatures, source extents and documentation
references, direct call edges and recursive caller paths
function-pointer assignments and indirect call sites
callback registrations and invocation relationships
active, preprocessor-filtered file content
raw and expanded macro values
inheritance, overrides and virtual-dispatch relationships
translation-unit and project/vendor metadata
optional embeddings and LLM-generated summaries
The MCP server exposes this information as compact high-level queries optimized for repeated use by an AI agent.
Typical use cases
build-aware review of firmware commits
tracing execution across ISRs, work queues, tasks and callbacks
locating all callers and references of an API
identifying the implementation selected by the current build
impact analysis before changing a function signature or data type
navigating unfamiliar firmware without reading complete files
finding dead-code candidates and unreferenced symbols
separating project code from SDK and vendor code
reducing irrelevant source text sent to the model
fw-context supports Zephyr, PlatformIO, Mbed OS, Arduino, ESP-IDF, generic CMake, Makefile-based projects and custom builds that can provide a compilation database. Additional setup paths are documented for Keil, IAR, STM32CubeIDE and TI Code Composer Studio.
Why not just use clangd or another LSP?
clangd already uses compilation commands and is excellent at editor-oriented tasks such as diagnostics, completion, go-to-definition and reference lookup. fw-context does not replace it.
fw-context targets a different interface and workload:
persistent project-wide data prepared for repeated agent queries
MCP tools that return compact, structured semantic context
recursive caller and impact-analysis queries
callback and function-pointer relationship modelling
active source content suitable for targeted retrieval
project/vendor classification and firmware-specific workflows
optional cached enrichment shared across repeated analyses
Use clangd for interactive editing. Use fw-context when an AI agent needs structured, reusable context for reviewing, understanding or navigating the built firmware.
Documentation
Project maturity
fw-context is functional and is used on real embedded C and C++ projects, but its interfaces and indexing behaviour are still evolving. Bug reports, incorrect results, unsupported build configurations and reproducible edge cases are particularly valuable.
The project is local-first: source code and the compiler-derived index remain on the developer's machine unless optional external services are explicitly configured.
Background
The project grew from a recurring failure mode in AI-assisted firmware work: coding agents frequently spent more effort reconstructing the active program than reasoning about the engineering question itself.
For the longer explanation, read: Why AI Coding Agents Keep Making the Same Mistakes When Analyzing Embedded Firmware
The compiler has already reconstructed your program. Let your coding agent use it.
Maintenance
Related MCP Servers
- AlicenseAqualityAmaintenanceKnot is a semantic and structural codebase indexer designed for AI coding agents and developers navigating large projects. It combines vector search and graph traversal to find code by meaning, analyze impact via reverse dependencies, and explore file architectures.54MIT

Semantic Code Search MCPofficial
Flicense-qualityDmaintenanceProvides AI coding agents with structured access to indexed codebases via semantic search, symbol analysis, and file reading tools.12- Alicense-qualityCmaintenanceProvides IDE-like code navigation and search for local repositories, enabling AI assistants to perform symbol search, trigram indexing, and semantic navigation.AGPL 3.0
- AlicenseAqualityFmaintenanceIndexes Unreal Engine project C++ source, config files, dependencies, gameplay tags, replication, asset references, and log categories into a SQLite database and exposes tools for AI assistants to query structural and config info.17MIT
Related MCP Connectors
Give your AI agent a persistent map of your project's structure, dependencies, and bugs.
Provide your AI coding tools with token-efficient access to up-to-date technical documentation for…
Persistent memory and knowledge management for AI agents with semantic search and 50+ tools.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/turbyho/fw-context-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server