add_watch
Monitor PHP variable values during debugging by adding persistent watch expressions that evaluate on each breakpoint hit.
Instructions
Add a watch expression that will be evaluated on each break. Watch expressions persist across steps.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | PHP expression to watch (e.g., '$user->id', 'count($items)') |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"expression": {
"description": "PHP expression to watch (e.g., '$user->id', 'count($items)')",
"type": "string"
}
},
"required": [
"expression"
],
"type": "object"
}
Implementation Reference
- src/tools/advanced.ts:42-58 (handler)MCP tool handler for 'add_watch': calls ctx.watchManager.addWatch(expression) and returns JSON response with success and watch details (id, expression).async ({ expression }) => { const watch = ctx.watchManager.addWatch(expression); return { content: [ { type: 'text', text: JSON.stringify({ success: true, watch: { id: watch.id, expression: watch.expression, }, }), }, ], }; }
- src/tools/advanced.ts:39-41 (schema)Input schema for 'add_watch' tool using Zod: requires 'expression' string parameter.{ expression: z.string().describe("PHP expression to watch (e.g., '$user->id', 'count($items)')"), },
- src/tools/advanced.ts:36-59 (registration)Registers the 'add_watch' tool on the MCP server with name, description, input schema, and handler function.server.tool( 'add_watch', 'Add a watch expression that will be evaluated on each break. Watch expressions persist across steps.', { expression: z.string().describe("PHP expression to watch (e.g., '$user->id', 'count($items)')"), }, async ({ expression }) => { const watch = ctx.watchManager.addWatch(expression); return { content: [ { type: 'text', text: JSON.stringify({ success: true, watch: { id: watch.id, expression: watch.expression, }, }), }, ], }; } );
- src/session/watch-manager.ts:40-52 (helper)Core implementation of addWatch in WatchManager: generates unique ID, creates WatchExpression object, stores in Map, logs, and returns the watch.addWatch(expression: string): WatchExpression { const id = `watch_${++this.watchIdCounter}`; const watch: WatchExpression = { id, expression, hasChanged: false, evaluationCount: 0, createdAt: new Date(), }; this.watches.set(id, watch); logger.debug(`Watch added: ${id} = ${expression}`); return watch; }
- src/session/watch-manager.ts:11-21 (schema)TypeScript interface defining the structure of a WatchExpression used by the watch system.export interface WatchExpression { id: string; expression: string; lastValue?: Property | null; previousValue?: Property | null; hasChanged: boolean; errorMessage?: string; evaluationCount: number; createdAt: Date; lastEvaluatedAt?: Date; }