evaluate
Evaluate a Go expression within an active debug session to inspect variables and test code logic.
Instructions
Evaluate an expression in current scope
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | ID of the debug session | |
| expr | Yes | Expression to evaluate |
Implementation Reference
- src/handlers/control.ts:102-111 (handler)The handler function that executes the 'evaluate' tool. It extracts the 'expr' argument, sends an 'Eval' command to the Delve debugger via sendDelveCommand, and returns the result as JSON.
case "evaluate": { const { expr } = args; const response = await sendDelveCommand(session, "Eval", { expr }); return { content: [{ type: "text", text: JSON.stringify(response.Variable, null, 2) }] }; } - src/server.ts:251-268 (registration)Registration of the 'evaluate' tool in the ListToolsRequestSchema handler. Defines the tool's name, description, and input schema requiring 'sessionId' (string) and 'expr' (string).
{ name: "evaluate", description: "Evaluate an expression in current scope", inputSchema: { type: "object", properties: { sessionId: { type: "string", description: "ID of the debug session" }, expr: { type: "string", description: "Expression to evaluate" } }, required: ["sessionId", "expr"] } }, - src/server.ts:411-413 (registration)The CallToolRequestSchema handler that routes the 'evaluate' tool name to handleControlCommands.
if (["setBreakpoint", "removeBreakpoint", "continue", "next", "step", "stepout", "variables", "evaluate"].includes(name)) { return handleControlCommands(name, args); } - src/session.ts:69-72 (helper)The sendDelveCommand helper used by the evaluate handler to send the 'Eval' API command to the Delve debugger via HTTP POST.
export async function sendDelveCommand(session: DebugSession, command: string, args: any = {}): Promise<any> { const { stdout } = await exec(`curl -s -X POST http://localhost:${session.port}/api/v2/${command} -d '${JSON.stringify(args)}'`); return JSON.parse(stdout); }