Skip to main content
Glama

Capture Live Intercepted Traffic

capture_traffic

Capture live HTTP(S) traffic from intercepted browsers, apps, or containers. Creates a temporary session to collect requests and responses for analysis and debugging.

Instructions

Capture live HTTP(S) traffic being intercepted by HTTP Toolkit. Creates a temporary session, subscribes to traffic events via WebSocket, collects requests and responses for the specified duration, then returns all captured exchanges. Use this to see what HTTP requests are being made by intercepted browsers, apps, or containers.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
durationNoDuration in seconds to capture traffic (default: 5, max: 30)

Implementation Reference

  • Registration and MCP handler for the 'capture_traffic' tool.
    server.registerTool(
      'capture_traffic',
      {
        title: 'Capture Live Intercepted Traffic',
        description:
          'Capture live HTTP(S) traffic being intercepted by HTTP Toolkit. Creates a temporary session, subscribes to traffic events via WebSocket, collects requests and responses for the specified duration, then returns all captured exchanges. Use this to see what HTTP requests are being made by intercepted browsers, apps, or containers.',
        inputSchema: z.object({
          duration: z.number().optional().describe('Duration in seconds to capture traffic (default: 5, max: 30)'),
        }),
      },
      async ({ duration }) => {
        const durationMs = Math.min((duration || 5), 30) * 1000;
        const exchanges = await trafficCapture.captureLive(durationMs);
        return jsonResult({
          capturedExchanges: exchanges.length,
          exchanges,
        });
      }
    );
  • The implementation of the traffic capturing logic using WebSockets and the Mockttp API.
      async captureLive(durationMs: number = 5000): Promise<CapturedExchange[]> {
        const sessionId = await this.createSession();
        const wsUrl = this.adminUrl.replace(/^http/, 'ws') +
          `/session/${sessionId}/subscription`;
    
        const exchanges = new Map<string, CapturedExchange>();
    
        return new Promise<CapturedExchange[]>((resolve, reject) => {
          const ws = new WebSocket(wsUrl, 'graphql-ws', {
            headers: { 'Origin': 'http://localhost' },
          });
    
          const cleanup = () => {
            try { ws.close(); } catch {}
            this.stopSession(sessionId).catch(() => {});
          };
    
          const timeout = setTimeout(() => {
            cleanup();
            resolve(Array.from(exchanges.values()));
          }, durationMs);
    
          ws.on('open', () => {
            // Init connection
            ws.send(JSON.stringify({ type: 'connection_init' }));
          });
    
          ws.on('message', (data: WebSocket.Data) => {
            const msg = JSON.parse(data.toString());
    
            if (msg.type === 'connection_ack') {
              // Subscribe to request initiated
              ws.send(JSON.stringify({
                id: '1',
                type: 'start',
                payload: {
                  query: `subscription {
                    requestInitiated {
                      id
                      protocol
                      httpVersion
                      method
                      url
                      path
                      headers
                      remoteIpAddress
                      remotePort
                      tags
                    }
                  }`,
                },
              }));
    
              // Subscribe to response completed
              ws.send(JSON.stringify({
                id: '2',
                type: 'start',
                payload: {
                  query: `subscription {
                    responseCompleted {
                      id
                      statusCode
                      statusMessage
                      headers
                      tags
                    }
                  }`,
                },
              }));
            }
    
            if (msg.type === 'data' && msg.id === '1' && msg.payload?.data?.requestInitiated) {
              const req = msg.payload.data.requestInitiated;
              exchanges.set(req.id, {
                request: {
                  id: req.id,
                  method: req.method,
                  url: req.url,
                  protocol: req.protocol,
                  headers: req.headers,
                  remoteIpAddress: req.remoteIpAddress,
                  tags: req.tags,
                },
              });
            }
    
            if (msg.type === 'data' && msg.id === '2' && msg.payload?.data?.responseCompleted) {
              const resp = msg.payload.data.responseCompleted;
              const exchange = exchanges.get(resp.id);
              if (exchange) {
                exchange.response = {
                  id: resp.id,
                  statusCode: resp.statusCode,
                  statusMessage: resp.statusMessage,
                  headers: resp.headers,
                  tags: resp.tags,
                };
              }
            }
          });
    
          ws.on('error', (err) => {
            clearTimeout(timeout);
            cleanup();
            reject(new Error(`WebSocket error: ${err.message}`));
          });
    
          ws.on('close', () => {
            clearTimeout(timeout);
            resolve(Array.from(exchanges.values()));
          });
        });
      }
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: it creates a temporary session, uses WebSocket for real-time events, collects data for a specified duration, and returns all captured exchanges. However, it lacks details on permissions needed, error handling, or rate limits, which are important for a tool involving network interception.

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 front-loaded with the core purpose in the first sentence, followed by operational details in a logical flow. Each sentence adds essential information without redundancy, making it efficient and easy to parse for an AI agent.

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

Completeness3/5

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

Given the tool's complexity (involving live interception and WebSocket communication), no annotations, and no output schema, the description is adequate but incomplete. It explains what the tool does and the input, but lacks details on output format (e.g., structure of captured exchanges), error cases, or dependencies on other tools (e.g., needing an active interceptor).

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% coverage with a clear description for the 'duration' parameter. The description adds value by explaining the parameter's role in the overall process ('collects requests and responses for the specified duration'), linking it to the tool's purpose. Since there's only one parameter, the baseline is high, and the description enhances understanding beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('capture live HTTP(S) traffic'), the resource ('traffic being intercepted by HTTP Toolkit'), and the mechanism ('creates a temporary session, subscribes to traffic events via WebSocket, collects requests and responses'). It distinguishes from siblings like 'send_http_request' (which sends rather than captures) or 'list_interceptors' (which lists rather than captures traffic).

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

Usage Guidelines4/5

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

The description provides clear context on when to use it: 'to see what HTTP requests are being made by intercepted browsers, apps, or containers.' This implies it should be used after interception tools (e.g., 'intercept_chrome') are active. However, it does not explicitly state when not to use it or name specific alternatives among siblings, such as for non-live traffic scenarios.

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/fdciabdul/httptoolkit-mcp'

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