Create a browser agent
Set up an agent that drives a real browser. There are two ways in, and which one you want depends on where the agent lives.
Use MCP when the agent is an assistant someone talks to, such as Claude, Cursor, or VS Code. The client keeps its own loop, and Browserless supplies the browser tools.
Use the Agent Run API when your own code needs a task done. You send the task in plain English, Browserless runs both the browser and the model, and you poll for the result.
Set up MCP in your AI client
Get Your API Token
Sign up for a free account, then copy your API token from the account dashboard.
Clients that support OAuth can skip this and sign in to Browserless when they first connect.
Add the Server to Your Client
The hosted server is
https://mcp.browserless.io/mcp. There's nothing to install.- Claude Code
- Claude Desktop
- Cursor
- Claude.ai
claude mcp add --transport http browserless https://mcp.browserless.io/mcp \
--header "Authorization: Bearer YOUR_API_TOKEN_HERE"Add to
claude_desktop_config.json:{
"mcpServers": {
"browserless": {
"type": "http",
"url": "https://mcp.browserless.io/mcp",
"headers": {
"Authorization": "Bearer YOUR_API_TOKEN_HERE"
}
}
}
}Add to your Cursor MCP settings:
{
"mcpServers": {
"browserless": {
"type": "http",
"url": "https://mcp.browserless.io/mcp",
"headers": {
"Authorization": "Bearer YOUR_API_TOKEN_HERE"
}
}
}
}The custom connector form takes a URL only, so the token goes in the query string:
https://mcp.browserless.io/mcp?token=YOUR_API_TOKEN_HEREAdd it under Customize > Connectors > Add custom connector.
Other clients, including VS Code and Windsurf, are in MCP server setup.
Give the Agent a Task
Restart the client so it picks up the server, then ask for something that needs a browser:
Open news.ycombinator.com and give me the titles of the top three stories.The client picks the tool itself. For multi-step work such as signing in or paginating, it reaches for
browserless_agent, which holds one browser session across turns so cookies and history survive between tool calls.
Set up the Agent Run API
The Agent Run API is currently in beta. Parameters and response shapes may change in future releases.
The Agent Run API is only available for Cloud plans. Contact us for more information.
Get Your API Token
Copy your API token from the account dashboard. You don't need a model key: Browserless runs the browser and the model.
Start a Run
POST /agent/runtakes the task in plain English and returns a run ID immediately. The agent works in the background.- cURL
- JavaScript
- Python
curl --request POST \
--url 'https://production-sfo.browserless.io/agent/run?token=YOUR_API_TOKEN_HERE' \
--header 'Content-Type: application/json' \
--data '{
"query": "Go to https://example.com and tell me the exact text of the top-level heading."
}'const TOKEN = "YOUR_API_TOKEN_HERE";
const response = await fetch(
`https://production-sfo.browserless.io/agent/run?token=${TOKEN}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query:
"Go to https://example.com and tell me the exact text of the top-level heading.",
}),
}
);
const { id } = await response.json();
console.log(id);import requests
TOKEN = "YOUR_API_TOKEN_HERE"
response = requests.post(
f"https://production-sfo.browserless.io/agent/run?token={TOKEN}",
json={
"query": "Go to https://example.com and tell me the exact text of the top-level heading."
},
)
print(response.json()["id"])Response
{
"id": "run_abc123def456",
"status": "pending"
}The
querymust be at least 10 characters.Poll for the Result
Request the run until
statusreaches a terminal value:succeeded,failed,timed_out, orstopped. Each poll also returns the steps taken so far, so you can show progress instead of a spinner.- cURL
- JavaScript
- Python
curl --request GET \
--url 'https://production-sfo.browserless.io/agent/run/run_abc123def456?token=YOUR_API_TOKEN_HERE'const TOKEN = "YOUR_API_TOKEN_HERE";
const runId = "run_abc123def456";
const TERMINAL = ["succeeded", "failed", "timed_out", "stopped"];
while (true) {
const response = await fetch(
`https://production-sfo.browserless.io/agent/run/${runId}?token=${TOKEN}`
);
const result = await response.json();
console.log(result.status, result.steps?.at(-1) ?? "");
if (TERMINAL.includes(result.status)) {
console.log(result.data);
break;
}
// A request right after submitting returns pending, so poll on an interval.
await new Promise((resolve) => setTimeout(resolve, 3000));
}import time
import requests
TOKEN = "YOUR_API_TOKEN_HERE"
run_id = "run_abc123def456"
url = f"https://production-sfo.browserless.io/agent/run/{run_id}?token={TOKEN}"
TERMINAL = {"succeeded", "failed", "timed_out", "stopped"}
while True:
result = requests.get(url).json()
print(result["status"], (result.get("steps") or [""])[-1])
if result["status"] in TERMINAL:
print(result["data"])
break
# A request right after submitting returns pending, so poll on an interval.
time.sleep(3)Response
{
"id": "run_abc123def456",
"status": "succeeded",
"data": {
"answer": "The exact text of the top-level heading is: Example Domain"
},
"error": null,
"steps": [
"Opening the example homepage",
"Reading the main heading",
"Closing the completed browser session"
]
}datais{ "answer": "..." }unless you pass aresponseSchema, which shapes it to match. Results are kept for 7 days.
FAQ & Troubleshooting
My MCP client doesn't list the Browserless tools.
Restart the client after editing its config. If they still don't appear, check that the config uses "type": "http" and that the token is on the Authorization header as Bearer YOUR_API_TOKEN_HERE. The query-string form is only for Claude.ai's connector field, which accepts a URL and nothing else.
A run came back timed_out.
The task was too broad, or the site was too slow. Narrow it, give the agent a starting URL, and say what a finished answer looks like. "Find the pricing" invites wandering. "Open this URL and return the monthly price of each plan" doesn't.
Can I constrain where the agent goes, or what it returns?
Yes. POST /agent/run accepts a starting URL, a navigation allowlist, an authentication profile, and a responseSchema for the shape of the answer. See the Agent Run API reference.
Do I need my own model API key?
Not for either path here. The Agent Run API manages the model for you, and with MCP the client you're already using brings its own.