Skip to main content
Glama

attach

Attach to a running Go process by specifying its process ID (PID) for debugging and analysis using the Delve debugger interface.

Instructions

Attach to a running process

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pidYesProcess ID to attach to

Implementation Reference

  • The main handler function for the 'attach' tool. Validates the PID argument, starts a new debug session using startDebugSession with type 'attach', and returns a success message with the session ID.
    case "attach": { const pid = Number(args?.pid); if (!pid) { throw new Error("Process ID is required"); } const session = await startDebugSession("attach", pid.toString()); return { content: [{ type: "text", text: `Attached to process ${pid} with session ${session.id}` }] }; }
  • Core helper function that implements the attachment by spawning the Delve debugger ('dlv') process with 'attach' mode, PID as target, assigns a random ID, finds available port, and manages the session.
    export async function startDebugSession(type: string, target: string, args: string[] = []): Promise<DebugSession> { const port = await getAvailablePort(); const id = Math.random().toString(36).substring(7); const dlvArgs = [ type, "--headless", `--listen=:${port}`, "--accept-multiclient", "--api-version=2", target, ...args ]; const process = spawn("dlv", dlvArgs, { stdio: ["pipe", "pipe", "pipe"] }); const session: DebugSession = { id, type, target, process, port, breakpoints: new Map() }; sessions.set(id, session); return session; }
  • src/server.ts:406-407 (registration)
    Routes calls to the 'attach' tool (and other debug tools) to the handleDebugCommands function in the CallToolRequestHandler.
    if (["debug", "attach", "exec", "test", "core", "dap", "replay", "trace"].includes(name)) { return handleDebugCommands(name, args);
  • Registers the 'attach' tool in ListTools response, providing name, description, and input schema requiring a numeric 'pid'.
    { name: "attach", description: "Attach to a running process", inputSchema: { type: "object", properties: { pid: { type: "number", description: "Process ID to attach to" } }, required: ["pid"] } },

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dwisiswant0/delve-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server