evaluate
Compute expression values in the current debug context to inspect variables and execution state. Specify a stack frame ID to target a specific scope.
Instructions
Evaluate an expression in the current debug context
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | Expression to evaluate | |
| frameId | No | Stack frame ID for context (from stack_trace) | |
| sessionId | No | Session ID (defaults to current session). Use list_sessions to see available sessions. |
Implementation Reference
- src/tools/inspection-tools.ts:98-104 (handler)The main handler function for the 'evaluate' tool. Receives the expression, frameId, and sessionId, calls session.evaluate(), and formats the result as a text response.
async ({ expression, frameId, sessionId }) => { const session = sessionManager.getSession(sessionId); const result = await session.evaluate(expression, frameId); const type = result.type ? ` (${result.type})` : ""; return textResponse(`${sessionPrefix(session.id)}${expression}${type} = ${result.result}`); } - src/tools/inspection-tools.ts:87-105 (registration)The MCP tool registration for 'evaluate'. Registers the tool with name, description, Zod schema for parameters (expression, frameId, sessionId), and the handler function.
server.tool( "evaluate", "Evaluate an expression in the current debug context", { expression: z.string().describe("Expression to evaluate"), frameId: z .number() .optional() .describe("Stack frame ID for context (from stack_trace)"), sessionId: sessionIdParam, }, async ({ expression, frameId, sessionId }) => { const session = sessionManager.getSession(sessionId); const result = await session.evaluate(expression, frameId); const type = result.type ? ` (${result.type})` : ""; return textResponse(`${sessionPrefix(session.id)}${expression}${type} = ${result.result}`); } ); - src/session.ts:518-521 (helper)Session-level helper that wraps the DAP client evaluate call. Validates client is connected before forwarding the request.
async evaluate(expression: string, frameId?: number): Promise<{ result: string; type?: string; variablesReference: number }> { const client = this.requireClient(); return client.evaluate(expression, frameId); } - src/dap-client.ts:371-388 (helper)DAP client implementation that sends the actual 'evaluate' request to the debug adapter. Handles the protocol-level communication and returns the response body.
async evaluate( expression: string, frameId?: number, context: "watch" | "repl" | "hover" = "repl" ): Promise<{ result: string; type?: string; variablesReference: number }> { const response = await this.sendRequest("evaluate", { expression, frameId, context, }); const body = response.body as { result: string; type?: string; variablesReference: number; }; return body; }