CMSIS-MCP  Version 0.0.0
Embedded MCP server with serial transport
 
Loading...
Searching...
No Matches
Integration

Add the pack and host bridge layer

For an installed pack, add it to your existing csolution:

solution:
packs:
- pack: ARM::CMSIS-MCP

For a local checkout or unpacked pack, use a versionless pack ID and the path to the directory containing ARM.CMSIS-MCP.pdsc instead:

solution:
packs:
- pack: ARM::CMSIS-MCP
path: ./third_party/c_mcp

Adjust the path relative to your csolution.

The pack declares SerialBridge.clayer.yml as an MCP-Host layer. Its PDSC copy-to="tools/mcp" supplies the proposed destination for an IDE copy; adding the pack or selecting the firmware component does not copy the host files by itself.

In the cproject, select the serial component, request the layer through a variable, and consume the connection that the pack layer provides:

project:
components:
- component: CMSIS:MCP&Serial
define:
- CJSON_NESTING_LIMIT: 16
layers:
- layer: $MCP-Host-Layer$
type: MCP-Host
connections:
- connect: MCP application
consumes:
- MCP_HOST_BRIDGE

The MCP_HOST_BRIDGE connection is a matching marker for the host bridge; it does not add firmware code. Leave $MCP-Host-Layer$ undefined in the csolution initially. With the solution active in VS Code, run CMSIS: Configure Solution from the Command Palette, select MCP-Host, choose the tools/mcp destination or another directory, and click OK. The IDE copies the layer file, Python bridge, requirements file and usage guide together outside RTE. It also writes the chosen MCP-Host-Layer path into the active target's variables: in the csolution.

The PDSC copy-to destination is relative to the csolution directory. If using an explicit layer: path instead of the variable, make it relative to the cproject: a cproject in MyProject/ would use ../tools/mcp/SerialBridge.clayer.yml for a solution-level tools/mcp copy. If the MCP-Host choice is disabled, verify the matching connections: entries and the pack path, then reload VS Code after a local pack update.

When updating the pack, refresh the imported layer explicitly and review the copied files.

The component requires CMSIS:CORE; select it in the application or board layer. Build the solution with the CMSIS Solution tooling, such as the Build action in the CMSIS Solution extension for VS Code. The selected component supplies its sources and include paths automatically.

Configure and integrate the firmware

The builder copies Config/c_mcp_config.h to the project's RTE directory. Edit that copy with the Configuration Wizard:

  • C_MCP_ARENA_SIZE: request memory capacity, default 32 KiB.
  • C_MCP_SERIAL_LINE_SIZE: serial input buffer size, default 4096 bytes.
  • C_MCP_ENABLE_SERIAL_LOOP: enable the supplied serial input loop.
  • C_MCP_ENABLE_VFS: enable optional read-only resources, default enabled.

Include mcp.h for tool and resource registration, and serial_transport.h for the serial input loop and board serial hooks.

Register tools with add_tool(), add_argument() and set_tool_callback(). Register optional read-only resources with add_resource(). Keep registration strings alive until free_tools(). Check all registration results and mcp_prepare() before accepting input.

The simple C example shows tool registration, startup, the serial request loop and cleanup together for a setGain tool.

Numeric arguments are expected to be finite values representable as a double.

Call init_serial() once, then process_serial() in the foreground main loop. The parser preserves partial input and accepts CR, LF and CRLF. It discards oversized lines or lost input through the next delimiter. At shutdown, call end_serial() and free_tools().

Override mcp_serial_transport_init(), mcp_serial_transport_close(), mcp_serial_getchar() and mcp_serial_send() with strong board functions. These functions can use any serial interface. A nonblocking read returns MCP_SERIAL_NO_DATA when RX is empty; MCP_SERIAL_EOF means closure, and MCP_SERIAL_INPUT_LOST means RX data loss. Finish serial writes before returning from the sender; response text is borrowed from the request arena. Do not retain it.

Dispatch is single-threaded and non-reentrant. The request arena defaults to 32 KiB and the serial line buffer to 4096 bytes. Persistent registration and prepared response metadata use the heap at startup.

Run the host bridge

The bridge exposes serial as a shared HTTP MCP endpoint on the computer. It requires Python 3.10 or newer. From the csolution directory:

uv run --script tools/mcp/mcp_serial_bridge.py --port "<serial-port>"

Replace <serial-port> with your board's serial device: for example COM3 on Windows, /dev/ttyACM0 or /dev/ttyUSB0 on Linux, or /dev/cu.usbmodem12345 on macOS.

The shared MCP endpoint is http://127.0.0.1:8765/mcp. Close other serial monitors before starting the bridge: it must be the port's only owner. Ctrl+C stops it and releases the port.

For an existing project environment:

uv pip install --python <venv-python> -r tools/mcp/requirements-mcp-serial-bridge.txt

The bridge can also be run directly from the pack checkout or an unpacked pack:

uv run --script tools/mcp_serial_bridge.py --port "<serial-port>"

The C implementation in this release is the Serial variant. A C HTTP variant will be added in a future release.

The automation guide explains how to connect an AI harness to the bridge, followed by a Bash and curl example for calling tools from scripts.