test
Debug and test Go packages with custom flags using Delve MCP, enabling precise code analysis and troubleshooting in a TypeScript-based environment.
Instructions
Debug tests in a package
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| package | No | Package to test (defaults to current directory) | |
| testFlags | No | Flags to pass to go test |
Implementation Reference
- src/handlers/debug.ts:54-65 (handler)The handler function for the 'test' tool. Extracts parameters (package and testFlags), starts a Delve debug session for Go tests, and returns a success message with session ID.case "test": { const pkg = (args?.package as string) || "."; const testFlags = (args?.testFlags as string[]) || []; const session = await startDebugSession("test", pkg, ["--", ...testFlags]); return { content: [{ type: "text", text: `Started test debug session ${session.id} for package ${pkg}` }] }; }
- src/server.ts:118-135 (schema)Defines the input schema, name, and description for the 'test' tool, used in tool listing.{ name: "test", description: "Debug tests in a package", inputSchema: { type: "object", properties: { package: { type: "string", description: "Package to test (defaults to current directory)" }, testFlags: { type: "array", items: { type: "string" }, description: "Flags to pass to go test" } } } },
- src/server.ts:406-408 (registration)Registers the 'test' tool by checking the tool name in the CallToolRequestHandler and dispatching to handleDebugCommands.if (["debug", "attach", "exec", "test", "core", "dap", "replay", "trace"].includes(name)) { return handleDebugCommands(name, args); }
- src/session.ts:35-64 (helper)Core helper function that spawns the Delve debugger process (dlv) with the 'test' mode, target package, and test flags, creating and registering a debug 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; }