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