cdpfleet Docs Sign up free

Examples & benchmarks / #91 · 2026-11-23 · Benchmark · Easy · for ai agents, llm data

Read a page from an AI assistant in one call: MCP Functions vs driving a browser

An MCP client reads the same two pages two ways through cdpfleet.com/mcp — one `scrape` call per page, or `launch_browser`, `navigate`, `evaluate`, `snapshot` and `close_browser` — and compares the thread-seconds each was billed, read back from the account's history. Then two agents share one API key, each driving its own browser by `browser_name`. In five languages, four of them on the official MCP SDK.

Chromium

Run on production on 2026-11-23: ✓ Node.js ✓ Python ✓ Java ✓ C# ✓ Go

A benchmark: the results below are what this setup measured on the dates shown, on our own test runs. Sites, networks and browsers change, so rerun the code before you rely on the numbers.

The problem

An assistant that only needs to read a page — its text, a price, a date — has two ways to do it on cdpfleet's hosted MCP server. It can call scrape, one tool call that loads the page in a real browser and returns Markdown plus the values it asked for. Or it can drive a browser: launch_browser, navigate, evaluate or snapshot, and close_browser. Both are billed in thread-seconds. Which one costs less depends on how the assistant works, and this case measures it, including the time a model spends thinking between calls. It also checks what happens when two agents share one API key.

What we used, and why

WhatWhy
https://cdpfleet.com/mcpThe hosted MCP server, over Streamable HTTP. A script sends its API key as Authorization: Bearer <key>; assistants sign in with OAuth.
scrapeOne call per page: formats: ["markdown"] and extract with CSS selectors (title, price and stock on the book page; title and "last edited" line on the article). No browser to launch or close.
launch_browser, navigate, evaluate, snapshot, close_browserThe same two reads with a browser: headless Chromium through your own proxy (PROXY_URL, record: false), the same selectors run by evaluate, and an accessibility snapshot of each page as its text.
A 3-second pause between browser callsA stand-in for the model reading a result and deciding the next call. The browser is billed while it waits; a scrape call is billed only while it runs.
browser_nameTwo agents, each with its own MCP session on the same key: one launches research, the other checkout, at the same time. Every browser tool then takes the name.
account and GET /v1/me/sessionsaccount shows the key's live sessions. The history lists each scrape call as a function:scrape record and each browser as a chromium session; billed thread-seconds = (ended_at − started_at) × weight.

How it works

  1. Functions: in one MCP session, call scrape for the book page and then the Wikipedia article, with Markdown and the picked values.
  2. Browser: in a new MCP session, launch headless Chromium, then for each page navigate, evaluate the same selectors and take a snapshot; close the browser. Calls back to back.
  3. The same browser run again with 3 s before every call after the launch.
  4. Look up the two function:scrape records and the two browser sessions in the account's history and add up their billed thread-seconds.
  5. Two agents at once on the same key: each launches a browser under its own browser_name and opens a different page. Then one of them calls navigate without a name, account counts the live sessions, and each closes its own browser.

The code

The same program in five languages (also on GitHub, with the raw output). Set these environment variables first:

// npm install @modelcontextprotocol/[email protected]
// env: CDPFLEET_API_KEY, PROXY_URL
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';

const MCP = new URL('https://cdpfleet.com/mcp');
const API = 'https://cdpfleet.com';
const KEY = process.env.CDPFLEET_API_KEY;
const PROXY = process.env.PROXY_URL;
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const since = new Date(Date.now() - 60000).toISOString();

// The same two reads both ways: the page as text, plus a few values picked by CSS selector.
const TARGETS = [
  { name: 'book', url: 'https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html', pick: { title: 'h1', price: '.price_color', stock: '.availability' } },
  { name: 'wikipedia', url: 'https://en.wikipedia.org/wiki/Web_scraping', pick: { title: 'h1', updated: '#footer-info-lastmod' } },
];
// evaluate calls an arrow function given as text.
const pickIn = (pick) => `() => { const q = (s) => document.querySelector(s)?.textContent.trim() ?? null; return { ${Object.entries(pick).map(([k, s]) => `${k}: q(${JSON.stringify(s)})`).join(', ')} }; }`;

