Skip to main content
Glama
pvinis
by pvinis

playwright_console_logs

Extract and filter browser console logs by type, search text, or limit results. Optionally clear logs after retrieval for efficient debugging in Playwright MCP Server.

Instructions

Retrieve console logs from the browser with filtering options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
clearNoWhether to clear logs after retrieval (default: false)
limitNoMaximum number of logs to return
searchNoText to search for in logs (handles text with square brackets)
typeNoType of logs to retrieve (all, error, warning, log, info, debug)

Implementation Reference

  • The execute method implements the core tool logic: filters stored console logs by type, search term, and limit; optionally clears them; and returns formatted response.
    async execute(args: any, context: ToolContext): Promise<ToolResponse> {
      // No need to use safeExecute here as we don't need to interact with the page
      // We're just filtering and returning logs that are already stored
      
      let logs = [...this.consoleLogs];
      
      // Filter by type if specified
      if (args.type && args.type !== 'all') {
        logs = logs.filter(log => log.startsWith(`[${args.type}]`));
      }
      
      // Filter by search text if specified
      if (args.search) {
        logs = logs.filter(log => log.includes(args.search));
      }
      
      // Limit the number of logs if specified
      if (args.limit && args.limit > 0) {
        logs = logs.slice(-args.limit);
      }
      
      // Clear logs if requested
      if (args.clear) {
        this.consoleLogs = [];
      }
      
      // Format the response
      if (logs.length === 0) {
        return createSuccessResponse("No console logs matching the criteria");
      } else {
        return createSuccessResponse([
          `Retrieved ${logs.length} console log(s):`,
          ...logs
        ]);
      }
    }
  • Defines the tool's input schema, description, and name for MCP protocol validation.
    {
      name: "playwright_console_logs",
      description: "Retrieve console logs from the browser with filtering options",
      inputSchema: {
        type: "object",
        properties: {
          type: {
            type: "string",
            description: "Type of logs to retrieve (all, error, warning, log, info, debug)",
            enum: ["all", "error", "warning", "log", "info", "debug"]
          },
          search: {
            type: "string",
            description: "Text to search for in logs (handles text with square brackets)"
          },
          limit: {
            type: "number",
            description: "Maximum number of logs to return"
          },
          clear: {
            type: "boolean",
            description: "Whether to clear logs after retrieval (default: false)"
          }
        },
        required: [],
      },
    },
  • Registers the tool in the main handleToolCall switch by dispatching execution to the ConsoleLogsTool instance.
    case "playwright_console_logs":
      return await consoleLogsTool.execute(args, context);
  • Instantiates the ConsoleLogsTool class instance used for handling the tool calls.
    if (!consoleLogsTool) consoleLogsTool = new ConsoleLogsTool(server);
  • Helper method called by page console event listener to store incoming console messages for later retrieval.
    /**
     * Register a console message
     * @param type The type of console message
     * @param text The text content of the message
     */
    registerConsoleMessage(type: string, text: string): void {
      this.consoleLogs.push(`[${type}] ${text}`);
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'filtering options' but doesn't explain key behaviors: whether logs are persisted across tool calls, if retrieval affects browser state, what format logs are returned in, or potential rate limits. For a tool that interacts with browser state, this leaves significant gaps in understanding its operational impact.

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 a single, efficient sentence that gets straight to the point without unnecessary words. It's appropriately sized for a tool with four well-documented parameters. However, it could be slightly more front-loaded by immediately mentioning the core action rather than starting with 'Retrieve console logs'.

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

Completeness2/5

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

Given no annotations and no output schema, the description is incomplete for a tool that retrieves browser data. It doesn't explain what format the logs are returned in (structured objects? plain text?), whether there's pagination for large log sets, or how this tool interacts with the browser session lifecycle. For a Playwright tool dealing with potentially complex console output, more context is needed.

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 schema already fully documents all four parameters. The description adds no additional parameter semantics beyond mentioning 'filtering options' generically. This meets the baseline expectation when the schema does the heavy lifting, but doesn't provide extra value like explaining parameter interactions or common usage patterns.

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 ('Retrieve') and resource ('console logs from the browser'), making the purpose immediately understandable. It distinguishes itself from sibling tools like playwright_screenshot or playwright_click by focusing on log retrieval rather than page interaction or capture. However, it doesn't explicitly differentiate from potential log-related siblings (none exist in the list), so it falls just short of a perfect score.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an active browser session), typical use cases (debugging, monitoring), or relationships with other tools like playwright_get_visible_html for page content. The agent must infer usage from the tool name and parameters alone.

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

Related 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/pvinis/mcp-playwright-stealth'

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