Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ All notable changes to this project will be documented in this file.

### Added

- HTTP/SSE MCP server mode: `cargo run -- --http --port 8080` exposes the same tool surface over HTTP/SSE, allowing multiple clients to share a single `DebugSession`/`OpenOcdClient`; follows MCP 2025-03-26 convention (`GET /sse` returns a unique `session_id` endpoint, `POST /message` returns 202 and pushes responses via SSE); broadcasts `notifications/tools/list_changed` on state transitions
- GDB DAP mode support (`--adapter-kind gdb --adapter-args=-i --adapter-args=dap`): adapter-aware `launch`/`configuration_done` behavior, GDB remote debugging via `target` field (codelldb keeps `processCreateCommands`), and runtime-derived default `adapterId` ("gdb" vs "lldb")
- `list_breakpoints` MCP tool: client-side breakpoint cache tracking source/function breakpoints, refreshed on `set_breakpoints`/`set_function_breakpoints` and DAP `breakpoint` events, cleared on disconnect/termination
- `get_state` detail parameter: opt-in `"simple"` mode omits the large `capabilities` object; default `"full"` preserves existing behavior

### Fixed

Expand All @@ -24,6 +27,8 @@ All notable changes to this project will be documented in this file.

### Documentation

- AI Agent 集成指南:面向 AI Agent 开发者和用户的完整集成文档,涵盖 stdio 与 HTTP/SSE 两种 MCP 接入模式、配置步骤、包装脚本示例、自建 Agent Python 代码示例、AI 系统提示模板、生命周期状态机图、路径映射机制、OpenOCD 嵌入式调试流程及 5 个常见问题解答
- TeleDAP 推广计划:按优先级排序列出推广所需工作,包括 README 更新、英文文档、示例仓库与教程、GitHub Releases/包管理器分发、AI 客户端集成验证矩阵、安全与远程化增强、社区推广渠道(awesome-mcp-servers/Reddit/HN/知乎)、生态扩展(VS Code 扩展/高级功能)及 5 阶段推广里程碑建议
- MCP Inspector 手动测试指南:使用官方 `@modelcontextprotocol/inspector` 在浏览器中交互式测试 TeleDAP,覆盖 codelldb 获取、状态门控体验、14 步完整调试流程、错误路径/路径映射/模糊搜索场景、排障表及两种替代测试方式
- MCP-DAP 协议桥接架构文档:覆盖项目整体架构、crate 依赖关系、MCP/DAP 协议层、桥接转换机制、24 个工具映射、事件流、会话状态机、变量缓存与路径映射、完整数据流示例

Expand Down
40 changes: 34 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ cargo run -- --codelldb-path /path/to/codelldb --elf-path ./app.elf -v
# Run MCP server (pipe-in mode — auto-detected when stdin is not a terminal)
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | cargo run --quiet --

# Run MCP server over HTTP/SSE (multi-client shared session)
cargo run -- --http --port 8080

# Force CLI mode when stdin is a pipe (e.g. PowerShell)
cargo run -- --cli --codelldb-path /path/to/codelldb --elf-path ./app.elf

# E2E MCP protocol smoke test
# E2E MCP protocol smoke test (stdio mode)
./test_mcp_e2e.sh # Unix/Mac
powershell -File test_mcp_e2e.ps1 # Windows
```

## Architecture

```
teledap (root binary — auto-detect: pipe→MCP server, terminal→CLI)
teledap (root binary — auto-detect: --http→HTTP/SSE, pipe→MCP stdio server, terminal→CLI)
├── debug-bridge — MCP→DAP translation: ToolRegistry, 24 tool handlers, state gating
│ ├── mcp-protocol — JSON-RPC 2.0 types, line-delimited stdio transport
│ ├── debug-session — state machine, context-chain, path mapping, variable cache
Expand All @@ -57,18 +60,19 @@ teledap (root binary — auto-detect: pipe→MCP server, terminal→CLI)

**Crate dependency direction:** `teledap → {debug-bridge, mcp-protocol, debug-session, dap-client}`. `dap-types` is the leaf crate with zero internal dependencies; every other crate depends on it.

**Dual-mode binary:** `src/main.rs` detects mode automatically — pipe stdin → MCP server (`src/server.rs`), terminal stdin → CLI (`src/cli.rs`). Use `--cli` to force CLI when piped.
**Tri-mode binary:** `src/main.rs` selects mode in this order: `--http` → HTTP/SSE MCP server (`src/http_server.rs`), pipe stdin → MCP stdio server (`src/server.rs`), terminal stdin → CLI (`src/cli.rs`). Use `--cli` to force CLI when piped. The HTTP/SSE server exposes the same tool surface as the stdio server but allows multiple clients to share a single `DebugSession`/`OpenOcdClient`.

