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
1 change: 1 addition & 0 deletions changelog.d/1389.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**The Java attach guidance and the server's free-port probe keep to loopback** — the text an agent reads before attaching to a JVM (the `attach_to_process` description, the Java adapter's attach hint, the workflow prompt and the debugging skill) told it to start the JVM with `address=*:<port>`, which opens the unauthenticated JDWP port on every network interface. All four now give `address=127.0.0.1:<port>`, and the three general ones name the case that needs more: a JVM in a Docker container reached through a published port, which is then published on the host's loopback. The Java docs and skill reference name `127.0.0.1` where they gave a bare port, which is every interface on a JDK 8 target. The server's own free-port probe, each time a launch or an attach is prepared (a dry run included), listened with no host and so on every interface for an instant; it binds `127.0.0.1`. A check in the unit suite now holds a recorded list of every `.listen(` call and Java socket constructor in the server's and adapters' sources and the Java bridge, each with what it binds and why, and of every line there or in the skill text that writes one of the wildcard shapes it knows (`0.0.0.0`, `[::]`, a `--listen` value that starts with a colon, a wildcard or non-loopback JDWP `address=`): a new one fails until someone has looked at it and recorded it, and so does a recorded line that no longer matches. It does not see a host handed to a spawned debug adapter on its command line (#1389)
4 changes: 2 additions & 2 deletions docs/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Connect to a running JVM that was started with JDWP agent.

Start your JVM with JDWP enabled:
```bash
java -agentlib:jdwp=transport=dt_socket,server=y,address=5005,suspend=y \
java -agentlib:jdwp=transport=dt_socket,server=y,address=127.0.0.1:5005,suspend=y \
-cp . MyProgram
```

Expand Down Expand Up @@ -244,7 +244,7 @@ javac -g Calculator.java
```bash
# Terminal 1: Start JVM with JDWP
javac -g MyServer.java
java -agentlib:jdwp=transport=dt_socket,server=y,address=5005,suspend=y \
java -agentlib:jdwp=transport=dt_socket,server=y,address=127.0.0.1:5005,suspend=y \
-cp . MyServer
# Output: "Listening for transport dt_socket at address: 5005"
```
Expand Down
2 changes: 1 addition & 1 deletion examples/java/InfiniteWait.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Simple Java program for testing attach-mode debugging.
*
* Launch with JDWP agent to allow debugger attach:
* java -agentlib:jdwp=transport=dt_socket,server=y,address=<port>,suspend=y \
* java -agentlib:jdwp=transport=dt_socket,server=y,address=127.0.0.1:<port>,suspend=y \
* -cp . InfiniteWait
*
* With suspend=y the JVM pauses at startup, so the program just needs
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-java/src/java-adapter-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class JavaAdapterFactory implements IAdapterFactory {
attachBy: ['port'],
attachHints: {
processId:
'JDWP has no PID step; start the JVM with -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:<port> and pass that port'
'JDWP has no PID step; start the JVM with -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:<port> and pass that port'
}
},
icon: 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMjggMTI4Ij48cGF0aCBmaWxsPSIjRTc2RjAwIiBkPSJNNDcuNiA3Ni41cy00LjYgMi43IDMuMyAzLjZjOS41IDEuMSAxNC40LjkgMjQuOS0xLjEgMCAwIDIuOCAxLjcgNi42IDMuMi0yMy40IDEwLTUzLTAuNi0zNC44LTUuN3ptLTIuOS0xMy4xcy01LjIgMy44IDIuNyA0LjZjMTAuMiAxLjEgMTguMiAxLjIgMzIuMS0xLjYgMCAwIDEuOSAyIDQuOSAzLjEtMjguMyA4LjMtNTkuOC42LTM5LjctNi4xeiIvPjxwYXRoIGZpbGw9IiM1MzgyQTEiIGQ9Ik02OS40IDQ1LjFjNS43IDYuNi0xLjUgMTIuNS0xLjUgMTIuNXMxNC41LTcuNSA3LjktMTYuOWMtNi4yLTguOC0xMC45LTEzLjIgMTQuNy0yOC4yIDAgMC00MC4yIDEwLTIxLjEgMzIuNnoiLz48cGF0aCBmaWxsPSIjRTc2RjAwIiBkPSJNOTUuOCA4My45czMuNCAyLjgtMy44IDVjLTEzLjUgNC4xLTU2LjIgNS4zLTY4LjEuMi00LjMtMS45IDMuOC00LjQgNi40LTUgMi43LS42IDQuMi0uNSA0LjItLjUtNC44LTMuNC0zMS4zIDYuNy0xMy40IDkuNSA0OC42IDcuNyA4OC42LTMuNSA3NC43LTkuMnpNNDkuOSA1NS42cy0yMi4yIDUuMy03LjkgNy4yYzYuMS44IDE4LjIuNiAyOS41LS4zIDkuMi0uOCAxOC41LTIuNCAxOC41LTIuNHMtMy4zIDEuNC01LjYgM2MtMjIuOCA2LTY2LjggMy4yLTU0LjEtMi45IDEwLjctNS4yIDE5LjYtNC42IDE5LjYtNC42ek04NS43IDcxLjJjMjMuMS0xMiAxMi40LTIzLjYgNS0yMiAtMS44LjQtMi42LjctMi42LjdzLjctMS4xIDItMS41YzE0LjctNS4yIDI2IDE1LjItNC44IDIzLjMgMCAwIC40LS4zLjQtLjV6Ii8+PHBhdGggZmlsbD0iIzUzODJBMSIgZD0iTTc2LjUgMS45czEyLjggMTIuOC0xMi4xIDMyLjVjLTIwIDE1LjgtNC42IDI0LjggMCAzNS4xLTExLjctMTAuNS0yMC4yLTE5LjgtMTQuNS0yOC40QzU4LjMgMjguNCA4MS4xIDIyIDc2LjUgMS45eiIvPjxwYXRoIGZpbGw9IiNFNzZGMDAiIGQ9Ik01MS40IDEwNC41YzIyLjIgMS40IDU2LjMtLjggNTcuMS0xMS4zIDAgMC0xLjYgNC0xOC40IDcuMi0xOSAzLjYtNDIuNCAzLjItNTYuMy45IDAgMCAyLjggMi40IDE3LjYgMy4yeiIvPjwvc3ZnPg==',
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/interfaces/adapter-policy-go.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* GoAdapterPolicy - policy for Go Debug Adapter (Delve/dlv)
*
* Encodes Delve-specific behaviors and variable handling logic.
* Delve operates in DAP mode via `dlv dap --listen=:port`
* Delve operates in DAP mode via `dlv dap --listen=127.0.0.1:<port>`
*/
import type { DebugProtocol } from '@vscode/debugprotocol';
import * as path from 'path';
Expand Down
2 changes: 1 addition & 1 deletion skills/debugging/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ attach_to_process {sessionId, host: "localhost", port: 5678, sourcePaths: ["<loc
- **Python**: target ran `python -m debugpy --listen <host>:<port> ...`; to address breakpoints by local-checkout path, map it onto the debuggee tree with `adapterConfig: {pathMappings: [{localRoot: "<abs local>", remoteRoot: "/app"}]}`
- **Ruby**: target ran `rdbg --open --port <port> ...` (works through `kubectl port-forward`); `localfsMap: "/app:<abs local dir>"` maps paths
- **JavaScript**: target ran `node --inspect=<host>:<port> ...` → attach by `host`/`port`; a plain `node app.js` on the same host → attach by `processId` (mcp-debugger opens its inspector on 9229, and it stays open, unauthenticated, after detach and close: #1261 — pass `port` too if the target set `--inspect-port=<n>`)
- **Java**: target JVM has `-agentlib:jdwp=transport=dt_socket,server=y,address=*:<port>`; breakpoints in not-yet-loaded classes are deferred automatically, and a fully-qualified class name as `file` needs no source files at all
- **Java**: target JVM has `-agentlib:jdwp=transport=dt_socket,server=y,address=127.0.0.1:<port>`. JDWP has no authentication, so keep it on loopback: that serves this machine, an in-pod sidecar and an SSH tunnel to another machine. A JVM in a Docker container reached through a published port needs `*` in place of `127.0.0.1`: publish that port on the host's loopback (`-p 127.0.0.1:<port>:<port>`). Breakpoints in not-yet-loaded classes are deferred automatically, and a fully-qualified class name as `file` needs no source files at all
- **C/C++ (and other native)**: attach by PID instead of port — `attach_to_process {sessionId, processId: <pid>, adapterConfig: {program: "<path to binary>"}}`; in a Kubernetes ephemeral debug container use `processId: 1` with `program: "/proc/1/root/<binary path>"` (on Linux, mind `kernel.yama.ptrace_scope`)
- **COBOL**: attach by PID like C/C++, plus `adapterConfig: {sources: ["<abs .cob>", …], dialect: "ibm"}` (the manifest is regenerated by a translate-only `cobc -C`; pass the options the binary was built with) or `adapterConfig: {manifestDirs: ["<dir holding *.cobol-symbols.json>"]}` (an earlier source launch's `.debug-mcp/cobol/<platform>-<arch>[-container]/<name>/<buildKey>/`, needs no cobc) so variables are COBOL-shaped; without either only the engine's C view is available. A job paused inside libcob still shows its program's data division (scopes from the nearest COBOL frame up the stack)
- **Dart/Flutter**: attach by VM-service URI, never by PID — `attach_to_process {sessionId, adapterConfig: {vmServiceUri: "ws://127.0.0.1:<port>/<token>=/ws"}}` (the URI a `dart --enable-vm-service … run` target prints, or `flutter run --machine`'s `app.debugPort` event) or `adapterConfig: {vmServiceInfoFile: "<file written by --write-service-info>"}`; a bare `host`/`port` only works for a VM started with `--disable-service-auth-codes`. The `dart-test`/`flutter-test` runners refuse attach. An isolate idle in an `await` shows an empty stack at the attach pause — set a breakpoint and `continue_execution`, or attach with `stopOnEntry: false`
Expand Down
2 changes: 1 addition & 1 deletion skills/debugging/references/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ close_debug_session {"sessionId": "<id>"}
Start the target JVM with the JDWP agent (`suspend=y` pauses until a debugger attaches; `suspend=n` for already-running servers):

```bash
java -agentlib:jdwp=transport=dt_socket,server=y,address=5005,suspend=y -cp . MyServer
java -agentlib:jdwp=transport=dt_socket,server=y,address=127.0.0.1:5005,suspend=y -cp . MyServer
```

```json
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/network-manager-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class NetworkManagerImpl implements INetworkManager {
const server = net.createServer();
server.unref();
server.on('error', reject);
server.listen(0, () => {
server.listen(0, '127.0.0.1', () => {
const address = server.address();
if (address && typeof address === 'object' && 'port' in address) {
const port = address.port;
Expand Down
2 changes: 1 addition & 1 deletion src/server/tool-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export function buildToolDefinitions(options: BuildToolDefinitionsOptions): Tool
}
},
{ name: 'restart_debugging', description: 'Restart the debuggee: terminate the current program (if still running) and relaunch it with the same configuration as the last start_debugging. All current breakpoints are re-applied automatically. The get_output buffer starts fresh — read from since=0 after a restart. A Flutter session hot-restarts in place instead, an attached one included: same process, output buffer kept, and the answer carries hotRestart: true. Works while running, paused, or after the program has exited. Not available for sessions never launched, or for attach sessions of the other adapters (detach and re-attach). Answers like start_debugging, including "running" with pending:true when the relaunch has not stopped within the same short hold (then call wait_for_stop)', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' } }, required: ['sessionId'] } },
{ name: 'attach_to_process', description: `Attach to a running process for debugging. After the handshake the target is verified by polling for threads; if none are reported within verifyTimeout (~20s default) the attach fails and the proxy is torn down. When a requested post-attach pause is accepted but no stopped event arrives within its bounded wait, returns state "running" with pending:true; the late event alone changes the session to "paused" — call wait_for_stop to block until it does. The target is started under its debugger or named by processId: Python python -m debugpy --listen <host:port>; Ruby rdbg --open --port <N>; Node.js node --inspect (host, port), or a local node process by processId; Java -agentlib:jdwp=transport=dt_socket,server=y,address=*:<port>; C/C++, COBOL and .NET by processId; Dart and Flutter a VM service (adapterConfig.vmServiceUri or vmServiceInfoFile; a Flutter app on an Android device: adapterConfig.deviceId). list_supported_languages shows each language's forms (attachBy). Breakpoint paths are resolved on the target's filesystem: ${attachPathForms} (Python: adapterConfig.pathMappings [{localRoot, remoteRoot}]; Ruby: adapterConfig.localfsMap "<target dir>:<local dir>"). Kubernetes pods (port-forward or an ephemeral sidecar, per-language presets): docs/kubernetes.md in the mcp-debugger repo`, inputSchema: {
{ name: 'attach_to_process', description: `Attach to a running process for debugging. After the handshake the target is verified by polling for threads; if none are reported within verifyTimeout (~20s default) the attach fails and the proxy is torn down. When a requested post-attach pause is accepted but no stopped event arrives within its bounded wait, returns state "running" with pending:true; the late event alone changes the session to "paused" — call wait_for_stop to block until it does. The target is started under its debugger or named by processId: Python python -m debugpy --listen <host:port>; Ruby rdbg --open --port <N>; Node.js node --inspect (host, port), or a local node process by processId; Java -agentlib:jdwp=transport=dt_socket,server=y,address=127.0.0.1:<port> (a JVM in a Docker container reached through a published port needs * in place of 127.0.0.1, with -p 127.0.0.1:<port>:<port>); C/C++, COBOL and .NET by processId; Dart and Flutter a VM service (adapterConfig.vmServiceUri or vmServiceInfoFile; a Flutter app on an Android device: adapterConfig.deviceId). list_supported_languages shows each language's forms (attachBy). Breakpoint paths are resolved on the target's filesystem: ${attachPathForms} (Python: adapterConfig.pathMappings [{localRoot, remoteRoot}]; Ruby: adapterConfig.localfsMap "<target dir>:<local dir>"). Kubernetes pods (port-forward or an ephemeral sidecar, per-language presets): docs/kubernetes.md in the mcp-debugger repo`, inputSchema: {
type: 'object',
properties: {
sessionId: { type: 'string', description: 'Debug session ID' },
Expand Down
5 changes: 3 additions & 2 deletions src/skill-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* `instructions` field); DEBUGGING_WORKFLOW_PROMPT backs the
* `debugging-workflow` prompt. Both are condensed views of the full agent
* skill in skills/debugging/ — when editing one, check the other and the
* skill for drift.
* skill for drift. The Java loopback recipe is pinned across these surfaces
* by tests/core/unit/server/server-instructions.test.ts.
*
* Both texts are built per addressing mode (issue #271): the
* DEBUG_MCP_BP_ADDRESSING flag must hide content-addressing features from
Expand Down Expand Up @@ -205,7 +206,7 @@ attach_to_process {sessionId, host, port, sourcePaths, adapterConfig}
- Python: target started with "python -m debugpy --listen host:port ..."; map a local checkout onto the debuggee tree with adapterConfig: {pathMappings: [{localRoot, remoteRoot}]}
- Ruby: target started with "rdbg --open --port N ..." (works via kubectl port-forward); localfsMap: "/app:<abs local dir>" maps paths
- JavaScript: host/port of a "node --inspect" target, or processId of a plain local node process (its inspector is opened for you on 9229 and stays open, unauthenticated, after detach and close: #1261; pass port too for an --inspect-port target)
- Java: JVM flag -agentlib:jdwp=transport=dt_socket,server=y,address=*:PORT (breakpoints defer until class load); FQCN as "file" needs no source at all
- Java: JVM flag -agentlib:jdwp=transport=dt_socket,server=y,address=127.0.0.1:PORT (breakpoints defer until class load); a JVM in a Docker container reached through a published port needs * in place of 127.0.0.1, with -p 127.0.0.1:PORT:PORT; reach another machine through an SSH tunnel. FQCN as "file" needs no source at all
- C/C++ (and other native): attach by PID — attach_to_process {sessionId, processId, adapterConfig: {program: "<binary path>"}}
- COBOL: attach by PID like C/C++; add adapterConfig: {sources: ["<abs .cob>", …]} (the manifest is regenerated by a translate-only cobc -C) or adapterConfig: {manifestDirs: ["<.debug-mcp/cobol/<platform>-<arch>/<name>/<buildKey> dir of the running build>"]} so the shim finds the symbol manifest, or variables show only the engine's C view
- Dart/Flutter: attach to a running VM service — pass adapterConfig.vmServiceUri or vmServiceInfoFile, not a PID (the SDK adapter is spawned locally and connects to the VM service); a Flutter app on an Android device or emulator takes adapterConfig.deviceId alone with no URI (flutter attach discovers it; the app.debugPort URI of another flutter run is that tool's own DDS and never connects)
Expand Down
6 changes: 6 additions & 0 deletions tests/adapters/java/unit/java-adapter-factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ describe('JavaAdapterFactory', () => {
const metadata = factory.getMetadata();
expect(metadata.documentationUrl).toContain('github.com');
});

it('recommends loopback for the local JDWP attach port (#1389)', () => {
expect(factory.getMetadata().modes?.attachHints?.processId).toContain(
'-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:<port>'
);
});
});

describe('validate', () => {
Expand Down
Loading
Loading