Skip to main content
Glama

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

NameRequiredDescriptionDefault
expressionYesPHP 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

  • 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, }, }), }, ], }; }
  • 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)')"), },
  • 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, }, }), }, ], }; } );
  • 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; }
  • 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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kpanuragh/xdebug-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server