mcp-dap-server
CLAUDE.md105 starsChanged 2 months agoMITView on GitHub
This is an MCP (Model Context Protocol) server that bridges MCP clients with DAP (Debug Adapter Protocol) debuggers. It exposes debugging capabilities as MCP tools, allowing AI assistants to programmatically control debuggers. Supports Delve (Go) and GDB (C/C++ via native DAP). main.go: MCP server initialization - Creates the MCP server using the go-sdk - Registers all debugging tools via registerTools() - Registers workflow prompts via registerPrompts() - Exposes stdio transport prompts.go: MCP prompt implementations - 4 prompt handlers for guided…
The file
We split this CLAUDE.md into the rules it gives an agent
8 rules. About 0 are common, 4 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
All MCP tools are methods on debuggerSession struct
- Very specific: line 35
All DAP request methods return (int, error) where int is the request sequence number
- Distinctive: line 55
All tool methods operate on this shared session
- Very specific: line 64
Dynamic Tool Registration: Only debug is registered initially.
- Distinctive: line 99
Test programs are compiled with debugging symbols during test execution:
- Distinctive: line 179
Only one debugger can be active per MCP server session
- Distinctive: line 198
Serialized Tool Calls: All tool calls are serialized by a mutex.
- Very specific: line 200
Test Binary Paths: Must be absolute paths for the debug tool in binary mode
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is an MCP (Model Context Protocol) server that bridges MCP clients with DAP (Debug Adapter Protocol) debuggers. It exposes debugging capabilities as MCP tools, allowing AI assistants to programmatically control debuggers. Supports Delve (Go) and GDB (C/C++ via native DAP).
Architecture
Core Components
main.go: MCP server initialization
- Creates the MCP server using the
go-sdk - Registers all debugging tools via
registerTools() - Registers workflow prompts via
registerPrompts() - Exposes stdio transport
prompts.go: MCP prompt implementations
- 4 prompt handlers for guided debugging workflows (source, attach, core dump, binary)
- Registered via
server.AddPrompt()— no session state, always available - Each prompt returns a
GetPromptResultwith step-by-step tool invocation guidance
tools.go: MCP tool implementations (~1200 lines)
- All MCP tools are methods on
debuggerSessionstruct - Each tool method signature:
func (ds *debuggerSession) toolName(ctx context.Context, _ *mcp.ServerSession, params *mcp.CallToolParamsFor[ParamsType]) (*mcp.CallToolResultFor[any], error) - Tools send DAP requests via
ds.clientand read/parse responses readAndValidateResponse(client, requestSeq, errorPrefix)matches responses byrequest_seq, skipping unrelated responsesreadTypedResponse[T](client, requestSeq)matches typed responses byrequest_seq, skipping unrelated responses- Tools that wait for stopped/terminated events loop on
ReadMessage()until they receive the expected event
dap.go: DAP client implementation
DAPClientmanages TCP or stdio connection to DAP server- Wraps
github.com/google/go-dapprotocol messages - All DAP request methods return
(int, error)whereintis the request sequence number - Sequence numbers are used to match responses to requests via
request_seqfield
backend.go: Debugger backend abstraction
DebuggerBackendinterface abstracts debugger-specific behavior (spawning, launch args, transport)delveBackend: Spawnsdlv dap, uses TCP transportgdbBackend: Spawnsgdb -i dap, uses stdio transport
flexint.go: Flexible integer parsing
FlexInttype handles JSON values that may be integers or string-encoded integers- Used in tool parameter structs where MCP clients may send numbers as strings
debuggerSession: Shared state (tools.go)
cmd: The debugger adapter processclient: DAP client connectionserver: MCP server reference (for dynamic tool registration)backend: Debugger-specific backend (delve, gdb)capabilities: DAP capabilities reported by the adapterlaunchMode,programPath,programArgs,coreFilePath: Session configstoppedThreadID,lastFrameID: State from last stop event- All tool methods operate on this shared session
Key Patterns
- Tool Parameter Structs: Each tool has a corresponding
*Paramsstruct with JSON/MCP tags - DAP Message Handling: Response reading matches by
request_seq(from the DAP protocol), skipping unrelated responses from other requests. go-dap decodes all failed responses as*dap.ErrorResponse, so matching by Go type alone is insufficient - Event vs Response: Some operations (continue, step, etc.) wait for
StoppedEventorTerminatedEventrather than just response messages - Error Propagation: DAP response
Successfield is checked; error messages fromresponse.Messageare wrapped in Go errors - Capability-Gated Tools:
set-variable,disassemble, andrestartare only registered when the DAP adapter reports support - Dynamic Tool Registration: Only
debugis registered initially; session tools replace it after a session starts, then are removed when the session stops - Serialized DAP Access: A mutex on
debuggerSessionserializes all tool calls, preventing concurrent reads from the single DAP connection
Development Commands
Build
go build -o bin/mcp-dap-serverRun Tests
# Run all tests
go test -v
# Run a specific test
go test -v -run TestBasic
# Run with race detector
go test -race -v
# Run with coverage
go test -v -coverprofile=coverage.out && go tool cover -func=coverage.out | grep totalRun the Server
# Default (port 8080)
./bin/mcp-dap-server
# Or via go run
go run .Test Program Compilation
Test programs are compiled with debugging symbols during test execution:
go build -gcflags=all=-N -l -o testdata/go/helloworld/debugprog testdata/go/helloworld/main.goMCP Tools (Current API)
Tools are dynamically registered. Before a debug session, only debug is available. After starting a session, the following tools are registered:
| Tool | Description |
debug | Start a complete debug session (modes: source, binary, core, attach) |
stop | End the debugging session |
breakpoint | Set a breakpoint (file+line or function name) |
clear-breakpoints | Remove breakpoints (by file or all) |
continue | Continue execution (with optional run-to-cursor) |
step | Step over/in/out |
pause | Pause a running program |
context | Get full debugging context (location, stack, variables) |
evaluate | Evaluate an expression |
info | List threads, sources, or modules |
set-variable | Modify a variable value (capability-gated) |
disassemble | Disassemble at address (capability-gated) |
restart | Restart the session (capability-gated) |
Typical Debugging Flow
- debug — Spawns debugger, connects, optionally sets breakpoints and continues to first hit
- context — Get location, stack trace, and variables at the stop point
- breakpoint / clear-breakpoints — Manage breakpoints
- continue / step — Navigate through execution
- evaluate — Inspect expressions
- stop — Clean up
Testing Architecture
Tests in tools_test.go follow a common pattern:
- Setup:
setupMCPServerAndClient()creates an in-process MCP server/client pair - Compilation:
compileTestProgram()builds test Go programs with debug flags (-gcflags=all=-N -l) - Session Management:
startDebugSession()starts a debug session with optional breakpoints - Helpers:
callTool()reduces boilerplate for calling tools and extracting text content;setBreakpointAndContinue(),getContextContent(),stopDebugger()handle common operations - Test Programs: Located in
testdata/go/*/main.go:helloworld— basic program with a greeting variablestep— arithmetic with multiple variables for stepping testsscopes— complex data types (slices, maps, structs) for variable inspectionrestart— program that uses command-line args for restart testingcoredump— program that crashes for core dump testingloop— infinite loop for pause testing
Common Test Flow
func TestSomething(t *testing.T) {
ts := setupMCPServerAndClient(t)
defer ts.cleanup()
binaryPath, cleanupBinary := compileTestProgram(t, ts.cwd, "helloworld")
defer cleanupBinary()
ts.startDebugSession(t, "0", binaryPath, nil) // port "0" = auto-assign
f := filepath.Join(ts.cwd, "testdata", "go", "helloworld", "main.go")
ts.setBreakpointAndContinue(t, f, 7)
contextStr := ts.getContextContent(t)
// Assert on contextStr...
ts.stopDebugger(t)
}Important Implementation Details
Multi-Debugger Support
- Delve (default): Go programs, TCP transport, spawns
dlv dap - GDB: C/C++ programs, stdio transport, requires GDB 14+ (native DAP)
- Backend selection via
debuggerparameter indebugtool ("delve" or "gdb")
State Management
debuggerSessionis shared across all tool calls within a session- Only one debugger can be active per MCP server session
ds.client == nilchecks protect against calling tools before debugger is started- Tools are dynamically registered/unregistered as sessions start/stop
Response Handling
- Some tools read multiple messages (events + responses) in a loop
continueandstep(all modes) wait forStoppedEventorTerminatedEvent- The
contexttool automatically fetches scopes and variables for the current frame
Tool Naming Convention
- MCP tool names use kebab-case:
clear-breakpoints,set-variable,step - Go function names use camelCase:
clearBreakpoints,setVariable,step
Common Gotchas
- Debugger Must Be Started First: Most tools will error if
ds.client == nil - Frame IDs vs Thread IDs: Frame IDs come from stack traces, thread IDs from the threads request. Delve uses frame IDs starting at 1000.
- Variables References: The
variablesReferencein scopes/variables is a DAP protocol identifier, not a simple index. Delve uses frame_id+1 for locals scope (e.g., 1001 for frame 1000). - Stopped Event Format: Contains
Reasonfield ("breakpoint", "function breakpoint", "step", "entry", "pause", etc.) andThreadId - Serialized Tool Calls: All tool calls are serialized by a mutex. Concurrent MCP tool calls will queue rather than race. Long-running operations (continue, step) hold the lock until completion.
- Capability-Gated Tools:
set-variable,disassemble, andrestartare only available when the DAP adapter reports support via capabilities - Test Binary Paths: Must be absolute paths for the
debugtool in binary mode - go-dap ErrorResponse Decoding: go-dap decodes ALL failed responses (
success: false) as*dap.ErrorResponseregardless of command. Response matching must userequest_seq, not Go type - DAP Response Ordering: GDB native DAP may send responses out of order (e.g.,
StoppedEventbeforeContinueResponse). Out-of-order responses are skipped byrequest_seqmatching - go-dap
omitemptyon FrameId:EvaluateArguments.FrameIdhasomitempty, soframeId=0is silently dropped.EvaluateRequestuses raw JSON map to work around this
Dependencies
github.com/google/go-dap- DAP protocol implementationgithub.com/modelcontextprotocol/go-sdk- MCP server framework- Requires
dlv(Delve debugger) in$PATHfor Go debugging - Optional: GDB 14+ for C/C++ debugging (native DAP support via
gdb -i dap)
Workflow Guidance
MCP Prompts
The server exposes 4 prompts (via prompts/list and prompts/get) that return guided debugging workflows:
| Prompt | Required Args | Use for |
debug-source | path | Debugging Go/C/C++ from source |
debug-attach | pid | Attaching to a running process |
debug-core-dump | binary_path, core_path | Post-mortem crash analysis |
debug-binary | path | Assembly-level binary debugging |
Prompts are registered in prompts.go via registerPrompts(), called from main.go.
Claude Code Skills
Four skills live in skills/ for use with the Claude Code Superpowers plugin:
| Skill file | Trigger |
debug-source.md | Debugging from source code |
debug-attach.md | Attaching to a running process |
debug-core-dump.md | Analyzing a core dump |
debug-binary.md | Assembly-level binary debugging |
To register skills with Claude Code, configure the skills/ directory as a skills source in your Superpowers plugin settings.
Human Reference
See docs/debugging-workflows.md for:
- Decision table: scenario → mode → which prompt/skill to use
- Mermaid workflow diagrams for each scenario
- Common gotchas and patterns per scenario
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

