API Reference

Browserful provides two APIs: MCP Tools for AI agents via Claude Desktop and similar clients, and a REST API for direct integration.

Overview

Browserful uses a session-based architecture. Each session represents a browser tab that persists across requests. You can create multiple sessions, perform actions in them, and read their state.

Core Concepts

Session A browser tab. Has a URL, title, and interactive elements. Persists until deleted.
Workspace A container for sessions. Each API key belongs to one workspace.
Action A browser operation: navigate, click, type, scroll, or screenshot.
Page State Current URL, title, scroll position, and interactive elements on the page.

Authentication

All API requests require an API key. Create one by running:

context-cloud init --name "my-workspace"

For the REST API, include your key in the X-API-Key header or as a Bearer token:

# Header
curl -H "X-API-Key: cb_your_api_key" https://api.browserful.com/api/v1/sessions

# Bearer token
curl -H "Authorization: Bearer cb_your_api_key" https://api.browserful.com/api/v1/sessions

Quick Start

Here's a complete example using the MCP tools:

# 1. Create a session and navigate to a page
create_session(url="https://news.ycombinator.com")
# Returns: session_id="abc123" + page state

# 2. Click on an article (element 5)
perform_action(session_id="abc123", action="click", element_id=5)
# Returns: new page state after click

# 3. Read the current state
read_session(session_id="abc123")
# Returns: URL, title, all interactive elements

# 4. Clean up
delete_session(session_id="abc123")

MCP Tools

These tools are exposed via the Model Context Protocol for use with Claude Desktop, Cursor, and other MCP clients.

list_sessions

list_sessions MCP Tool

List all active browser sessions in your workspace.

Parameters

None

Response
Active sessions: 2

- [abc123] Hacker News
  URL: https://news.ycombinator.com/

- [def456] GitHub
  URL: https://github.com/

create_session

create_session MCP Tool

Create a new browser session. Optionally navigate to an initial URL.

Parameters
url string Initial URL to navigate to. If omitted, opens a blank page.
Response
Session created: abc123

URL: https://news.ycombinator.com/
Title: Hacker News
Scroll: 0/1214 (viewport: 581px)

Interactive Elements:
  [0]<a href="...">Hacker News</a>
  [1]<a href="...">new</a>
  [2]<a href="...">past</a>
  ...

read_session

read_session MCP Tool

Get the current state of a browser session, including all interactive elements.

Parameters
session_id string required The session ID to read.
Response
URL: https://news.ycombinator.com/
Title: Hacker News
Scroll: 0/1214 (viewport: 581px)

Interactive Elements:
  [0]<a href="...">Hacker News</a>
  [1]<a href="...">new</a>
  [2]<input type="text" placeholder="Search...">
  [3]<button>Login</button>
  ...

perform_action

perform_action MCP Tool

Perform an action in a browser session. Returns the new page state after the action.

Parameters
session_id string required The session ID to perform the action in.
action string required The action to perform: navigate, click, type, scroll, or screenshot.
url string URL to navigate to. Required for navigate action.
element_id integer Element ID to interact with. Required for click and type actions.
text string Text to type. Required for type action.
direction string Scroll direction: up, down, left, right. Default: down.
amount integer Scroll amount in pixels. Default: 500.
Examples
# Navigate to a URL
perform_action(session_id="abc123", action="navigate", url="https://google.com")

# Click an element
perform_action(session_id="abc123", action="click", element_id=5)

# Type text into an input
perform_action(session_id="abc123", action="type", element_id=2, text="search query")

# Scroll down
perform_action(session_id="abc123", action="scroll", direction="down", amount=500)

# Take a screenshot
perform_action(session_id="abc123", action="screenshot")

delete_session

delete_session MCP Tool

Close and delete a browser session.

Parameters
session_id string required The session ID to delete.
Response
Session abc123 deleted.

REST API

The REST API provides the same functionality as the MCP tools, but for direct HTTP integration. All endpoints are prefixed with /api/v1.

Sessions

GET /api/v1/sessions

List all active sessions in your workspace.

Response
{
  "sessions": [
    {
      "id": "abc123",
      "url": "https://news.ycombinator.com/",
      "title": "Hacker News",
      "status": "active",
      "created_at": "2024-01-15T10:30:00Z",
      "last_action_at": "2024-01-15T10:35:00Z"
    }
  ],
  "count": 1
}
POST /api/v1/sessions

Create a new browser session.

Request Body
{
  "url": "https://news.ycombinator.com"  // optional
}
Response
{
  "session": {
    "id": "abc123",
    "url": "https://news.ycombinator.com/",
    "title": "Hacker News",
    "status": "active"
  },
  "state": {
    "url": "https://news.ycombinator.com/",
    "title": "Hacker News",
    "elements": [...]
  }
}
GET /api/v1/sessions/{session_id}

Get the current state of a session.

Response
{
  "session_id": "abc123",
  "state": {
    "url": "https://news.ycombinator.com/",
    "title": "Hacker News",
    "scroll_x": 0,
    "scroll_y": 0,
    "scroll_height": 1214,
    "viewport_height": 581,
    "elements": [
      {
        "id": 0,
        "tag": "a",
        "type": "link",
        "text": "Hacker News",
        "attributes": { "href": "..." }
      },
      ...
    ]
  }
}

Actions

POST /api/v1/sessions/{session_id}/action

Perform an action in a session.

Request Body
{
  "action": "click",
  "params": {
    "element_id": 5
  }
}
Action Types
navigate Params: { "url": "https://..." }
click Params: { "element_id": 5 }
type Params: { "element_id": 2, "text": "hello", "clear_first": true }
scroll Params: { "direction": "down", "amount": 500 }
screenshot Params: none. Returns base64 image in state.
DELETE /api/v1/sessions/{session_id}

Delete a session.

Response
{
  "deleted": "abc123"
}

Stats

GET /api/v1/stats

Get usage statistics for your workspace.

Response
{
  "total_sessions": 42,
  "active_sessions": 3,
  "total_actions": 1337
}

Page State

Every action returns the current page state. This includes all interactive elements the AI can interact with.

Page State Structure

url Current page URL
title Page title
scroll_x / scroll_y Current scroll position in pixels
scroll_height Total scrollable height
viewport_height Visible viewport height
elements Array of interactive elements

Element Structure

id Unique element ID for this page load
tag HTML tag: a, button, input, etc.
type Semantic type: link, button, input, select, etc.
text Visible text content (max 200 chars)
attributes Key attributes like href, id
input_type For inputs: text, password, email, etc.
placeholder Input placeholder text
aria_label Accessibility label

Errors

Errors are returned with appropriate HTTP status codes and a JSON body.

{
  "error": "Session not found: abc123"
}
400 Bad Request - Invalid parameters
401 Unauthorized - Invalid or missing API key
404 Not Found - Session doesn't exist
500 Internal Error - Browser or server error