Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_custom_user_agent

Set a custom User Agent string for browser automation to simulate different devices or browsers, bypass restrictions, and test website compatibility.

Instructions

Set a custom User Agent for the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userAgentYesCustom User Agent for the Playwright browser instance

Implementation Reference

  • The CustomUserAgentTool class containing the execute method that validates the custom user agent set on the browser page.
    export class CustomUserAgentTool extends BrowserToolBase {
      /**
       * Execute the custom user agent tool
       */
      async execute(args: CustomUserAgentArgs, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async (page) => {
          if (!args.userAgent) {
            return createErrorResponse("Missing required parameter: userAgent must be provided");
          }
    
          try {
            const currentUserAgent = await page.evaluate(() => navigator.userAgent);
            
            if (currentUserAgent !== args.userAgent) {
              const messages = [
                "Page was already initialized with a different User Agent.",
                `Requested: ${args.userAgent}`,
                `Current: ${currentUserAgent}`
              ];
              return createErrorResponse(messages.join('\n'));
            }
    
            return createSuccessResponse("User Agent validation successful");
          } catch (error) {
            return createErrorResponse(`Failed to validate User Agent: ${(error as Error).message}`);
          }
        });
      }
    } 
  • Tool definition including name, description, and input schema for validation.
    {
      name: "playwright_custom_user_agent",
      description: "Set a custom User Agent for the browser",
      inputSchema: {
        type: "object",
        properties: {
          userAgent: { type: "string", description: "Custom User Agent for the Playwright browser instance" }
        },
        required: ["userAgent"],
      },
    },
  • Switch case in main tool handler that dispatches to the CustomUserAgentTool execute method.
    case "playwright_custom_user_agent":
      return await customUserAgentTool.execute(args, context);
  • Instantiation of the CustomUserAgentTool instance.
    if (!customUserAgentTool) customUserAgentTool = new CustomUserAgentTool(server);
  • Passes the userAgent argument to browser launch settings specifically for this tool.
    userAgent: name === "playwright_custom_user_agent" ? args.userAgent : undefined,
    headless: args.headless,
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 but only states the basic action without details on effects (e.g., whether it persists across sessions, impacts other tools, or requires specific permissions). It doesn't mention potential side effects like breaking website functionality or rate limits, leaving significant gaps.

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?

The description is a single, direct sentence with zero wasted words, front-loading the core action and resource. It efficiently conveys the essential information without unnecessary elaboration, making it easy to parse quickly.

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 the lack of annotations and output schema, the description is incomplete for a tool that modifies browser behavior. It doesn't explain what happens after setting the User Agent (e.g., success confirmation, error handling, or impact on subsequent actions), leaving the agent with insufficient context for reliable use.

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?

The input schema has 100% description coverage, with the 'userAgent' parameter clearly documented in the schema. The description adds no additional meaning beyond what the schema provides, such as examples or format constraints, so it meets the baseline for high schema coverage without enhancing parameter 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 ('Set') and the resource ('custom User Agent for the browser'), making the purpose immediately understandable. It doesn't explicitly differentiate from siblings like 'playwright_get' or 'playwright_navigate', but the specificity of 'User Agent' distinguishes it from general browser interaction tools.

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, such as whether it's for testing specific browser versions, bypassing detection, or other scenarios. It lacks context about prerequisites (e.g., requiring an active browser session) or exclusions, leaving usage unclear.

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/devskido/customed-playwright'

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