Skip to main content
Glama

set_viewport_size

Adjust browser viewport dimensions in pixels for responsive testing and layout verification. Specify width and height to simulate different screen sizes.

Instructions

Set viewport dimensions in pixels.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
widthYesWidth in pixels
heightYesHeight in pixels

Implementation Reference

  • The MCP tool handler function that validates input parameters (width, height), retrieves the Firefox instance, calls the underlying setViewportSize method, and returns a formatted success or error response.
    export async function handleSetViewportSize(args: unknown): Promise<McpToolResponse> {
      try {
        const { width, height } = args as { width: number; height: number };
    
        if (typeof width !== 'number' || width <= 0) {
          throw new Error('width parameter is required and must be a positive number');
        }
    
        if (typeof height !== 'number' || height <= 0) {
          throw new Error('height parameter is required and must be a positive number');
        }
    
        const { getFirefox } = await import('../index.js');
        const firefox = await getFirefox();
    
        await firefox.setViewportSize(width, height);
    
        return successResponse(`✅ ${width}x${height}`);
      } catch (error) {
        return errorResponse(error as Error);
      }
    }
  • The tool definition object specifying name, description, and input schema (object with required numeric width/height properties).
    export const setViewportSizeTool = {
      name: 'set_viewport_size',
      description: 'Set viewport dimensions in pixels.',
      inputSchema: {
        type: 'object',
        properties: {
          width: {
            type: 'number',
            description: 'Width in pixels',
          },
          height: {
            type: 'number',
            description: 'Height in pixels',
          },
        },
        required: ['width', 'height'],
      },
    };
  • src/index.ts:146-146 (registration)
    Registers the tool handler in the central toolHandlers Map used by the MCP server to dispatch CallTool requests.
    ['set_viewport_size', tools.handleSetViewportSize],
  • src/index.ts:190-190 (registration)
    Adds the tool definition to the allTools array served in response to ListTools requests.
    tools.setViewportSizeTool,
  • Underlying browser automation helper: uses Selenium WebDriver to set the browser window/viewport size via setRect.
    async setViewportSize(width: number, height: number): Promise<void> {
      await this.driver.manage().window().setRect({ width, height });
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action without behavioral details. It doesn't disclose if this is a destructive operation (likely yes, as it changes viewport), what happens to existing content, error conditions, or side effects, leaving significant gaps in understanding.

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, efficient sentence with zero wasted words. It's front-loaded with the core action and resource, making it easy to parse quickly, which is ideal for conciseness.

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, no output schema, and a mutation tool (implied by 'Set'), the description is incomplete. It lacks details on permissions, effects, return values, or error handling, which are crucial for safe and effective use in a browser automation context.

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 fully documents the width and height parameters. The description adds no additional meaning beyond implying pixel units, which is already in the schema. This meets the baseline for high coverage but doesn't enhance 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 resource ('viewport dimensions in pixels'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'screenshot_page' or 'take_snapshot' that also involve viewport manipulation, so it misses the highest 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 page), exclusions, or related tools like 'screenshot_page' that might depend on viewport settings, leaving the agent with minimal context for selection.

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/mozilla/firefox-devtools-mcp'

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