## Key Design Patterns

### Two wire protocols
### Three wire protocols

| Layer | Transport | Framing |
|-------|-----------|---------|
| **MCP** (AI ↔ TeleDAP) | stdin/stdout | Line-delimited JSON (`\n` terminated) |
| **MCP stdio** (AI ↔ TeleDAP) | stdin/stdout | Line-delimited JSON (`\n` terminated) |
| **MCP HTTP/SSE** (AI ↔ TeleDAP) | HTTP 1.1 | `GET /sse` returns event stream; `POST /message` accepts JSON-RPC |
| **DAP** (TeleDAP ↔ codelldb) | child process stdin/stdout | `Content-Length: <N>\r\n\r\n<JSON body>` |

`McpServer` reads lines via `BufReader::read_line()`. `DapCodec` implements `tokio_util::codec::Decoder<Item=ProtocolMessage>` handling partial reads, sticky packets, oversized frames (max 4 MiB), and header size limits (4 KiB).
`McpServer` reads lines via `BufReader::read_line()`. The HTTP/SSE transport in `src/http_server.rs` uses axum: each SSE connection gets a unique `session_id`; all connections share one `DebugSession`. `DapCodec` implements `tokio_util::codec::Decoder<Item=ProtocolMessage>` handling partial reads, sticky packets, oversized frames (max 4 MiB), and header size limits (4 KiB).

### ProtocolMessage — serde internal tagging

Expand Down Expand Up @@ -119,6 +123,29 @@ Five states: `Disconnected → Connected → Initialized → {Running ↔ Halted

`handle_event()` also triggers variable cache invalidation (Halted→Running/Disconnected) and `watch::channel` broadcasts.

### HTTP/SSE MCP transport

`src/http_server.rs` implements the MCP 2025-03-26 HTTP/SSE convention:

- `GET /sse` opens an SSE stream. The first event is `event: endpoint` with `data: /message?session_id=<uuid>`.
- `POST /message?session_id=<uuid>` accepts a JSON-RPC request. The server returns `202 Accepted` immediately; the actual response is pushed to that client's SSE stream as `event: message`.
- Every SSE connection gets a unique MCP client session id, but all connections share the same `DebugSession` and `OpenOcdClient`.
- When the debug session state changes, the server broadcasts `notifications/tools/list_changed` to all connected clients.

Example with `curl`:

```bash
# Terminal 1: connect SSE and capture the endpoint URL
curl -N http://localhost:8080/sse
# → event: endpoint
# → data: /message?session_id=550e8400-e29b-41d4-a716-446655440000

# Terminal 2: send initialize
curl -X POST "http://localhost:8080/message?session_id=550e8400-e29b-41d4-a716-446655440000" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'
```

### Fire-and-forget pattern for launch

`launch` and `configurationDone` use `send_request_nb()`. codelldb defers the `launch` response until `configurationDone` is received, so awaiting `launch` in the traditional `send_request()` + oneshot pattern would deadlock.
Expand Down Expand Up @@ -150,6 +177,7 @@ All dependency versions are declared in the root `Cargo.toml` `[workspace.depend
- **Unit tests** are inline `#[cfg(test)] mod tests` blocks in each source file — spread across 27 files.
- **Integration tests** live in `crates/dap-client/tests/`, `crates/debug-session/tests/`, and `crates/debug-bridge/tests/`. They spawn a real codelldb process and use a `codelldb_available()` env probe that gracefully skips when codelldb is absent. Every async test is wrapped in `tokio::time::timeout()` to prevent hangs.
- **MCP E2E scripts** (`test_mcp_e2e.sh`, `test_mcp_e2e.ps1`) pipe 7 phases of JSON-RPC messages into the binary and assert every response — no test framework needed.
- **HTTP/SSE tests** live in `src/http_server.rs` and exercise the axum router via `ServiceExt::oneshot`, including the `initialize` handshake over SSE.
- **test_debuggee** (`test_debuggee/main.c`) is a simple C program compiled for integration tests — tests locate it relative to workspace root or `CARGO_MANIFEST_DIR`.
- New dap-codec tests go in `crates/dap-codec/src/lib.rs` in the existing `mod tests` block; use `make_codec()` and `make_wire()` / `make_wire_value()` helpers.
- New state machine tests go in `crates/debug-session/src/state.rs` and `gating.rs`.
Expand Down
Loading
Loading