dap-mcp-server 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -89,8 +89,17 @@ export async function runDebugInspect(
89
89
  if (opts.args !== undefined) launchArgs.args = opts.args;
90
90
  if (opts.cwd !== undefined) launchArgs.cwd = opts.cwd;
91
91
  if (opts.env !== undefined) launchArgs.env = opts.env;
92
+ // delve: mirror cwd → dlvCwd so `go build` finds go.mod from the right dir.
93
+ if (config.type === "go" && opts.cwd !== undefined && launchArgs.dlvCwd === undefined) {
94
+ launchArgs.dlvCwd = opts.cwd;
95
+ }
92
96
 
93
97
  const launchPromise = session.launch(launchArgs);
98
+ // Suppress unhandled rejection: the real `await launchPromise` below will
99
+ // still throw if launch fails. Without this, an early launch rejection
100
+ // (e.g. adapter rejects the request) crashes the MCP server.
101
+ launchPromise.catch(() => { /* handled at await */ });
102
+ await session.waitForInitialized(10000);
94
103
 
95
104
  await session.setBreakpoints(opts.at.file, [
96
105
  {
@@ -118,9 +127,13 @@ export async function runDebugInspect(
118
127
  const state = await session.collectState();
119
128
  const values: Record<string, InspectValueResult> = {};
120
129
  if (opts.expressions && opts.expressions.length > 0) {
130
+ // Some adapters (vscode-js-debug) require a frameId to evaluate names
131
+ // bound in the current function's scope. Use the top frame's id when
132
+ // available so locals resolve correctly.
133
+ const topFrameId = state.stackTrace?.[0]?.id;
121
134
  for (const expr of opts.expressions) {
122
135
  try {
123
- const r = await session.evaluate(expr);
136
+ const r = await session.evaluate(expr, topFrameId);
124
137
  values[expr] = { result: r.result, type: r.type };
125
138
  } catch (err) {
126
139
  values[expr] = { error: err instanceof Error ? err.message : String(err) };
@@ -80,8 +80,16 @@ export async function runDebugRun(
80
80
  if (opts.args !== undefined) launchArgs.args = opts.args;
81
81
  if (opts.cwd !== undefined) launchArgs.cwd = opts.cwd;
82
82
  if (opts.env !== undefined) launchArgs.env = opts.env;
83
+ // delve: mirror cwd → dlvCwd so `go build` finds go.mod from the right dir.
84
+ if (config.type === "go" && opts.cwd !== undefined && launchArgs.dlvCwd === undefined) {
85
+ launchArgs.dlvCwd = opts.cwd;
86
+ }
83
87
 
84
88
  const launchPromise = session.launch(launchArgs);
89
+ // Suppress unhandled rejection: the real `await launchPromise` below will
90
+ // still throw if launch fails.
91
+ launchPromise.catch(() => { /* handled at await */ });
92
+ await session.waitForInitialized(10000);
85
93
 
86
94
  if (opts.logpoints && opts.logpoints.length > 0) {
87
95
  const byFile = new Map<string, Array<{ line: number; logMessage: string }>>();
@@ -62,7 +62,10 @@ export class DebugSession {
62
62
  const runtime = config.runtime || "";
63
63
  const program = config.program;
64
64
  const args = config.args || [];
65
- this.client = new DAPClient(runtime, program, args);
65
+ this.client = new DAPClient(runtime, program, args, {
66
+ transport: config.transport,
67
+ portMatcher: config.portMatcher,
68
+ });
66
69
 
67
70
  this.client.on("event", (event: DebugProtocol.Event) => {
68
71
  this.handleEvent(event);
@@ -104,7 +107,12 @@ export class DebugSession {
104
107
  });
105
108
  this.capabilities = response.body || {};
106
109
  this._state = "configuring";
107
- await this.waitForInitialized(10000);
110
+ // Note: per DAP spec, the "initialized" event signals the adapter is
111
+ // ready for configuration (setBreakpoints, etc.). Different adapters
112
+ // emit it at different times: delve emits it immediately after the
113
+ // initialize response, but debugpy only emits it after `launch` is
114
+ // received. The orchestrator (server.ts) is responsible for waiting
115
+ // for it AFTER firing the launch/attach request — see waitForInitialized.
108
116
  return this.capabilities;
109
117
  } catch (err) {
110
118
  this._state = "terminated";
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Copyright (c) 2026 Ivan Iraci <ivan.iraci@professioneit.com>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+ // TCP-mode mock DAP adapter for testing the TCP transport.
24
+ // Opens a TCP listener on a random port, prints the listen address banner to
25
+ // stdout (matching the regex "DAP server listening at: \S+:(\d+)"), accepts a
26
+ // single client connection, and runs a tiny DAP server on it.
27
+
28
+ import net from "node:net";
29
+
30
+ const TWO_CRLF = "\r\n\r\n";
31
+
32
+ const server = net.createServer((socket) => {
33
+ let buffer = Buffer.alloc(0);
34
+ let contentLength = -1;
35
+ let seq = 1;
36
+
37
+ const send = (msg) => {
38
+ const json = JSON.stringify(msg);
39
+ const header = `Content-Length: ${Buffer.byteLength(json)}${TWO_CRLF}`;
40
+ socket.write(header + json);
41
+ };
42
+
43
+ socket.on("data", (chunk) => {
44
+ buffer = Buffer.concat([buffer, chunk]);
45
+ while (true) {
46
+ if (contentLength === -1) {
47
+ const idx = buffer.indexOf(TWO_CRLF);
48
+ if (idx === -1) return;
49
+ const header = buffer.subarray(0, idx).toString();
50
+ const match = header.match(/Content-Length:\s*(\d+)/i);
51
+ if (!match) return;
52
+ contentLength = parseInt(match[1], 10);
53
+ buffer = buffer.subarray(idx + TWO_CRLF.length);
54
+ }
55
+ if (buffer.length < contentLength) return;
56
+ const body = buffer.subarray(0, contentLength).toString();
57
+ buffer = buffer.subarray(contentLength);
58
+ contentLength = -1;
59
+ const msg = JSON.parse(body);
60
+ if (msg.type === "request" && msg.command === "initialize") {
61
+ send({
62
+ seq: seq++,
63
+ type: "response",
64
+ request_seq: msg.seq,
65
+ command: msg.command,
66
+ success: true,
67
+ body: { supportsConfigurationDoneRequest: true },
68
+ });
69
+ send({ seq: seq++, type: "event", event: "initialized" });
70
+ } else if (msg.type === "request") {
71
+ send({
72
+ seq: seq++,
73
+ type: "response",
74
+ request_seq: msg.seq,
75
+ command: msg.command,
76
+ success: true,
77
+ });
78
+ }
79
+ }
80
+ });
81
+ });
82
+
83
+ server.listen(0, "127.0.0.1", () => {
84
+ const { address, port } = server.address();
85
+ // Print the listen banner in the same shape delve uses.
86
+ process.stdout.write(`DAP server listening at: ${address}:${port}\n`);
87
+ });