attach
:
Instructions
Attach debugger to a running .NET process
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| processId | Yes | Process ID to attach to | |
| sessionId | No | Session ID for this debug session (auto-generated if not specified) |
Implementation Reference
- src/session.ts:166-184 (handler)The DebugSession.attach() method that implements the core attach logic. Creates a DAP client, initializes it, and attaches to the specified process ID. Saves session config with mode: 'attach'.
async attach(processId: number): Promise<void> { // Clear any existing state await this.cleanup(); this.dapClient = new DAPClient(); this.setupEventHandlers(); await this.dapClient.start(); await this.dapClient.attach(processId); // Save session config this.config = { program: `process:${processId}`, resolvedEnv: {}, processId, startTime: new Date(), mode: "attach", }; } - src/tools/launch-tools.ts:87-112 (registration)Registration of the 'attach' tool with the MCP server using server.tool(). Includes tool name, description, Zod schema for parameters, and the async handler that creates a session and calls session.attach().
// Tool: attach server.tool( "attach", "Attach debugger to a running .NET process", { processId: z.number().describe("Process ID to attach to"), sessionId: z .string() .optional() .describe("Session ID for this debug session (auto-generated if not specified)"), }, async ({ processId, sessionId }) => { // Derive session ID if not specified const derivedSessionId = sessionId || `process-${processId}`; const session = sessionManager.createSession(derivedSessionId); try { await session.attach(processId); return textResponse(`${sessionPrefix(session.id)}Attached to process ${processId}\nSession ID: ${session.id}`); } catch (err) { await sessionManager.removeSession(session.id); throw err; } } ); - src/tools/launch-tools.ts:91-97 (schema)Zod schema defining the input parameters for the 'attach' tool: processId (required number) and sessionId (optional string).
{ processId: z.number().describe("Process ID to attach to"), sessionId: z .string() .optional() .describe("Session ID for this debug session (auto-generated if not specified)"), }, - src/dap-client.ts:277-283 (helper)Low-level DAPClient.attach() helper method that sends the DAP 'attach' request with the process ID to the netcoredbg debugger, followed by configurationDone.
async attach(processId: number): Promise<void> { await this.sendRequest("attach", { processId, }); await this.sendRequest("configurationDone", {}); }