Skip to main content
Glama
maderwin

pinchtab-mcp

Wait for Selector

pinchtab_wait_for_selector

Wait for a CSS selector to appear on the page, polling every 500ms until timeout. Useful for dynamic content, modals, or lazy-loaded elements.

Instructions

Wait for a CSS selector to appear on the page. Polls every 500ms up to the timeout. Useful for waiting on dynamic content, modals, or lazy-loaded elements.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector to wait for (e.g. '#login-form', '.loaded', '[data-ready]')
timeoutMsNoMaximum wait time in ms (default: 5000, max: 15000).

Implementation Reference

  • Registration of the 'pinchtab_wait_for_selector' tool via server.registerTool().
    server.registerTool(
      "pinchtab_wait_for_selector",
      {
        description:
          "Wait for a CSS selector to appear on the page. Polls every 500ms up to the timeout. Useful for waiting on dynamic content, modals, or lazy-loaded elements.",
        inputSchema: z.object({
          selector: z
            .string()
            .describe("CSS selector to wait for (e.g. '#login-form', '.loaded', '[data-ready]')"),
          timeoutMs: z
            .number()
            .optional()
            .describe("Maximum wait time in ms (default: 5000, max: 15000)."),
        }),
        title: "Wait for Selector",
      },
      async ({ selector, timeoutMs }) => {
        const timeout = Math.min(timeoutMs ?? SELECTOR_TIMEOUT_DEFAULT, SELECTOR_TIMEOUT_MAX);
        const deadline = Date.now() + timeout;
        try {
          while (Date.now() < deadline) {
            const result = await pinch("POST", "/evaluate", {
              expression: `!!document.querySelector(${JSON.stringify(selector)})`,
            });
            const found =
              result === true ||
              result === "true" ||
              (typeof result === "object" &&
                result !== null &&
                (result as Record<string, unknown>).result === true);
            if (found) return toolResult({ found: true, selector });
            await new Promise((resolve) => setTimeout(resolve, SELECTOR_POLL_MS));
          }
          return toolError(new Error(`Selector "${selector}" not found within ${timeout}ms`));
        } catch (error) {
          return toolError(error);
        }
      },
    );
  • Handler function for pinchtab_wait_for_selector: polls document.querySelector every 500ms until selector is found or timeout.
    async ({ selector, timeoutMs }) => {
      const timeout = Math.min(timeoutMs ?? SELECTOR_TIMEOUT_DEFAULT, SELECTOR_TIMEOUT_MAX);
      const deadline = Date.now() + timeout;
      try {
        while (Date.now() < deadline) {
          const result = await pinch("POST", "/evaluate", {
            expression: `!!document.querySelector(${JSON.stringify(selector)})`,
          });
          const found =
            result === true ||
            result === "true" ||
            (typeof result === "object" &&
              result !== null &&
              (result as Record<string, unknown>).result === true);
          if (found) return toolResult({ found: true, selector });
          await new Promise((resolve) => setTimeout(resolve, SELECTOR_POLL_MS));
        }
        return toolError(new Error(`Selector "${selector}" not found within ${timeout}ms`));
      } catch (error) {
        return toolError(error);
      }
    },
  • Input schema using zod: requires 'selector' (string), optional 'timeoutMs' (number, default 5000, max 15000).
    {
      description:
        "Wait for a CSS selector to appear on the page. Polls every 500ms up to the timeout. Useful for waiting on dynamic content, modals, or lazy-loaded elements.",
      inputSchema: z.object({
        selector: z
          .string()
          .describe("CSS selector to wait for (e.g. '#login-form', '.loaded', '[data-ready]')"),
        timeoutMs: z
          .number()
          .optional()
          .describe("Maximum wait time in ms (default: 5000, max: 15000)."),
      }),
      title: "Wait for Selector",
    },
  • Constants used by the tool: SELECTOR_POLL_MS (500), SELECTOR_TIMEOUT_DEFAULT (5000), SELECTOR_TIMEOUT_MAX (15000).
    const SELECTOR_POLL_MS = 500;
    const SELECTOR_TIMEOUT_DEFAULT = 5000;
    const SELECTOR_TIMEOUT_MAX = 15_000;
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must disclose all behavioral traits. It mentions polling interval (500ms) and timeout, but does not specify return value, error behavior on timeout, or whether it waits for visibility vs. presence. This is a partial disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, front-loaded with purpose and polling detail, then use cases. No wasted words, efficient and clear.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description lacks return value information (e.g., what is returned when element appears or times out) and does not mention error scenarios. Given no output schema, this is a gap. However, the tool is simple and the description covers core behavior.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, but the description adds value beyond the schema by explaining polling behavior and providing usage examples for the selector parameter. The timeout default and max are also mentioned.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool waits for a CSS selector to appear, which distinguishes it from sibling tools like pinchtab_wait that may be a generic delay. The verb 'wait' is paired with the specific resource 'CSS selector'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit use cases: waiting on dynamic content, modals, or lazy-loaded elements. It does not specify when not to use or differentiate from alternatives like pinchtab_wait, but the context is clear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/maderwin/pinchtab-mcp'

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