// A script authenticates with its API key as a bearer token (assistants use OAuth instead).
async function connect(name) {
  const transport = new StreamableHTTPClientTransport(MCP, { requestInit: { headers: { authorization: `Bearer ${KEY}` } } });
  const client = new Client({ name, version: '1.0.0' });
  await client.connect(transport);
  return { client, transport };
}

// One tool call, timed; the text of its result.
async function call(client, log, name, args = {}) {
  const t = Date.now();
  const r = await client.callTool({ name, arguments: args });
  const text = r.content.filter((c) => c.type === 'text').map((c) => c.text).join('\n');
  log.push({ tool: name, ms: Date.now() - t, error: Boolean(r.isError) });
  return { text, error: Boolean(r.isError) };
}

// A shared proxy drops the odd connection: one retry of a failed page load.
async function retried(client, log, name, args) {
  const r = await call(client, log, name, args);
  return r.error ? call(client, log, name, args) : r;
}

// The account's history: a Function call is a "function:scrape" record, a browser its own session.
// Billed thread-seconds = (ended_at - started_at) × weight.
async function history(match) {
  for (let i = 0; i < 30; i++) {
    const r = await fetch(`${API}/v1/me/sessions?from=${encodeURIComponent(since)}&limit=200`, { headers: { 'x-api-key': KEY } });
    const found = ((await r.json()).sessions || []).filter(match);
    if (found.length && found.every((s) => s.ended_at)) return found.map((s) => ({ engine: s.engine, weight: s.weight, thread_seconds: Math.round((Date.parse(s.ended_at) - Date.parse(s.started_at)) * s.weight / 100) / 10 }));
    await sleep(2000);
  }
  return [];
}
const total = (records) => Math.round(records.reduce((a, r) => a + r.thread_seconds, 0) * 10) / 10;

// ---- 1. Functions: one scrape call per page, no browser to drive.
async function functions() {
  const log = [];
  const { client, transport } = await connect('cdpfleet-case-91');
  const start = new Date();
  const reads = [];
  for (const t of TARGETS) {
    const r = await retried(client, log, 'scrape', { url: t.url, formats: ['markdown'], extract: t.pick });
    // "200 <url>\n\nextract: {…}\n\n--- markdown ---\n…"
    const extract = /extract: (\{[\s\S]*?\n\})/.exec(r.text)?.[1];
    reads.push({ page: t.name, status: r.text.split(' ')[0], picked: extract ? JSON.parse(extract) : null, text_chars: r.text.split('--- markdown ---\n')[1]?.length ?? 0 });
  }
  const end = new Date();
  await transport.terminateSession();
  await client.close();
  const billed = await history((s) => s.engine === 'function:scrape' && Date.parse(s.started_at) >= start - 1000 && Date.parse(s.started_at) <= end);
  return { reads, wall_ms: end - start, records: billed.length, thread_seconds: total(billed), calls: log };
}

