Skip to main content
Glama
maderwin

pinchtab-mcp

Evaluate JavaScript

pinchtab_eval

Execute JavaScript in the active browser page and return the result. Enables custom automation scripts.

Instructions

Execute JavaScript code in the page context. Returns the result of the expression.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesJavaScript code to execute in the page

Implementation Reference

  • The tool handler function for 'pinchtab_eval'. It sends the code to the PinchTab server via POST /evaluate with the expression, then formats the result as text. Uses the pinch() client helper.
      async ({ code }) => {
        try {
          const result = await pinch("POST", "/evaluate", { expression: code });
          const text =
            isRecord(result) && "result" in result ? String(result.result) : toJson(result);
          return { content: [{ text, type: "text" as const }] };
        } catch (error) {
          return toolError(error);
        }
      },
    );
  • Input schema for pinchtab_eval: expects a single required string parameter 'code' — JavaScript code to execute in the page context.
    inputSchema: z.object({
      code: z.string().describe("JavaScript code to execute in the page"),
    }),
  • Registration of the 'pinchtab_eval' tool via server.registerTool() with the name, description, schema, and handler. Located in registerContentTools() which is called from registerAllTools() in src/tools/index.ts.
    server.registerTool(
      "pinchtab_eval",
      {
        description:
          "Execute JavaScript code in the page context. Returns the result of the expression.",
        inputSchema: z.object({
          code: z.string().describe("JavaScript code to execute in the page"),
        }),
        title: "Evaluate JavaScript",
      },
      async ({ code }) => {
        try {
          const result = await pinch("POST", "/evaluate", { expression: code });
          const text =
            isRecord(result) && "result" in result ? String(result.result) : toJson(result);
          return { content: [{ text, type: "text" as const }] };
        } catch (error) {
          return toolError(error);
        }
      },
    );
  • The pinch() helper function used by the handler to make HTTP requests to the PinchTab server. pinchtab_eval calls pinch('POST', '/evaluate', { expression: code }).
    export async function pinch(
      method: string,
      path: string,
      body?: Record<string, unknown>,
    ): Promise<unknown> {
      if (!(await isPinchtabRunning())) {
        await ensurePinchtabRunning();
      }
    
      const headers: Record<string, string> = {
        "Content-Type": "application/json",
      };
      if (PINCHTAB_TOKEN) {
        headers["Authorization"] = `Bearer ${PINCHTAB_TOKEN}`;
      }
    
      const url = `${PINCHTAB_URL}${path}`;
    
      let res: Response;
      try {
        res = await fetch(url, {
          body: body ? JSON.stringify(body) : undefined,
          headers,
          method,
          signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
        });
      } catch (error) {
        if (error instanceof DOMException && error.name === "TimeoutError") {
          throw new Error(`PinchTab ${method} ${path} timed out after ${REQUEST_TIMEOUT_MS / 1000}s`);
        }
        throw error;
      }
    
      if (!res.ok) {
        const text = await res.text();
        throw new Error(`PinchTab ${method} ${path} → ${res.status}: ${text}`);
      }
    
      const contentType = (res.headers.get("content-type") ?? "").split(";")[0].toLowerCase().trim();
      if (contentType === "application/json") {
        return res.json();
      }
      return res.text();
    }
  • Utility functions (isRecord, toJson, toolError) used by the handler to process the response and format errors.
    /** Type guard: checks that a value is a non-null object (record). */
    export function isRecord(value: unknown): value is Record<string, unknown> {
      return typeof value === "object" && value !== null;
    }
    
    /** Pretty-print a value as indented JSON. */
    export function toJson(value: unknown): string {
      return JSON.stringify(value, undefined, 2);
    }
    
    interface ToolResult {
      [key: string]: unknown;
      content: { text: string; type: "text" }[];
      isError?: boolean;
    }
    
    /** Wrap a tool handler with standardized error handling. */
    export function toolResult(data: unknown): ToolResult {
      return { content: [{ text: toJson(data), type: "text" as const }] };
    }
    
    /** Format an error as an MCP tool error response. */
    export function toolError(error: unknown): ToolResult {
      const message = error instanceof Error ? error.message : String(error);
      return {
        content: [{ text: message, type: "text" as const }],
        isError: true,
      };
    }
Behavior3/5

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

No annotations are provided, so the description carries full burden. It states that code is executed 'in the page context' and returns a result, which is accurate but minimal. It does not disclose potential side effects, security implications, or what happens to the page state. Since there is no contradiction with annotations (none exist), a score of 3 is appropriate.

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

Conciseness4/5

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

The description is brief and front-loaded, with two sentences that convey the core action and return value. No unnecessary words. However, it could be improved by including context about the execution environment or return value type, but it is appropriately sized for a simple tool.

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?

Given no output schema, the description mentions the return value, which is helpful. However, it lacks details about the types of expressions supported, error handling, or whether asynchronous code is allowed. The tool has only one parameter, so completeness is adequate but not thorough.

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

Parameters3/5

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

Schema description coverage is 100%, so the baseline is 3. The description adds minimal extra meaning beyond the schema by specifying 'JavaScript code' and 'in the page context'. The schema already describes the parameter as 'JavaScript code to execute in the page', so the description does not significantly enhance understanding.

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

Purpose4/5

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

The description clearly states the action 'Execute JavaScript code' and the resource 'in the page context', indicating a specific verb-resource pair. It also mentions the return value, which distinguishes it from other tools that perform actions on the page without returning results. However, it does not explicitly differentiate from sibling tools like pinchtab_get_text, which is a related but distinct operation.

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

Usage Guidelines2/5

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

There is no guidance on when to use this tool versus alternatives. For example, it does not clarify whether to use this tool instead of pinchtab_get_text for extracting text content. The description lacks context about prerequisites, limitations, or exclusions.

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