Skip to main content
Glama

monitor-network

Monitor browser network requests for a specified duration using URL pattern filtering to analyze traffic during development.

Instructions

Monitors network requests in the browser for a specified duration

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlPatternNoURL pattern to filter (regex string)
durationNoDuration in milliseconds to monitor (default: 5000)

Implementation Reference

  • Executes network monitoring by listening to Playwright page 'request' events for a specified duration, optionally filtering by URL pattern, and returns captured requests.
    async ({ urlPattern, duration = 5000 }) => {
      try {
        // Check browser status
        const browserStatus = getContextForOperation();
        if (!browserStatus.isStarted) {
          return browserStatus.error;
        }
    
        const requests: Array<{
          url: string;
          method: string;
          resourceType: string;
          timestamp: number;
        }> = [];
        const pattern = urlPattern ? new RegExp(urlPattern) : null;
    
        // Start network request monitoring
        const requestHandler = (request: Request) => {
          const url = request.url();
          if (!pattern || pattern.test(url)) {
            requests.push({
              url,
              method: request.method(),
              resourceType: request.resourceType(),
              timestamp: Date.now()
            });
          }
        };
    
        browserStatus.page.on('request', requestHandler);
    
        // Wait for specified duration
        await new Promise(resolve => setTimeout(resolve, duration));
    
        // Stop monitoring
        browserStatus.page.off('request', requestHandler);
    
        return {
          content: [
            {
              type: 'text',
              text: requests.length > 0
                ? `Captured ${requests.length} network requests:\n${JSON.stringify(requests, null, 2)}`
                : 'No network requests matching the criteria were captured during the monitoring period.'
            }
          ]
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        Logger.error(`Failed to monitor network: ${errorMessage}`);
        return {
          content: [
            {
              type: 'text',
              text: `Failed to monitor network: ${errorMessage}`
            }
          ],
          isError: true
        };
      }
    }
  • Input schema using Zod: optional urlPattern (regex string for filtering), optional duration (milliseconds, defaults to 5000).
    {
      urlPattern: z.string().optional().describe('URL pattern to filter (regex string)'),
      duration: z.number().optional().describe('Duration in milliseconds to monitor (default: 5000)')
    },
  • Registers the 'monitor-network' tool with the MCP server using server.tool(name, description, inputSchema, handler).
    server.tool(
      'monitor-network',
      'Monitors network requests in the browser for a specified duration',
      {
        urlPattern: z.string().optional().describe('URL pattern to filter (regex string)'),
        duration: z.number().optional().describe('Duration in milliseconds to monitor (default: 5000)')
      },
      async ({ urlPattern, duration = 5000 }) => {
        try {
          // Check browser status
          const browserStatus = getContextForOperation();
          if (!browserStatus.isStarted) {
            return browserStatus.error;
          }
    
          const requests: Array<{
            url: string;
            method: string;
            resourceType: string;
            timestamp: number;
          }> = [];
          const pattern = urlPattern ? new RegExp(urlPattern) : null;
    
          // Start network request monitoring
          const requestHandler = (request: Request) => {
            const url = request.url();
            if (!pattern || pattern.test(url)) {
              requests.push({
                url,
                method: request.method(),
                resourceType: request.resourceType(),
                timestamp: Date.now()
              });
            }
          };
    
          browserStatus.page.on('request', requestHandler);
    
          // Wait for specified duration
          await new Promise(resolve => setTimeout(resolve, duration));
    
          // Stop monitoring
          browserStatus.page.off('request', requestHandler);
    
          return {
            content: [
              {
                type: 'text',
                text: requests.length > 0
                  ? `Captured ${requests.length} network requests:\n${JSON.stringify(requests, null, 2)}`
                  : 'No network requests matching the criteria were captured during the monitoring period.'
              }
            ]
          };
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          Logger.error(`Failed to monitor network: ${errorMessage}`);
          return {
            content: [
              {
                type: 'text',
                text: `Failed to monitor network: ${errorMessage}`
              }
            ],
            isError: true
          };
        }
      }
    );
    
    // Element HTML content retrieval tool
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 states the tool monitors network requests but doesn't describe what happens during monitoring (e.g., does it block execution, collect data, or trigger events?), the output format (e.g., returns a list of requests), or any limitations (e.g., rate limits, browser compatibility). This leaves significant gaps for a tool that likely involves asynchronous behavior and data collection.

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 that front-loads the core purpose ('Monitors network requests in the browser') and adds a key constraint ('for a specified duration'). There is zero waste, with every word contributing to understanding the tool's function without redundancy.

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 complexity of network monitoring (likely involving asynchronous operations and data collection), no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., request details, errors), behavioral traits (e.g., whether it waits for duration or streams results), or integration with other tools (e.g., requires 'start-browser' first). For a tool with potential side effects and no structured 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%, with both parameters ('urlPattern' and 'duration') well-documented in the schema. The description adds no additional parameter semantics beyond implying duration is required for monitoring. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't compensate with extra context like regex examples or duration units clarification.

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 ('Monitors') and resource ('network requests in the browser') with a specific constraint ('for a specified duration'). It distinguishes from siblings like 'get-console-logs' or 'capture-screenshot' by focusing on network monitoring rather than console output or visual capture. However, it doesn't explicitly differentiate from potential overlapping tools like 'get-hmr-events' which might also involve network activity.

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., requires an active browser session), exclusions (e.g., not for monitoring after browser closure), or compare it to siblings like 'get-console-logs' for different types of browser data. The context is implied but not explicit.

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/ESnark/blowback'

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