Skip to main content
Glama
BrowserGenie

BrowserGenie MCP Server

by BrowserGenie

resize_viewport

Resize the browser viewport to test responsive designs at various screen sizes. Optionally emulate mobile, touch, and custom user agent.

Instructions

Resize the browser viewport to specific dimensions. Use this to test responsive layouts at different screen sizes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
widthYesViewport width in pixels
heightYesViewport height in pixels
deviceScaleFactorNoDevice pixel ratio (default: 1)
mobileNoWhether to emulate mobile (default: false)
userAgentNoCustom user agent string
touchNoEnable touch emulation (default: false)
tabIdNoTarget tab ID (defaults to currently active tab)
apiKeyNoAPI key for authentication if enabled

Implementation Reference

  • The 'resize_viewport' tool is registered via server.tool() inside registerEmulationTools(). This is the MCP tool registration point.
    export function registerEmulationTools(server: McpServer, bridge: WebSocketBridge) {
      server.tool(
        'resize_viewport',
        'Resize the browser viewport to specific dimensions. Use this to test responsive layouts at different screen sizes.',
        {
          width: z.number().describe('Viewport width in pixels'),
          height: z.number().describe('Viewport height in pixels'),
          deviceScaleFactor: z.number().optional().describe('Device pixel ratio (default: 1)'),
          mobile: z.boolean().optional().describe('Whether to emulate mobile (default: false)'),
          userAgent: z.string().optional().describe('Custom user agent string'),
          touch: z.boolean().optional().describe('Enable touch emulation (default: false)'),
          tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'),
          apiKey: z.string().optional().describe('API key for authentication if enabled'),
        },
        async ({ width, height, deviceScaleFactor, mobile, userAgent, touch, tabId, apiKey }) => {
          const result = await bridge.sendCommand({
            command: 'resize_viewport',
            params: { width, height, deviceScaleFactor, mobile, userAgent, touch },
            tabId,
            apiKey,
          });
          if (!result.success) {
            return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
          }
          return { content: [{ type: 'text', text: `Viewport resized to ${width}x${height}` }] };
        }
      );
  • The async handler that executes the 'resize_viewport' tool logic. It sends a 'resize_viewport' command via WebSocketBridge and returns the result.
    async ({ width, height, deviceScaleFactor, mobile, userAgent, touch, tabId, apiKey }) => {
      const result = await bridge.sendCommand({
        command: 'resize_viewport',
        params: { width, height, deviceScaleFactor, mobile, userAgent, touch },
        tabId,
        apiKey,
      });
      if (!result.success) {
        return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
      }
      return { content: [{ type: 'text', text: `Viewport resized to ${width}x${height}` }] };
    }
  • Zod schema definitions for the 'resize_viewport' tool's input parameters: width, height, deviceScaleFactor, mobile, userAgent, touch, tabId, apiKey.
    {
      width: z.number().describe('Viewport width in pixels'),
      height: z.number().describe('Viewport height in pixels'),
      deviceScaleFactor: z.number().optional().describe('Device pixel ratio (default: 1)'),
      mobile: z.boolean().optional().describe('Whether to emulate mobile (default: false)'),
      userAgent: z.string().optional().describe('Custom user agent string'),
      touch: z.boolean().optional().describe('Enable touch emulation (default: false)'),
      tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'),
      apiKey: z.string().optional().describe('API key for authentication if enabled'),
    },
  • The sendCommand() helper that forwards the 'resize_viewport' command over WebSocket to the Chrome extension backend.
    async sendCommand(cmd: BridgeCommand): Promise<BridgeResponse> {
      if (!this.isConnected()) {
        return {
          success: false,
          error: {
            code: 'NOT_CONNECTED',
            message: 'Chrome extension is not connected. Ensure the extension is installed, enabled, and the browser is running.',
          },
        };
      }
    
      const id = crypto.randomUUID();
      const timeout = cmd.timeout ?? DEFAULT_TIMEOUT;
    
      return new Promise<BridgeResponse>((resolve, reject) => {
        const timer = setTimeout(() => {
          this.pending.delete(id);
          resolve({
            success: false,
            error: {
              code: 'TIMEOUT',
              message: `Command '${cmd.command}' timed out after ${timeout}ms`,
            },
          });
        }, timeout);
    
        this.pending.set(id, { resolve, reject, timer });
    
        const message = {
          id,
          type: 'request',
          command: cmd.command,
          params: cmd.params,
          tabId: cmd.tabId,
          apiKey: cmd.apiKey,
          timestamp: Date.now(),
        };
    
        this.client!.send(JSON.stringify(message));
      });
    }
Behavior2/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 does not disclose side effects such as whether scroll position resets, resize events are triggered, or how it interacts with existing emulation settings. The behavior regarding tab target (tabId) is also not described.

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 two sentences long, direct, and contains no unnecessary words. Every sentence contributes to understanding the tool's purpose.

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 8 parameters and no output schema, the description is too brief. It omits critical details about optional parameters like deviceScaleFactor, mobile, and touch, which are essential for understanding the tool's full capability. The presence of a sibling 'emulate_device' suggests a more comprehensive alternative, but this is not addressed.

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, so the description does not need to elaborate on parameters. However, it adds no extra context (e.g., defaults or typical usage of optional parameters), meeting the baseline expectation.

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 tool resizes the browser viewport for testing responsive layouts. However, it does not differentiate from sibling tools like 'reset_viewport' or 'emulate_device', which also modify viewport settings.

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

Usage Guidelines3/5

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

The description provides a use case ('test responsive layouts at different screen sizes') but lacks explicit guidance on when not to use it or alternatives. It does not mention that 'emulate_device' might be more appropriate for full device emulation.

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/BrowserGenie/mcp'

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