@mastra/mcp-docs-server 0.0.0-studio-deploy-20260404182525 → 0.0.0-studio-cli-20260504022012
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/docs/agents/adding-voice.md +18 -17
- package/.docs/docs/agents/background-tasks.md +242 -0
- package/.docs/docs/agents/channels.md +2 -1
- package/.docs/docs/agents/overview.md +4 -0
- package/.docs/docs/agents/processors.md +177 -5
- package/.docs/docs/agents/structured-output.md +66 -1
- package/.docs/docs/agents/supervisor-agents.md +65 -0
- package/.docs/docs/agents/using-tools.md +73 -0
- package/.docs/docs/browser/agent-browser.md +78 -0
- package/.docs/docs/browser/browser-viewer.md +144 -0
- package/.docs/docs/browser/overview.md +168 -0
- package/.docs/docs/browser/stagehand.md +129 -0
- package/.docs/docs/deployment/cloud-providers.md +5 -1
- package/.docs/docs/deployment/mastra-server.md +4 -4
- package/.docs/docs/deployment/monorepo.md +3 -3
- package/.docs/docs/deployment/overview.md +11 -8
- package/.docs/docs/editor/overview.md +290 -0
- package/.docs/docs/editor/prompts.md +134 -0
- package/.docs/docs/editor/tools.md +152 -0
- package/.docs/docs/evals/custom-scorers.md +63 -3
- package/.docs/docs/evals/datasets/overview.md +1 -1
- package/.docs/docs/index.md +2 -2
- package/.docs/docs/mastra-platform/configuration.md +36 -0
- package/.docs/docs/mastra-platform/overview.md +78 -0
- package/.docs/docs/mcp/overview.md +17 -0
- package/.docs/docs/memory/memory-processors.md +3 -3
- package/.docs/docs/memory/message-history.md +8 -2
- package/.docs/docs/memory/observational-memory.md +65 -8
- package/.docs/docs/memory/storage.md +1 -2
- package/.docs/docs/memory/working-memory.md +2 -2
- package/.docs/docs/observability/logging.md +1 -1
- package/.docs/docs/observability/metrics/overview.md +2 -2
- package/.docs/docs/observability/overview.md +1 -1
- package/.docs/docs/observability/tracing/bridges/datadog.md +217 -0
- package/.docs/docs/observability/tracing/bridges/otel.md +2 -2
- package/.docs/docs/observability/tracing/exporters/arthur.md +163 -0
- package/.docs/docs/observability/tracing/exporters/cloud.md +135 -63
- package/.docs/docs/observability/tracing/exporters/datadog.md +3 -1
- package/.docs/docs/observability/tracing/exporters/default.md +5 -5
- package/.docs/docs/observability/tracing/exporters/laminar.md +22 -14
- package/.docs/docs/observability/tracing/exporters/langfuse.md +50 -33
- package/.docs/docs/observability/tracing/overview.md +87 -20
- package/.docs/docs/server/custom-adapters.md +5 -5
- package/.docs/docs/server/custom-api-routes.md +3 -3
- package/.docs/docs/server/mastra-client.md +2 -2
- package/.docs/docs/server/mastra-server.md +1 -1
- package/.docs/docs/server/middleware.md +46 -42
- package/.docs/docs/server/request-context.md +13 -2
- package/.docs/docs/server/server-adapters.md +91 -8
- package/.docs/docs/streaming/background-task-streaming.md +80 -0
- package/.docs/docs/streaming/overview.md +3 -0
- package/.docs/docs/studio/deployment.md +24 -6
- package/.docs/docs/studio/observability.md +1 -1
- package/.docs/docs/studio/overview.md +4 -4
- package/.docs/docs/voice/overview.md +74 -5
- package/.docs/docs/voice/speech-to-speech.md +45 -1
- package/.docs/docs/voice/speech-to-text.md +7 -7
- package/.docs/docs/voice/text-to-speech.md +10 -10
- package/.docs/docs/workflows/agents-and-tools.md +1 -1
- package/.docs/docs/workflows/overview.md +105 -4
- package/.docs/docs/workflows/scheduled-workflows.md +181 -0
- package/.docs/docs/workspace/filesystem.md +64 -6
- package/.docs/docs/workspace/lsp.md +76 -4
- package/.docs/docs/workspace/overview.md +62 -15
- package/.docs/docs/workspace/sandbox.md +3 -1
- package/.docs/docs/workspace/search.md +41 -2
- package/.docs/docs/workspace/skills.md +19 -19
- package/.docs/guides/agent-frameworks/ai-sdk.md +4 -4
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +56 -9
- package/.docs/guides/build-your-ui/assistant-ui.md +1 -1
- package/.docs/guides/deployment/mastra-platform.md +191 -0
- package/.docs/guides/deployment/netlify.md +16 -1
- package/.docs/guides/getting-started/nestjs.md +238 -0
- package/.docs/guides/getting-started/next-js.md +0 -4
- package/.docs/guides/guide/code-review-bot.md +2 -2
- package/.docs/guides/guide/dev-assistant.md +4 -4
- package/.docs/{docs/mcp → guides/guide}/publishing-mcp-server.md +21 -1
- package/.docs/guides/guide/slack-assistant.md +191 -0
- package/.docs/guides/migrations/mastra-cloud.md +368 -0
- package/.docs/guides/migrations/upgrade-to-v1/tracing.md +1 -1
- package/.docs/models/embeddings.md +3 -3
- package/.docs/models/gateways/azure-openai.md +74 -35
- package/.docs/models/gateways/mastra.md +64 -0
- package/.docs/models/gateways/netlify.md +7 -3
- package/.docs/models/gateways/openrouter.md +28 -12
- package/.docs/models/gateways/vercel.md +22 -2
- package/.docs/models/gateways.md +1 -0
- package/.docs/models/index.md +43 -8
- package/.docs/models/providers/302ai.md +37 -4
- package/.docs/models/providers/abliteration-ai.md +71 -0
- package/.docs/models/providers/alibaba-cn.md +8 -2
- package/.docs/models/providers/alibaba-coding-plan-cn.md +3 -2
- package/.docs/models/providers/alibaba-coding-plan.md +3 -2
- package/.docs/models/providers/alibaba.md +8 -1
- package/.docs/models/providers/anthropic.md +18 -5
- package/.docs/models/providers/baseten.md +3 -1
- package/.docs/models/providers/berget.md +10 -12
- package/.docs/models/providers/chutes.md +4 -2
- package/.docs/models/providers/cloudflare-workers-ai.md +14 -48
- package/.docs/models/providers/cortecs.md +22 -2
- package/.docs/models/providers/deepinfra.md +8 -2
- package/.docs/models/providers/deepseek.md +6 -4
- package/.docs/models/providers/digitalocean.md +133 -0
- package/.docs/models/providers/fireworks-ai.md +6 -1
- package/.docs/models/providers/firmware.md +12 -10
- package/.docs/models/providers/friendli.md +6 -7
- package/.docs/models/providers/google.md +9 -3
- package/.docs/models/providers/helicone.md +1 -2
- package/.docs/models/providers/hpc-ai.md +73 -0
- package/.docs/models/providers/huggingface.md +6 -2
- package/.docs/models/providers/inception.md +9 -11
- package/.docs/models/providers/kilo.md +359 -339
- package/.docs/models/providers/kimi-for-coding.md +2 -1
- package/.docs/models/providers/llmgateway.md +67 -77
- package/.docs/models/providers/mistral.md +3 -2
- package/.docs/models/providers/mixlayer.md +75 -0
- package/.docs/models/providers/moonshotai-cn.md +3 -2
- package/.docs/models/providers/moonshotai.md +3 -2
- package/.docs/models/providers/nano-gpt.md +8 -2
- package/.docs/models/providers/neuralwatt.md +84 -0
- package/.docs/models/providers/novita-ai.md +19 -4
- package/.docs/models/providers/nvidia.md +8 -1
- package/.docs/models/providers/ollama-cloud.md +7 -2
- package/.docs/models/providers/openai.md +7 -2
- package/.docs/models/providers/opencode-go.md +21 -13
- package/.docs/models/providers/opencode.md +11 -4
- package/.docs/models/providers/ovhcloud.md +6 -8
- package/.docs/models/providers/poe.md +10 -15
- package/.docs/models/providers/regolo-ai.md +83 -0
- package/.docs/models/providers/siliconflow-cn.md +5 -2
- package/.docs/models/providers/siliconflow.md +6 -3
- package/.docs/models/providers/stepfun.md +8 -7
- package/.docs/models/providers/synthetic.md +5 -2
- package/.docs/models/providers/tencent-token-plan.md +71 -0
- package/.docs/models/providers/tencent-tokenhub.md +71 -0
- package/.docs/models/providers/togetherai.md +8 -7
- package/.docs/models/providers/vivgrid.md +7 -3
- package/.docs/models/providers/vultr.md +7 -6
- package/.docs/models/providers/wafer.ai.md +73 -0
- package/.docs/models/providers/wandb.md +3 -2
- package/.docs/models/providers/xai.md +6 -1
- package/.docs/models/providers/xiaomi-token-plan-ams.md +75 -0
- package/.docs/models/providers/xiaomi-token-plan-cn.md +75 -0
- package/.docs/models/providers/xiaomi-token-plan-sgp.md +75 -0
- package/.docs/models/providers/xiaomi.md +4 -2
- package/.docs/models/providers/zai-coding-plan.md +11 -19
- package/.docs/models/providers/zai.md +2 -1
- package/.docs/models/providers/zenmux.md +17 -6
- package/.docs/models/providers/zhipuai-coding-plan.md +11 -21
- package/.docs/models/providers/zhipuai.md +2 -1
- package/.docs/models/providers.md +11 -0
- package/.docs/reference/agents/agent.md +1 -1
- package/.docs/reference/agents/channels.md +3 -3
- package/.docs/reference/agents/generate.md +88 -6
- package/.docs/reference/agents/generateLegacy.md +1 -1
- package/.docs/reference/ai-sdk/chat-route.md +2 -0
- package/.docs/reference/ai-sdk/handle-chat-stream.md +19 -0
- package/.docs/reference/ai-sdk/handle-network-stream.md +2 -0
- package/.docs/reference/ai-sdk/network-route.md +2 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-messages.md +95 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +15 -0
- package/.docs/reference/browser/agent-browser.md +375 -0
- package/.docs/reference/browser/browser-viewer.md +228 -0
- package/.docs/reference/browser/mastra-browser.md +286 -0
- package/.docs/reference/browser/stagehand-browser.md +286 -0
- package/.docs/reference/cli/mastra.md +703 -0
- package/.docs/reference/client-js/agents.md +166 -0
- package/.docs/reference/client-js/conversations.md +1 -1
- package/.docs/reference/client-js/mastra-client.md +23 -0
- package/.docs/reference/client-js/observability.md +2 -2
- package/.docs/reference/client-js/responses.md +1 -1
- package/.docs/reference/client-js/workflows.md +62 -1
- package/.docs/reference/configuration.md +67 -1
- package/.docs/reference/core/addGateway.md +5 -5
- package/.docs/reference/core/getEditor.md +35 -0
- package/.docs/reference/core/getGateway.md +5 -5
- package/.docs/reference/core/getGatewayById.md +5 -5
- package/.docs/reference/core/getMCPServer.md +2 -2
- package/.docs/reference/core/getMCPServerById.md +2 -2
- package/.docs/reference/core/getScorer.md +3 -3
- package/.docs/reference/core/getScorerById.md +3 -3
- package/.docs/reference/core/listGateways.md +5 -5
- package/.docs/reference/core/listMCPServers.md +2 -2
- package/.docs/reference/core/listScorers.md +3 -3
- package/.docs/reference/core/mastra-class.md +11 -1
- package/.docs/reference/core/mastra-model-gateway.md +5 -5
- package/.docs/reference/datasets/create.md +4 -4
- package/.docs/reference/datasets/startExperiment.md +28 -2
- package/.docs/reference/datasets/update.md +4 -4
- package/.docs/reference/deployer/cloudflare.md +14 -1
- package/.docs/reference/deployer/netlify.md +50 -2
- package/.docs/reference/editor/mastra-editor.md +168 -0
- package/.docs/reference/editor/tool-provider.md +85 -0
- package/.docs/reference/evals/context-precision.md +3 -3
- package/.docs/reference/evals/context-relevance.md +3 -3
- package/.docs/reference/evals/create-scorer.md +5 -3
- package/.docs/reference/evals/filter-run.md +117 -0
- package/.docs/reference/evals/mastra-scorer.md +4 -4
- package/.docs/reference/evals/noise-sensitivity.md +6 -6
- package/.docs/reference/evals/prompt-alignment.md +12 -12
- package/.docs/reference/evals/run-evals.md +6 -6
- package/.docs/reference/evals/scorer-utils.md +3 -3
- package/.docs/reference/evals/trajectory-accuracy.md +3 -3
- package/.docs/reference/harness/harness-class.md +152 -53
- package/.docs/reference/index.md +25 -0
- package/.docs/reference/logging/pino-logger.md +0 -2
- package/.docs/reference/mastra-platform/api.md +108 -0
- package/.docs/reference/memory/clone-utilities.md +4 -2
- package/.docs/reference/memory/cloneThread.md +4 -2
- package/.docs/reference/memory/observational-memory.md +4 -0
- package/.docs/reference/observability/metrics/automatic-metrics.md +3 -3
- package/.docs/reference/observability/tracing/bridges/datadog.md +211 -0
- package/.docs/reference/observability/tracing/bridges/otel.md +3 -3
- package/.docs/reference/observability/tracing/configuration.md +18 -11
- package/.docs/reference/observability/tracing/exporters/arthur.md +122 -0
- package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +102 -21
- package/.docs/reference/observability/tracing/exporters/console-exporter.md +8 -8
- package/.docs/reference/observability/tracing/exporters/datadog.md +3 -1
- package/.docs/reference/observability/tracing/exporters/default-exporter.md +8 -8
- package/.docs/reference/observability/tracing/exporters/langfuse.md +25 -32
- package/.docs/reference/observability/tracing/exporters/otel.md +3 -3
- package/.docs/reference/observability/tracing/instances.md +7 -7
- package/.docs/reference/observability/tracing/interfaces.md +23 -6
- package/.docs/reference/observability/tracing/span-filtering.md +95 -0
- package/.docs/reference/observability/tracing/spans.md +6 -6
- package/.docs/reference/processors/prefill-error-handler.md +70 -0
- package/.docs/reference/processors/processor-interface.md +400 -40
- package/.docs/reference/processors/skill-search-processor.md +20 -1
- package/.docs/reference/processors/stream-error-retry-processor.md +54 -0
- package/.docs/reference/processors/tool-call-filter.md +23 -0
- package/.docs/reference/server/create-route.md +3 -3
- package/.docs/reference/server/express-adapter.md +4 -4
- package/.docs/reference/server/fastify-adapter.md +4 -4
- package/.docs/reference/server/hono-adapter.md +4 -4
- package/.docs/reference/server/koa-adapter.md +4 -4
- package/.docs/reference/server/mastra-server.md +3 -3
- package/.docs/reference/server/nestjs-adapter.md +169 -0
- package/.docs/reference/server/register-api-route.md +4 -4
- package/.docs/reference/server/routes.md +11 -10
- package/.docs/reference/storage/clickhouse.md +300 -0
- package/.docs/reference/storage/cloudflare-d1.md +42 -42
- package/.docs/reference/storage/composite.md +5 -3
- package/.docs/reference/storage/duckdb.md +150 -0
- package/.docs/reference/storage/overview.md +1 -1
- package/.docs/reference/storage/redis.md +266 -0
- package/.docs/reference/streaming/ChunkType.md +143 -3
- package/.docs/reference/streaming/agents/MastraModelOutput.md +2 -2
- package/.docs/reference/streaming/agents/stream.md +10 -2
- package/.docs/reference/streaming/agents/streamUntilIdle.md +94 -0
- package/.docs/reference/streaming/workflows/resumeStream.md +2 -0
- package/.docs/reference/templates/overview.md +88 -14
- package/.docs/reference/tools/create-tool.md +107 -5
- package/.docs/reference/tools/mcp-client.md +45 -0
- package/.docs/reference/tools/mcp-server.md +1 -3
- package/.docs/reference/tools/perplexity.md +155 -0
- package/.docs/reference/tools/tavily.md +307 -0
- package/.docs/reference/vectors/mongodb.md +0 -2
- package/.docs/reference/voice/aws-nova-sonic.md +247 -0
- package/.docs/reference/voice/cloudflare.md +3 -3
- package/.docs/reference/voice/sarvam.md +29 -23
- package/.docs/reference/voice/voice.connect.md +4 -4
- package/.docs/reference/voice/voice.listen.md +3 -3
- package/.docs/reference/workflows/run-methods/resume.md +24 -0
- package/.docs/reference/workflows/run-methods/startAsync.md +1 -1
- package/.docs/reference/workflows/step.md +88 -7
- package/.docs/reference/workflows/workflow-methods/foreach.md +14 -1
- package/.docs/reference/workflows/workflow.md +88 -4
- package/.docs/reference/workspace/azure-blob-filesystem.md +219 -0
- package/.docs/reference/workspace/docker-sandbox.md +196 -0
- package/.docs/reference/workspace/gcs-filesystem.md +1 -0
- package/.docs/reference/workspace/google-drive-filesystem.md +185 -0
- package/.docs/reference/workspace/modal-sandbox.md +168 -0
- package/.docs/reference/workspace/process-manager.md +1 -1
- package/.docs/reference/workspace/s3-filesystem.md +80 -5
- package/.docs/reference/workspace/vercel.md +1 -1
- package/.docs/reference/workspace/workspace-class.md +37 -6
- package/CHANGELOG.md +500 -4
- package/dist/stdio.js.map +1 -1
- package/dist/utils.d.ts +1 -4
- package/dist/utils.d.ts.map +1 -1
- package/package.json +11 -11
- package/.docs/docs/mastra-cloud/deployment.md +0 -77
- package/.docs/docs/mastra-cloud/observability.md +0 -38
- package/.docs/docs/mastra-cloud/overview.md +0 -23
- package/.docs/docs/mastra-cloud/setup.md +0 -42
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# BrowserViewer
|
|
2
|
+
|
|
3
|
+
The `BrowserViewer` class provides browser automation for CLI-based tools. It launches Chrome via Playwright, exposes a Chrome DevTools Protocol (CDP) URL, and automatically injects it into CLI commands run through workspace tools.
|
|
4
|
+
|
|
5
|
+
Use `BrowserViewer` when your agent drives a browser through a CLI tool like `browser-use`, `agent-browser`, or `browse`. For SDK-based browser automation, use [`AgentBrowser`](https://mastra.ai/reference/browser/agent-browser) or [`StagehandBrowser`](https://mastra.ai/reference/browser/stagehand-browser).
|
|
6
|
+
|
|
7
|
+
## Usage example
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { Workspace, LocalSandbox } from '@mastra/core/workspace'
|
|
11
|
+
import { BrowserViewer } from '@mastra/browser-viewer'
|
|
12
|
+
import { Agent } from '@mastra/core/agent'
|
|
13
|
+
|
|
14
|
+
const workspace = new Workspace({
|
|
15
|
+
sandbox: new LocalSandbox({
|
|
16
|
+
workingDirectory: './workspace',
|
|
17
|
+
}),
|
|
18
|
+
browser: new BrowserViewer({
|
|
19
|
+
cli: 'browser-use',
|
|
20
|
+
headless: false,
|
|
21
|
+
}),
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const browserAgent = new Agent({
|
|
25
|
+
id: 'browser-agent',
|
|
26
|
+
model: 'openai/gpt-5.4',
|
|
27
|
+
workspace,
|
|
28
|
+
instructions: 'You are a web automation assistant.',
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Connecting to an existing browser
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
const viewer = new BrowserViewer({
|
|
36
|
+
cli: 'browser-use',
|
|
37
|
+
cdpUrl: 'ws://127.0.0.1:9222/devtools/browser/abc123',
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
When `cdpUrl` is provided, `BrowserViewer` connects to the existing browser instead of launching a new one. Scope defaults to `'shared'`.
|
|
42
|
+
|
|
43
|
+
## Constructor parameters
|
|
44
|
+
|
|
45
|
+
**cli** (`'agent-browser' | 'browser-use' | 'browse-cli'`): Which CLI the agent uses for browser automation. The CLI connects to Chrome via the CDP URL.
|
|
46
|
+
|
|
47
|
+
**headless** (`boolean`): Whether to run Chrome in headless mode. (Default: `true`)
|
|
48
|
+
|
|
49
|
+
**cdpUrl** (`string | (() => string | Promise<string>)`): CDP WebSocket URL for connecting to an existing browser instead of launching one.
|
|
50
|
+
|
|
51
|
+
**cdpPort** (`number`): Port for Chrome remote debugging. Only used when launching Chrome (not when connecting via cdpUrl). (Default: `0 (auto-assign)`)
|
|
52
|
+
|
|
53
|
+
**scope** (`'shared' | 'thread'`): Browser instance scope. 'thread' gives each thread its own browser. 'shared' shares one browser across all threads. Defaults to 'shared' when cdpUrl is provided. (Default: `'thread'`)
|
|
54
|
+
|
|
55
|
+
**viewport** (`{ width: number; height: number }`): Browser viewport dimensions. (Default: `{ width: 1280, height: 720 }`)
|
|
56
|
+
|
|
57
|
+
**executablePath** (`string`): Path to a Chrome executable. Uses Playwright's bundled Chromium by default.
|
|
58
|
+
|
|
59
|
+
**onLaunch** (`(args: { browser: MastraBrowser }) => void | Promise<void>`): Callback invoked after the browser is ready.
|
|
60
|
+
|
|
61
|
+
**onClose** (`(args: { browser: MastraBrowser }) => void | Promise<void>`): Callback invoked before the browser closes.
|
|
62
|
+
|
|
63
|
+
**screencast** (`ScreencastOptions`): Configuration for streaming browser frames to Studio.
|
|
64
|
+
|
|
65
|
+
## Properties
|
|
66
|
+
|
|
67
|
+
**id** (`string`): Unique identifier for this browser instance. Generated as 'browser-viewer-{timestamp}'.
|
|
68
|
+
|
|
69
|
+
**name** (`string`): 'BrowserViewer'
|
|
70
|
+
|
|
71
|
+
**provider** (`string`): 'browser-viewer'
|
|
72
|
+
|
|
73
|
+
**providerType** (`'cli'`): Always 'cli'. Distinguishes BrowserViewer from SDK-based providers like AgentBrowser.
|
|
74
|
+
|
|
75
|
+
**cli** (`'agent-browser' | 'browser-use' | 'browse-cli'`): The CLI provider this instance is configured for.
|
|
76
|
+
|
|
77
|
+
**status** (`BrowserStatus`): Current browser status: 'pending', 'launching', 'ready', 'error', 'closing', or 'closed'.
|
|
78
|
+
|
|
79
|
+
## Methods
|
|
80
|
+
|
|
81
|
+
### Lifecycle
|
|
82
|
+
|
|
83
|
+
#### `launch(threadId?)`
|
|
84
|
+
|
|
85
|
+
Launches Chrome. For `'shared'` scope, launches a single shared browser. For `'thread'` scope, launches a browser for the specified thread.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
await viewer.launch()
|
|
89
|
+
await viewer.launch('thread-123')
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### `ensureReady()`
|
|
93
|
+
|
|
94
|
+
Ensures the browser is launched and ready. For `'thread'` scope, creates a new browser for the current thread if needed.
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
await viewer.ensureReady()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### `isBrowserRunning(threadId?)`
|
|
101
|
+
|
|
102
|
+
Checks if a browser is running. For `'thread'` scope, checks the specified thread.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const running = viewer.isBrowserRunning()
|
|
106
|
+
const threadRunning = viewer.isBrowserRunning('thread-123')
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Returns: `boolean`
|
|
110
|
+
|
|
111
|
+
#### `close()`
|
|
112
|
+
|
|
113
|
+
Closes all browser instances and cleans up resources.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
await viewer.close()
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### CDP access
|
|
120
|
+
|
|
121
|
+
#### `getCdpUrl(threadId?)`
|
|
122
|
+
|
|
123
|
+
Returns the CDP WebSocket URL for the current or specified thread. CLI tools use this URL to connect to the managed browser.
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
const cdpUrl = viewer.getCdpUrl()
|
|
127
|
+
// => 'ws://127.0.0.1:52481/devtools/browser/abc...'
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Returns: `string | null`
|
|
131
|
+
|
|
132
|
+
#### `connectToExternalCdp(cdpUrl, threadId?)`
|
|
133
|
+
|
|
134
|
+
Connects to an external browser via CDP URL for screencast. Use this when the agent provides its own browser endpoint (for example, a cloud browser service). BrowserViewer connects for screencast without managing the browser lifecycle.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
await viewer.connectToExternalCdp('wss://cloud.example.com/session', 'thread-123')
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Screencast
|
|
141
|
+
|
|
142
|
+
#### `startScreencast(options?)`
|
|
143
|
+
|
|
144
|
+
Starts streaming browser frames. Returns a `ScreencastStream` that emits frame events. Handles tab switching automatically by creating fresh CDP sessions when tabs change.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const stream = await viewer.startScreencast({
|
|
148
|
+
format: 'jpeg',
|
|
149
|
+
quality: 80,
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
stream.on('frame', frame => {
|
|
153
|
+
console.log('Frame received:', frame.data.length, 'bytes')
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
stream.on('stop', reason => {
|
|
157
|
+
console.log('Screencast stopped:', reason)
|
|
158
|
+
})
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Returns: `Promise<ScreencastStream>`
|
|
162
|
+
|
|
163
|
+
### Input injection
|
|
164
|
+
|
|
165
|
+
#### `injectMouseEvent(params, threadId?)`
|
|
166
|
+
|
|
167
|
+
Injects a mouse event into the browser via CDP. Used by Studio for live interaction.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
await viewer.injectMouseEvent({
|
|
171
|
+
type: 'mousePressed',
|
|
172
|
+
x: 100,
|
|
173
|
+
y: 200,
|
|
174
|
+
button: 'left',
|
|
175
|
+
clickCount: 1,
|
|
176
|
+
})
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### `injectKeyboardEvent(params, threadId?)`
|
|
180
|
+
|
|
181
|
+
Injects a keyboard event into the browser via CDP. Used by Studio for live interaction.
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
await viewer.injectKeyboardEvent({
|
|
185
|
+
type: 'keyDown',
|
|
186
|
+
key: 'Enter',
|
|
187
|
+
code: 'Enter',
|
|
188
|
+
})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Supported CLIs
|
|
192
|
+
|
|
193
|
+
Each CLI must be installed separately. Each also publishes a [skill](https://mastra.ai/docs/workspace/skills) that teaches the agent its commands and workflows. When a CLI command runs through `workspace_execute_command`, Mastra detects it and injects the CDP URL automatically using the correct flag.
|
|
194
|
+
|
|
195
|
+
Unlike SDK providers, `BrowserViewer` does not provide agent tools. The agent uses CLI commands through `workspace_execute_command` instead.
|
|
196
|
+
|
|
197
|
+
### [agent-browser](https://www.npmjs.com/package/agent-browser)
|
|
198
|
+
|
|
199
|
+
Config value: `'agent-browser'` · CDP flag: `--cdp`
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
npm install -g agent-browser
|
|
203
|
+
npx skills add vercel-labs/agent-browser
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### [browser-use](https://pypi.org/project/browser-use/)
|
|
207
|
+
|
|
208
|
+
Config value: `'browser-use'` · CDP flag: `--cdp-url`
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
pip install browser-use
|
|
212
|
+
npx skills add browser-use/browser-use --skill browser-use
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### [browse-cli](https://www.npmjs.com/package/@browserbasehq/browse-cli) (command: `browse`)
|
|
216
|
+
|
|
217
|
+
Config value: `'browse-cli'` · CDP flag: `--ws`
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
npm install -g @browserbasehq/browse-cli
|
|
221
|
+
npx skills add browserbase/skills
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Related
|
|
225
|
+
|
|
226
|
+
- [BrowserViewer guide](https://mastra.ai/docs/browser/browser-viewer) — setup and usage walkthrough
|
|
227
|
+
- [MastraBrowser](https://mastra.ai/reference/browser/mastra-browser) — base class API reference
|
|
228
|
+
- [Workspace overview](https://mastra.ai/docs/workspace/overview) — workspace configuration
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# MastraBrowser class
|
|
2
|
+
|
|
3
|
+
The `MastraBrowser` class is the abstract base class for browser automation providers. It defines the common interface for launching browsers, managing thread isolation, streaming screencasts, and handling input events.
|
|
4
|
+
|
|
5
|
+
You don't instantiate `MastraBrowser` directly. Instead, use a provider implementation:
|
|
6
|
+
|
|
7
|
+
- [`AgentBrowser`](https://mastra.ai/reference/browser/agent-browser): Deterministic browser automation using refs
|
|
8
|
+
- [`StagehandBrowser`](https://mastra.ai/reference/browser/stagehand-browser): AI-powered browser automation using natural language
|
|
9
|
+
- [`BrowserViewer`](https://mastra.ai/reference/browser/browser-viewer): CLI-based browser automation with CDP URL injection
|
|
10
|
+
|
|
11
|
+
## Usage example
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Agent } from '@mastra/core/agent'
|
|
15
|
+
import { AgentBrowser } from '@mastra/agent-browser'
|
|
16
|
+
|
|
17
|
+
const browser = new AgentBrowser({
|
|
18
|
+
headless: true,
|
|
19
|
+
viewport: { width: 1280, height: 720 },
|
|
20
|
+
scope: 'thread',
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const browserAgent = new Agent({
|
|
24
|
+
id: 'browser-agent',
|
|
25
|
+
name: 'Browser Agent',
|
|
26
|
+
instructions: 'You can browse the web to find information.',
|
|
27
|
+
model: 'openai/gpt-5.4',
|
|
28
|
+
browser,
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Constructor parameters
|
|
33
|
+
|
|
34
|
+
**headless** (`boolean`): Whether to run the browser in headless mode (no visible UI). (Default: `true`)
|
|
35
|
+
|
|
36
|
+
**viewport** (`{ width: number; height: number }`): Browser viewport dimensions. Controls the size of the browser window. (Default: `{ width: 1280, height: 720 }`)
|
|
37
|
+
|
|
38
|
+
**timeout** (`number`): Default timeout in milliseconds. Each provider defines its own semantics and default. See the provider reference for details.
|
|
39
|
+
|
|
40
|
+
**cdpUrl** (`string | (() => string | Promise<string>)`): CDP WebSocket URL, HTTP endpoint, or sync/async provider function. When provided, connects to an existing browser instead of launching a new one. HTTP endpoints are resolved to WebSocket internally. Can't be used with scope: 'thread' (automatically uses shared scope).
|
|
41
|
+
|
|
42
|
+
**scope** (`'shared' | 'thread'`): Browser instance scope across threads. 'shared' means all threads share a single browser instance. 'thread' means each thread gets its own browser instance (full isolation). (Default: `'thread' (or 'shared' when cdpUrl is provided)`)
|
|
43
|
+
|
|
44
|
+
**onLaunch** (`(args: { browser: MastraBrowser }) => void | Promise<void>`): Callback invoked after the browser reaches 'ready' status.
|
|
45
|
+
|
|
46
|
+
**onClose** (`(args: { browser: MastraBrowser }) => void | Promise<void>`): Callback invoked before the browser is closed.
|
|
47
|
+
|
|
48
|
+
**screencast** (`ScreencastOptions`): Configuration for streaming browser frames.
|
|
49
|
+
|
|
50
|
+
**screencast.format** (`'jpeg' | 'png'`): Image format for screencast frames.
|
|
51
|
+
|
|
52
|
+
**screencast.quality** (`number`): Image quality (1-100). Only applies to JPEG format.
|
|
53
|
+
|
|
54
|
+
**screencast.maxWidth** (`number`): Maximum width for screencast frames.
|
|
55
|
+
|
|
56
|
+
**screencast.maxHeight** (`number`): Maximum height for screencast frames.
|
|
57
|
+
|
|
58
|
+
**screencast.everyNthFrame** (`number`): Capture every Nth frame to reduce bandwidth.
|
|
59
|
+
|
|
60
|
+
## Properties
|
|
61
|
+
|
|
62
|
+
The following properties (`id`, `name`, `provider`) are abstract and must be defined by concrete provider implementations:
|
|
63
|
+
|
|
64
|
+
**id** (`string`): Unique identifier for this browser instance. Abstract - defined by provider.
|
|
65
|
+
|
|
66
|
+
**name** (`string`): Human-readable name of the browser provider (e.g., 'AgentBrowser', 'StagehandBrowser'). Abstract - defined by provider.
|
|
67
|
+
|
|
68
|
+
**provider** (`string`): Provider identifier (e.g., 'vercel-labs/agent-browser', 'browserbase/stagehand'). Abstract - defined by provider.
|
|
69
|
+
|
|
70
|
+
**headless** (`boolean`): Whether the browser is running in headless mode.
|
|
71
|
+
|
|
72
|
+
**status** (`BrowserStatus`): Current browser status: 'pending', 'launching', 'ready', 'error', 'closing', or 'closed'.
|
|
73
|
+
|
|
74
|
+
## Methods
|
|
75
|
+
|
|
76
|
+
### Lifecycle
|
|
77
|
+
|
|
78
|
+
#### `ensureReady()`
|
|
79
|
+
|
|
80
|
+
Ensures the browser is launched and ready for use. Automatically called before tool execution. Implemented in the base class.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
await browser.ensureReady()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### `close()`
|
|
87
|
+
|
|
88
|
+
Closes the browser and cleans up all resources. Implemented in the base class with race-condition-safe handling.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
await browser.close()
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### `isBrowserRunning()`
|
|
95
|
+
|
|
96
|
+
Checks if the browser is currently running.
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
const isRunning = browser.isBrowserRunning()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Returns:** `boolean`
|
|
103
|
+
|
|
104
|
+
### Thread management
|
|
105
|
+
|
|
106
|
+
#### `setCurrentThread(threadId)`
|
|
107
|
+
|
|
108
|
+
Sets the current thread ID for browser operations. Used internally by the agent runtime.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
browser.setCurrentThread('thread-123')
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### `getCurrentThread()`
|
|
115
|
+
|
|
116
|
+
Gets the current thread ID.
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
const threadId = browser.getCurrentThread()
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Returns:** `string`
|
|
123
|
+
|
|
124
|
+
#### `hasThreadSession(threadId)`
|
|
125
|
+
|
|
126
|
+
Checks if a thread has an active browser session.
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const hasSession = browser.hasThreadSession('thread-123')
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Returns:** `boolean`
|
|
133
|
+
|
|
134
|
+
#### `closeThreadSession(threadId)`
|
|
135
|
+
|
|
136
|
+
Closes a specific thread's browser session. For 'thread' scope, this closes that thread's browser instance. For 'shared' scope, this clears the thread's state.
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
await browser.closeThreadSession('thread-123')
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Tools
|
|
143
|
+
|
|
144
|
+
#### `getTools()`
|
|
145
|
+
|
|
146
|
+
Returns the browser tools for use with agents. Each provider returns different tools based on its paradigm.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
const tools = browser.getTools()
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Returns:** `Record<string, Tool>`
|
|
153
|
+
|
|
154
|
+
### Screencast
|
|
155
|
+
|
|
156
|
+
#### `startScreencast(options?, threadId?)`
|
|
157
|
+
|
|
158
|
+
Starts streaming browser frames. Returns a `ScreencastStream` that emits frame events.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
const stream = await browser.startScreencast({ format: 'jpeg', quality: 80 }, 'thread-123')
|
|
162
|
+
|
|
163
|
+
stream.on('frame', frame => {
|
|
164
|
+
console.log('Frame received:', frame.data.length, 'bytes')
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
stream.on('stop', reason => {
|
|
168
|
+
console.log('Screencast stopped:', reason)
|
|
169
|
+
})
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Returns:** `Promise<ScreencastStream>`
|
|
173
|
+
|
|
174
|
+
### Input injection
|
|
175
|
+
|
|
176
|
+
#### `injectMouseEvent(params, threadId?)`
|
|
177
|
+
|
|
178
|
+
Injects a mouse event into the browser. Used by Studio for live interaction.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
await browser.injectMouseEvent({
|
|
182
|
+
type: 'mousePressed',
|
|
183
|
+
x: 100,
|
|
184
|
+
y: 200,
|
|
185
|
+
button: 'left',
|
|
186
|
+
clickCount: 1,
|
|
187
|
+
})
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### `injectKeyboardEvent(params, threadId?)`
|
|
191
|
+
|
|
192
|
+
Injects a keyboard event into the browser. Used by Studio for live interaction.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
await browser.injectKeyboardEvent({
|
|
196
|
+
type: 'keyDown',
|
|
197
|
+
key: 'Enter',
|
|
198
|
+
code: 'Enter',
|
|
199
|
+
})
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### State
|
|
203
|
+
|
|
204
|
+
#### `getState(threadId?)`
|
|
205
|
+
|
|
206
|
+
Gets the current browser state including URL and tabs.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
const state = await browser.getState('thread-123')
|
|
210
|
+
console.log('Current URL:', state.currentUrl)
|
|
211
|
+
console.log('Tabs:', state.tabs)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Returns:** `Promise<BrowserState>`
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
interface BrowserState {
|
|
218
|
+
currentUrl: string | null
|
|
219
|
+
tabs: BrowserTabState[]
|
|
220
|
+
activeTabIndex: number
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
interface BrowserTabState {
|
|
224
|
+
id: string
|
|
225
|
+
url: string
|
|
226
|
+
title: string
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### `getCurrentUrl(threadId?)`
|
|
231
|
+
|
|
232
|
+
Gets the current page URL.
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
const url = await browser.getCurrentUrl()
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Returns:** `Promise<string | null>`
|
|
239
|
+
|
|
240
|
+
## Browser scope
|
|
241
|
+
|
|
242
|
+
The `scope` option controls how browser instances are shared across conversation threads:
|
|
243
|
+
|
|
244
|
+
| Scope | Description | Use case |
|
|
245
|
+
| ---------- | ------------------------------------------- | ---------------------------------------- |
|
|
246
|
+
| `'shared'` | All threads share a single browser instance | Cost-efficient for non-conflicting tasks |
|
|
247
|
+
| `'thread'` | Each thread gets its own browser instance | Full isolation for concurrent users |
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
// Shared browser for all threads
|
|
251
|
+
const sharedBrowser = new AgentBrowser({
|
|
252
|
+
scope: 'shared',
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
// Isolated browser per thread
|
|
256
|
+
const isolatedBrowser = new AgentBrowser({
|
|
257
|
+
scope: 'thread',
|
|
258
|
+
})
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
When using `cdpUrl` to connect to an external browser, the scope automatically falls back to `'shared'` since you can't spawn new browser instances.
|
|
262
|
+
|
|
263
|
+
## Cloud browser providers
|
|
264
|
+
|
|
265
|
+
Connect to cloud browser services using the `cdpUrl` option:
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
// Static CDP URL
|
|
269
|
+
const browser = new AgentBrowser({
|
|
270
|
+
cdpUrl: 'wss://browser.example.com/ws',
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
// Dynamic CDP URL (e.g., session-based)
|
|
274
|
+
const browser = new AgentBrowser({
|
|
275
|
+
cdpUrl: async () => {
|
|
276
|
+
const session = await createBrowserSession()
|
|
277
|
+
return session.wsUrl
|
|
278
|
+
},
|
|
279
|
+
})
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## Related
|
|
283
|
+
|
|
284
|
+
- [AgentBrowser](https://mastra.ai/reference/browser/agent-browser): Deterministic browser automation
|
|
285
|
+
- [StagehandBrowser](https://mastra.ai/reference/browser/stagehand-browser): AI-powered browser automation
|
|
286
|
+
- [Browser overview](https://mastra.ai/docs/browser/overview): Conceptual guide to browser automation
|