Skip to main content
Glama

add_watch

Monitor PHP variable values during debugging by adding watch expressions that evaluate on each breakpoint.

Instructions

Add a watch expression that will be evaluated on each break. Watch expressions persist across steps.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expressionYesPHP expression to watch (e.g., '$user->id', 'count($items)')

Implementation Reference

  • Handler function for the 'add_watch' tool. It calls ctx.watchManager.addWatch(expression) to add the watch and returns a success response with the watch ID and 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,
              },
            }),
          },
        ],
      };
    }
  • Registration of the 'add_watch' MCP tool on the server, including name, description, input schema, and handler.
      '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,
                },
              }),
            },
          ],
        };
      }
    );
  • Input schema for the 'add_watch' tool, defining the 'expression' parameter as a string.
    expression: z.string().describe("PHP expression to watch (e.g., '$user->id', 'count($items)')"),
  • Core implementation of adding a watch expression in WatchManager class. Creates a unique ID, initializes WatchExpression object, stores it in a Map, and logs the addition.
    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 add_watch tool.
      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