// ---- 2. Driving a browser: launch, then navigate + evaluate + snapshot per page, then close.
// pauseMs stands in for the model thinking between tool calls; the browser is billed meanwhile.
async function browser(pauseMs) {
  const log = [];
  const { client, transport } = await connect('cdpfleet-case-91');
  const start = Date.now();
  const launched = await call(client, log, 'launch_browser', { browser: 'chromium', headless: true, proxy: PROXY, record: false });
  const sessionId = /session ([0-9a-f-]{36})/.exec(launched.text)?.[1] ?? null;
  const reads = [];
  for (const t of TARGETS) {
    await sleep(pauseMs);
    const nav = await retried(client, log, 'navigate', { url: t.url });
    await sleep(pauseMs);
    const picked = JSON.parse((await call(client, log, 'evaluate', { expression: pickIn(t.pick) })).text);
    await sleep(pauseMs);
    const snap = await call(client, log, 'snapshot');
    reads.push({ page: t.name, status: nav.text.split(' ')[0], picked, text_chars: snap.text.length });
  }
  await sleep(pauseMs);
  const closed = (await call(client, log, 'close_browser')).text.startsWith(`Session ${sessionId} ended`);
  const wall = Date.now() - start;
  await transport.terminateSession();
  await client.close();
  const billed = await history((s) => s.session_id === sessionId);
  return { pause_ms: pauseMs, session_id: sessionId, launched: launched.text.split('. ')[0], closed, reads, wall_ms: wall, engine: billed[0]?.engine ?? null, weight: billed[0]?.weight ?? null, thread_seconds: total(billed), calls: log };
}

// ---- 3. Two agents on one key, each in its own MCP session, each with its own named browser.
async function agent(name, url) {
  const log = [];
  const { client, transport } = await connect(`cdpfleet-case-91-${name}`);
  const launched = await call(client, log, 'launch_browser', { browser: 'chromium', headless: true, proxy: PROXY, record: false, browser_name: name });
  const sessionId = /session ([0-9a-f-]{36})/.exec(launched.text)?.[1] ?? null;
  await retried(client, log, 'navigate', { url, browser_name: name });
  const seen = JSON.parse((await call(client, log, 'evaluate', { expression: '({ url: location.href, title: document.title })', browser_name: name })).text);
  return { name, client, transport, log, mcp_session: transport.sessionId, session_id: sessionId, as_named: launched.text.includes(`as "${name}"`), seen };
}

async function named() {
  const [a, b] = await Promise.all([agent('research', TARGETS[0].url), agent('checkout', TARGETS[1].url)]);
  // Without browser_name, a tool drives "default" — which neither agent launched.
  const unnamed = await call(b.client, b.log, 'navigate', { url: TARGETS[0].url });
  const during = JSON.parse((await call(a.client, a.log, 'account')).text).live_sessions;
  const closed = {};
  for (const x of [a, b]) closed[x.name] = (await call(x.client, x.log, 'close_browser', { browser_name: x.name })).text.startsWith(`Session ${x.session_id} ended`);
  // The live count follows the router's view of the key: read it until both are gone (up to 15 s).
  let after;
  const closedAt = Date.now();
  for (let i = 0; i < 15; i++) {
    after = JSON.parse((await call(a.client, a.log, 'account')).text).live_sessions;
    if (after === 0) break;
    await sleep(1000);
  }
  const zeroAfterMs = after === 0 ? Date.now() - closedAt : null;
  for (const x of [a, b]) { await x.transport.terminateSession(); await x.client.close(); }
  const billed = {};
  for (const x of [a, b]) billed[x.name] = total(await history((s) => s.session_id === x.session_id));
  return {
    agents: [a, b].map((x) => ({ browser_name: x.name, as_named: x.as_named, session_id: x.session_id, seen: x.seen, calls: x.log })),
    distinct_mcp_sessions: new Set([a.mcp_session, b.mcp_session]).size,
    distinct_browser_sessions: new Set([a.session_id, b.session_id]).size,
    unnamed: { error: unnamed.error, text: unnamed.text.split('\n')[0] },
    live_sessions_during: during,
    closed,
    live_sessions_after: after,
    live_zero_after_ms: zeroAfterMs,
    thread_seconds: billed,
  };
}

const fns = await functions();
const fast = await browser(0);
const paced = await browser(3000);
const two = await named();
console.log(JSON.stringify({ language: 'node', functions: fns, browser: fast, browser_paced: paced, named: two, measured_at: new Date().toISOString().slice(0, 10) }, null, 2));

What we got

