evaluate_watches
Retrieve current values of all active watch expressions during PHP debugging sessions to monitor variable changes and program state.
Instructions
Evaluate all watch expressions and return their current values
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | No | Session ID |
Implementation Reference
- src/tools/advanced.ts:80-119 (handler)MCP tool registration and inline handler for 'evaluate_watches'. Resolves the debug session (optionally by ID), evaluates all watch expressions, detects changes, and returns formatted JSON response with watch values, errors, and change count.server.tool( 'evaluate_watches', 'Evaluate all watch expressions and return their current values', { session_id: z.string().optional().describe('Session ID'), }, async ({ session_id }) => { const session = ctx.sessionManager.resolveSession(session_id); if (!session) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'No active session' }) }], }; } const results = await ctx.watchManager.evaluateAll(session); const changedWatches = results.filter((r) => r.hasChanged); return { content: [ { type: 'text', text: JSON.stringify( { watches: results.map((r) => ({ id: r.id, expression: r.expression, value: r.value, hasChanged: r.hasChanged, error: r.error, })), changedCount: changedWatches.length, }, null, 2 ), }, ], }; } );
- src/tools/advanced.ts:83-85 (schema)Input schema using Zod: optional 'session_id' string to target a specific debug session.{ session_id: z.string().optional().describe('Session ID'), },
- src/session/watch-manager.ts:78-90 (helper)WatchManager.evaluateAll(): Iterates over all watches and evaluates each one using evaluateWatch, returning array of results. Called directly by the tool handler.async evaluateAll( session: DebugSession, stackDepth: number = 0 ): Promise<WatchEvaluationResult[]> { const results: WatchEvaluationResult[] = []; for (const watch of this.watches.values()) { const result = await this.evaluateWatch(session, watch, stackDepth); results.push(result); } return results; }
- src/session/watch-manager.ts:95-139 (helper)WatchManager.evaluateWatch(): Performs the actual evaluation of a single watch expression via session.evaluate(), handles errors, detects value changes using hasValueChanged, updates watch state and emits events.async evaluateWatch( session: DebugSession, watch: WatchExpression, stackDepth: number = 0 ): Promise<WatchEvaluationResult> { try { const value = await session.evaluate(watch.expression, stackDepth); // Track previous value for change detection watch.previousValue = watch.lastValue; watch.lastValue = value; watch.lastEvaluatedAt = new Date(); watch.evaluationCount++; watch.errorMessage = undefined; // Detect changes watch.hasChanged = this.hasValueChanged(watch.previousValue, watch.lastValue); if (watch.hasChanged) { this.emit('watchChanged', watch); } return { id: watch.id, expression: watch.expression, value, previousValue: watch.previousValue || null, hasChanged: watch.hasChanged, }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); watch.errorMessage = errorMessage; watch.lastEvaluatedAt = new Date(); watch.evaluationCount++; return { id: watch.id, expression: watch.expression, value: null, previousValue: watch.previousValue || null, hasChanged: false, error: errorMessage, }; } }