|
| 1 | +# Model Context Protocol (MCP) |
| 2 | + |
| 3 | +LLDB supports the [Model Context Protocol][https://modelcontextprotocol.io] |
| 4 | +(MCP). This structured, machine-friendly protocol allows AI models to access |
| 5 | +and interact with external tools, for example debuggers. Using MCP, an AI agent |
| 6 | +can execute LLDB commands to control the debugger: set breakpoints, inspect |
| 7 | +memory, step through code. This can range from helping you run a specific |
| 8 | +command you cannot immediately remember, to a fully agent-driven debugging |
| 9 | +experience. |
| 10 | + |
| 11 | +## MCP Server |
| 12 | + |
| 13 | +To start the MCP server in LLDB, use the `protocol-server start` command. |
| 14 | +Specify `MCP` as the protocol and provide a URI to listen on. For example, to |
| 15 | +start listening for local TCP connections on port `59999`, use the following |
| 16 | +command: |
| 17 | + |
| 18 | +``` |
| 19 | +(lldb) protocol-server start MCP listen://localhost:59999 |
| 20 | +MCP server started with connection listeners: connection://[::1]:59999, connection://[127.0.0.1]:59999 |
| 21 | +``` |
| 22 | + |
| 23 | +The server will automatically stop when exiting LLDB, or it can be stopped |
| 24 | +explicitly with the `protocol-server stop` command. |
| 25 | + |
| 26 | +``` |
| 27 | +(lldb) protocol-server stop MCP |
| 28 | +``` |
| 29 | + |
| 30 | +The commands will fail if a server is already running or not running |
| 31 | +respectively. |
| 32 | + |
| 33 | +## MCP Client |
| 34 | + |
| 35 | +MCP uses standard input/output (stdio) for communication between client and |
| 36 | +server. The exact configuration depends on the client, but most applications |
| 37 | +allow you to specify an MCP server as a binary and arguments. This means that |
| 38 | +you need to use something like `netcat` to connect to LLDB's MCP server and |
| 39 | +forward communication over stdio over the network connection. |
| 40 | + |
| 41 | +``` |
| 42 | +┌──────────┐ ┌──────────┐ ┌──────────┐ |
| 43 | +│ │ │ │ │ │ |
| 44 | +│ LLDB ├─────socket────┤ netcat ├─────stdio─────┤MCP Client│ |
| 45 | +│ │ │ │ │ │ |
| 46 | +└──────────┘ └──────────┘ └──────────┘ |
| 47 | +``` |
| 48 | + |
| 49 | +Configuration example for [Claude Code][https://modelcontextprotocol.io/quickstart/user]: |
| 50 | + |
| 51 | +```json |
| 52 | +{ |
| 53 | + "mcpServers": { |
| 54 | + "tool": { |
| 55 | + "command": "/usr/bin/nc", |
| 56 | + "args": ["localhost", "59999"] |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +Configuration example for [Visual Studio Code][https://code.visualstudio.com/docs/copilot/chat/mcp-servers]: |
| 63 | + |
| 64 | +```json |
| 65 | +{ |
| 66 | + "mcp": { |
| 67 | + "servers": { |
| 68 | + "lldb": { |
| 69 | + "type": "stdio", |
| 70 | + "command": "/usr/bin/nc", |
| 71 | + "args": ["localhost", "59999"] |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +### Troubleshooting |
| 79 | + |
| 80 | +The MCP server uses the `Host` log channel. You can enable logging with the |
| 81 | +`log enable` command. |
| 82 | + |
| 83 | +``` |
| 84 | +(lldb) log enable lldb host |
| 85 | +``` |
0 commit comments