WayTool callsTimeBilledWhat came backMeasured
Functions: scrape per page2 calls: scrape 5.7 s, scrape 7.6 s13.3 s13 thread-s (2 function:scrape records)the book page: A Light in the Attic £51.77, In stock (22 available), Markdown 2,140 chars; the Wikipedia article: Web scraping, Markdown 24,872 chars2026-11-23
Browser, calls back to back8 calls: launch_browser 0.6 s, navigate 2.6 s and 0.7 s, evaluate/snapshot/close 22–368 ms4.6 s4.3 thread-s (chromium, weight 1, launch to close)the book page: A Light in the Attic £51.77, snapshot 2,615 chars; the Wikipedia article: Web scraping, snapshot 25,056 chars2026-11-23
Browser, 3 s between calls8 calls: launch_browser 0.6 s, navigate 3.0 s and 1.7 s, evaluate/snapshot/close 22–234 ms26.8 s26.5 thread-s (chromium, weight 1, launch to close)the book page: A Light in the Attic £51.77, snapshot 2,615 chars; the Wikipedia article: Web scraping, snapshot 25,056 chars2026-11-23
Two agents on one key: browser_name "research"6 calls in its own MCP session4.8 thread-sA Light in the Attic | Books to Scrape - Sandbox (closed its own browser)2026-11-23
Two agents on one key: browser_name "checkout"5 calls in its own MCP session4.9 thread-sWeb scraping - Wikipedia (closed its own browser)2026-11-23
Two agents on one key: a call without browser_namenavigaterefused: No browser named "default". Open: checkout, research (pass browser_name).; live sessions 2 while both ran, 0 after both closed2026-11-23

From the Node.js run on 2026-11-23. IP addresses are replaced with placeholders (203.0.113.x); equal addresses stay equal. The other languages produced the same findings.

Raw output (Node.js)
{
  "language": "node",
  "functions": {
    "reads": [
      {
        "page": "book",
        "status": "200",
        "picked": {
          "title": "A Light in the Attic",
          "price": "£51.77",
          "stock": "In stock (22 available)"
        },
        "text_chars": 2140
      },
      {
        "page": "wikipedia",
        "status": "200",
        "picked": {
          "title": "Web scraping",
          "updated": "This page was last edited on 16 November 2026, at 04:13 (UTC)."
        },
        "text_chars": 24872
      }
    ],
    "wall_ms": 13290,
    "records": 2,
    "thread_seconds": 13,
    "calls": [
      {
        "tool": "scrape",
        "ms": 5654,
        "error": false
      },
      {
        "tool": "scrape",
        "ms": 7636,
        "error": false
      }
    ]
  },
  "browser": {
    "pause_ms": 0,
    "session_id": "1c875bb8-0947-405d-88d9-67b6158dfcb5",
    "launched": "Launched chromium 148.0.7778.96 (linux_headless, 1 thread(s)), session 1c875bb8-0947-405d-88d9-67b6158dfcb5",
    "closed": true,
    "reads": [
      {
        "page": "book",
        "status": "200",
        "picked": {
          "title": "A Light in the Attic",
          "price": "£51.77",
          "stock": "In stock (22 available)"
        },
        "text_chars": 2615
      },
      {
        "page": "wikipedia",
        "status": "200",
        "picked": {
          "title": "Web scraping",
          "updated": "This page was last edited on 16 November 2026, at 04:13 (UTC)."
        },
        "text_chars": 25056
      }
    ],
    "wall_ms": 4610,
    "engine": "chromium",
    "weight": 1,
    "thread_seconds": 4.3,
    "calls": [
      {
        "tool": "launch_browser",
        "ms": 622,
        "error": false
      },
      {
        "tool": "navigate",
        "ms": 2599,
        "error": false
      },
      {
        "tool": "evaluate",
        "ms": 64,
        "error": false
      },
      {
        "tool": "snapshot",
        "ms": 151,
        "error": false
      },
      {
        "tool": "navigate",
        "ms": 711,
        "error": false
      },
      {
        "tool": "evaluate",
        "ms": 64,
        "error": false
      },
      {
        "tool": "snapshot",
        "ms": 368,
        "error": false
      },
      {
        "tool": "close_browser",
        "ms": 22,
        "error": false
      }
    ]
  },
  "browser_paced": {
    "pause_ms": 3000,
    "session_id": "bc220d64-0c8e-4353-afbb-1e4200c73784",
    "launched": "Launched chromium 148.0.7778.96 (linux_headless, 1 thread(s)), session bc220d64-0c8e-4353-afbb-1e4200c73784",
    "closed": true,
    "reads": [
      {
        "page": "book",
        "status": "200",
        "picked": {
          "title": "A Light in the Attic",
          "price": "£51.77",
          "stock": "In stock (22 available)"
        },
        "text_chars": 2615
      },
      {
        "page": "wikipedia",
        "status": "200",
        "picked": {
          "title": "Web scraping",
          "updated": "This page was last edited on 16 November 2026, at 04:13 (UTC)."
        },
        "text_chars": 25056
      }
    ],
    "wall_ms": 26832,
    "engine": "chromium",
    "weight": 1,
    "thread_seconds": 26.5,
    "calls": [
      {
        "tool": "launch_browser",
        "ms": 594,
        "error": false
      },
      {
        "tool": "navigate",
        "ms": 2968,
        "error": false
      },
      {
        "tool": "evaluate",
        "ms": 67,
        "error": false
      },
      {
        "tool": "snapshot",
        "ms": 128,
        "error": false
      },
      {
        "tool": "navigate",
        "ms": 1747,
        "error": false
      },
      {
        "tool": "evaluate",
        "ms": 72,
        "error": false
      },
      {
        "tool": "snapshot",
        "ms": 234,
        "error": false
      },
      {
        "tool": "close_browser",
        "ms": 22,
        "error": false
      }
    ]
  },
  "named": {
    "agents": [
      {
        "browser_name": "research",
        "as_named": true,
        "session_id": "5a516f09-b0a8-4d89-b1ee-4907ef613225",
        "seen": {
          "url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html",
          "title": "A Light in the Attic | Books to Scrape - Sandbox"
        },
        "calls": [
          {
            "tool": "launch_browser",
            "ms": 769,
            "error": false
          },
          {
            "tool": "navigate",
            "ms": 4178,
            "error": false
          },
          {
            "tool": "evaluate",
            "ms": 58,
            "error": false
          },
          {
            "tool": "account",
            "ms": 109,
            "error": false
          },
          {
            "tool": "close_browser",
            "ms": 37,
            "error": false
          },
          {
            "tool": "account",
            "ms": 103,
            "error": false
          }
        ]
      },
      {
        "browser_name": "checkout",
        "as_named": true,
        "session_id": "e229eae4-d13a-45ef-9e7d-4a3ac0900917",
        "seen": {
          "url": "https://en.wikipedia.org/wiki/Web_scraping",
          "title": "Web scraping - Wikipedia"
        },
        "calls": [
          {
            "tool": "launch_browser",
            "ms": 432,
            "error": false
          },
          {
            "tool": "navigate",
            "ms": 1861,
            "error": false
          },
          {
            "tool": "evaluate",
            "ms": 29,
            "error": false
          },
          {
            "tool": "navigate",
            "ms": 36,
            "error": true
          },
          {
            "tool": "close_browser",
            "ms": 22,
            "error": false
          }
        ]
      }
    ],
    "distinct_mcp_sessions": 2,
    "distinct_browser_sessions": 2,
    "unnamed": {
      "error": true,
      "text": "No browser named \"default\". Open: checkout, research (pass browser_name)."
    },
    "live_sessions_during": 2,
    "closed": {
      "research": true,
      "checkout": true
    },
    "live_sessions_after": 0,
    "live_zero_after_ms": 103,
    "thread_seconds": {
      "research": 4.8,
      "checkout": 4.9
    }
  },
  "measured_at": "2026-11-23"
}

Takeaways