@mastra/mcp-docs-server 1.1.22-alpha.11 → 1.1.22-alpha.13
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/browser/agent-browser.md +75 -0
- package/.docs/docs/browser/overview.md +136 -0
- package/.docs/docs/browser/stagehand.md +128 -0
- package/.docs/docs/observability/tracing/exporters/arthur.md +163 -0
- package/.docs/docs/observability/tracing/exporters/langfuse.md +19 -33
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/zenmux.md +3 -5
- package/.docs/reference/browser/agent-browser.md +374 -0
- package/.docs/reference/browser/mastra-browser.md +284 -0
- package/.docs/reference/browser/stagehand-browser.md +290 -0
- package/.docs/reference/index.md +3 -0
- package/.docs/reference/observability/tracing/exporters/arthur.md +122 -0
- package/.docs/reference/observability/tracing/exporters/langfuse.md +23 -32
- package/CHANGELOG.md +14 -0
- package/package.json +3 -3
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# StagehandBrowser class
|
|
2
|
+
|
|
3
|
+
The `StagehandBrowser` class provides AI-powered browser automation using [Stagehand](https://github.com/browserbase/stagehand). It uses natural language instructions for interactions instead of element refs.
|
|
4
|
+
|
|
5
|
+
Use `StagehandBrowser` when you want AI to interpret and execute browser actions from natural language. For deterministic automation using element refs, see [`AgentBrowser`](https://mastra.ai/reference/browser/agent-browser).
|
|
6
|
+
|
|
7
|
+
## Usage example
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { Agent } from '@mastra/core/agent'
|
|
11
|
+
import { StagehandBrowser } from '@mastra/stagehand'
|
|
12
|
+
|
|
13
|
+
const browser = new StagehandBrowser({
|
|
14
|
+
headless: true,
|
|
15
|
+
model: 'openai/gpt-5.4',
|
|
16
|
+
selfHeal: true,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const browserAgent = new Agent({
|
|
20
|
+
name: 'browser-agent',
|
|
21
|
+
instructions: `You can browse the web using natural language.
|
|
22
|
+
Use stagehand_act to perform actions like "click the login button".
|
|
23
|
+
Use stagehand_extract to get data from pages.`,
|
|
24
|
+
model: 'openai/gpt-5.4',
|
|
25
|
+
browser,
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Constructor parameters
|
|
30
|
+
|
|
31
|
+
**headless** (`boolean`): Whether to run the browser in headless mode. (Default: `true`)
|
|
32
|
+
|
|
33
|
+
**viewport** (`{ width: number; height: number }`): Browser viewport dimensions. (Default: `{ width: 1280, height: 720 }`)
|
|
34
|
+
|
|
35
|
+
**env** (`'LOCAL' | 'BROWSERBASE'`): Environment to run the browser in. Use 'BROWSERBASE' for cloud execution. (Default: `'LOCAL'`)
|
|
36
|
+
|
|
37
|
+
**apiKey** (`string`): Browserbase API key. Required when env is 'BROWSERBASE'.
|
|
38
|
+
|
|
39
|
+
**projectId** (`string`): Browserbase project ID. Required when env is 'BROWSERBASE'.
|
|
40
|
+
|
|
41
|
+
**model** (`string | ModelConfiguration`): Model configuration for AI operations. Can be a string like 'openai/gpt-5.4' or an object with modelName, apiKey, and baseURL. (Default: `'openai/gpt-5.4'`)
|
|
42
|
+
|
|
43
|
+
**selfHeal** (`boolean`): Enable self-healing selectors. When enabled, Stagehand uses AI to find elements even when initial selectors fail. (Default: `true`)
|
|
44
|
+
|
|
45
|
+
**domSettleTimeout** (`number`): Timeout in milliseconds for DOM to settle after actions. (Default: `5000`)
|
|
46
|
+
|
|
47
|
+
**verbose** (`0 | 1 | 2`): Logging verbosity level. 0 = silent, 1 = errors only, 2 = verbose. (Default: `1`)
|
|
48
|
+
|
|
49
|
+
**systemPrompt** (`string`): Custom system prompt for AI operations.
|
|
50
|
+
|
|
51
|
+
**cdpUrl** (`string | (() => string | Promise<string>)`): CDP WebSocket URL or HTTP endpoint for connecting to an existing browser. HTTP endpoints are resolved to WebSocket internally.
|
|
52
|
+
|
|
53
|
+
**scope** (`'shared' | 'thread'`): Browser instance scope across threads. (Default: `'thread' (or 'shared' when cdpUrl is provided)`)
|
|
54
|
+
|
|
55
|
+
**timeout** (`number`): Default timeout in milliseconds for browser operations. (Default: `10000`)
|
|
56
|
+
|
|
57
|
+
**onLaunch** (`(args: { browser: MastraBrowser }) => void | Promise<void>`): Callback invoked after the browser is ready.
|
|
58
|
+
|
|
59
|
+
**onClose** (`(args: { browser: MastraBrowser }) => void | Promise<void>`): Callback invoked before the browser closes.
|
|
60
|
+
|
|
61
|
+
**screencast** (`ScreencastOptions`): Configuration for streaming browser frames to Studio.
|
|
62
|
+
|
|
63
|
+
## Tools
|
|
64
|
+
|
|
65
|
+
`StagehandBrowser` provides 6 AI-powered tools for browser automation:
|
|
66
|
+
|
|
67
|
+
| Tool | Description |
|
|
68
|
+
| -------------------- | --------------------------------------------------- |
|
|
69
|
+
| `stagehand_act` | Perform actions using natural language instructions |
|
|
70
|
+
| `stagehand_extract` | Extract structured data from pages |
|
|
71
|
+
| `stagehand_observe` | Discover actionable elements on a page |
|
|
72
|
+
| `stagehand_navigate` | Navigate to a URL |
|
|
73
|
+
| `stagehand_tabs` | Manage browser tabs |
|
|
74
|
+
| `stagehand_close` | Close the browser |
|
|
75
|
+
|
|
76
|
+
## Tool reference
|
|
77
|
+
|
|
78
|
+
### `stagehand_act`
|
|
79
|
+
|
|
80
|
+
Perform an action using natural language instructions. The AI interprets your instruction and executes the appropriate browser action.
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
// Tool input
|
|
84
|
+
{
|
|
85
|
+
"instruction": "click the login button",
|
|
86
|
+
"variables": { "username": "john" },
|
|
87
|
+
"useVision": true,
|
|
88
|
+
"timeout": 30000
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// With variable substitution
|
|
92
|
+
{
|
|
93
|
+
"instruction": "type %email% into the email field",
|
|
94
|
+
"variables": { "email": "user@example.com" }
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
| Parameter | Type | Description |
|
|
99
|
+
| ------------- | ------------------------ | ---------------------------------------------------- |
|
|
100
|
+
| `instruction` | `string` | Natural language instruction (required) |
|
|
101
|
+
| `variables` | `Record<string, string>` | Variables for %variableName% substitution (optional) |
|
|
102
|
+
| `useVision` | `boolean` | Enable vision capabilities (optional) |
|
|
103
|
+
| `timeout` | `number` | Timeout in ms (optional) |
|
|
104
|
+
|
|
105
|
+
**Returns:**
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
interface ActResult {
|
|
109
|
+
success: boolean
|
|
110
|
+
message?: string
|
|
111
|
+
action?: string
|
|
112
|
+
url?: string
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### `stagehand_extract`
|
|
117
|
+
|
|
118
|
+
Extract structured data from a page using natural language instructions.
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
// Basic extraction
|
|
122
|
+
{
|
|
123
|
+
"instruction": "extract all product names and prices"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// With schema for structured output
|
|
127
|
+
{
|
|
128
|
+
"instruction": "extract the product information",
|
|
129
|
+
"schema": {
|
|
130
|
+
"type": "object",
|
|
131
|
+
"properties": {
|
|
132
|
+
"name": { "type": "string" },
|
|
133
|
+
"price": { "type": "number" },
|
|
134
|
+
"inStock": { "type": "boolean" }
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Returns:**
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
interface ExtractResult<T = unknown> {
|
|
144
|
+
success: boolean
|
|
145
|
+
data?: T
|
|
146
|
+
hint?: string
|
|
147
|
+
error?: string
|
|
148
|
+
url?: string
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### `stagehand_observe`
|
|
153
|
+
|
|
154
|
+
Discover actionable elements on a page. Returns a list of elements with their selectors and descriptions.
|
|
155
|
+
|
|
156
|
+
```text
|
|
157
|
+
// Find specific elements
|
|
158
|
+
{
|
|
159
|
+
"instruction": "find all buttons related to checkout"
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Find all interactive elements
|
|
163
|
+
{
|
|
164
|
+
"onlyVisible": true
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
| Parameter | Type | Description |
|
|
169
|
+
| ------------- | --------- | --------------------------------------------------------- |
|
|
170
|
+
| `instruction` | `string` | Natural language instruction (optional, omit to find all) |
|
|
171
|
+
| `onlyVisible` | `boolean` | Only include visible elements (optional) |
|
|
172
|
+
| `timeout` | `number` | Timeout in ms (optional) |
|
|
173
|
+
|
|
174
|
+
**Returns:**
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
interface ObserveResult {
|
|
178
|
+
success: boolean
|
|
179
|
+
actions: StagehandAction[]
|
|
180
|
+
url?: string
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
interface StagehandAction {
|
|
184
|
+
selector: string
|
|
185
|
+
description: string
|
|
186
|
+
method?: string
|
|
187
|
+
arguments?: string[]
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### `stagehand_navigate`
|
|
192
|
+
|
|
193
|
+
Navigate to a URL.
|
|
194
|
+
|
|
195
|
+
```text
|
|
196
|
+
// Tool input
|
|
197
|
+
{
|
|
198
|
+
"url": "https://example.com",
|
|
199
|
+
"waitUntil": "domcontentloaded"
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
| Parameter | Type | Description |
|
|
204
|
+
| ----------- | ----------------------------------------------- | ----------------------------------------------- |
|
|
205
|
+
| `url` | `string` | URL to navigate to (required) |
|
|
206
|
+
| `waitUntil` | `"load" \| "domcontentloaded" \| "networkidle"` | When to consider navigation complete (optional) |
|
|
207
|
+
|
|
208
|
+
### `stagehand_tabs`
|
|
209
|
+
|
|
210
|
+
Manage browser tabs.
|
|
211
|
+
|
|
212
|
+
```text
|
|
213
|
+
// List all tabs
|
|
214
|
+
{ "action": "list" }
|
|
215
|
+
|
|
216
|
+
// Open new tab
|
|
217
|
+
{ "action": "new", "url": "https://example.com" }
|
|
218
|
+
|
|
219
|
+
// Switch to tab by index
|
|
220
|
+
{ "action": "switch", "index": 0 }
|
|
221
|
+
|
|
222
|
+
// Close tab by index (or current if omitted)
|
|
223
|
+
{ "action": "close", "index": 1 }
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### `stagehand_close`
|
|
227
|
+
|
|
228
|
+
Close the browser and clean up resources.
|
|
229
|
+
|
|
230
|
+
```text
|
|
231
|
+
// Tool input (no parameters required)
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Using Browserbase
|
|
236
|
+
|
|
237
|
+
Run Stagehand in the cloud using Browserbase:
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
const browser = new StagehandBrowser({
|
|
241
|
+
env: 'BROWSERBASE',
|
|
242
|
+
apiKey: process.env.BROWSERBASE_API_KEY,
|
|
243
|
+
projectId: process.env.BROWSERBASE_PROJECT_ID,
|
|
244
|
+
model: 'openai/gpt-5.4',
|
|
245
|
+
})
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Model configuration
|
|
249
|
+
|
|
250
|
+
Configure the AI model for Stagehand operations:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
// String format: "provider/model"
|
|
254
|
+
const browser = new StagehandBrowser({
|
|
255
|
+
model: 'openai/gpt-5.4',
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
// Object format for custom configuration
|
|
259
|
+
const browser = new StagehandBrowser({
|
|
260
|
+
model: {
|
|
261
|
+
modelName: 'gpt-5.4',
|
|
262
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
263
|
+
baseURL: 'https://api.openai.com/v1',
|
|
264
|
+
},
|
|
265
|
+
})
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Supported providers:
|
|
269
|
+
|
|
270
|
+
- OpenAI: `"openai/gpt-5.4"`, `"openai/gpt-5.4-mini"`
|
|
271
|
+
- Anthropic: `"anthropic/claude-3-5-sonnet-20241022"`
|
|
272
|
+
|
|
273
|
+
## AgentBrowser vs StagehandBrowser
|
|
274
|
+
|
|
275
|
+
| Aspect | AgentBrowser | StagehandBrowser |
|
|
276
|
+
| --------------- | -------------------------- | --------------------- |
|
|
277
|
+
| **Approach** | Deterministic refs (`@e5`) | Natural language |
|
|
278
|
+
| **Precision** | Exact element targeting | AI interpretation |
|
|
279
|
+
| **Flexibility** | Requires a snapshot first | Direct instructions |
|
|
280
|
+
| **Use case** | Reproducible automation | Adaptive automation |
|
|
281
|
+
| **Speed** | Faster (no AI inference) | Slower (AI inference) |
|
|
282
|
+
|
|
283
|
+
Choose `AgentBrowser` for precise, reproducible automation. Choose `StagehandBrowser` for flexible, natural language interactions.
|
|
284
|
+
|
|
285
|
+
## Related
|
|
286
|
+
|
|
287
|
+
- [MastraBrowser](https://mastra.ai/reference/browser/mastra-browser): Base class reference
|
|
288
|
+
- [AgentBrowser](https://mastra.ai/reference/browser/agent-browser): Deterministic alternative
|
|
289
|
+
- [Browser overview](https://mastra.ai/docs/browser/overview): Conceptual guide
|
|
290
|
+
- [Stagehand guide](https://mastra.ai/docs/browser/stagehand): Usage guide
|
package/.docs/reference/index.md
CHANGED
|
@@ -39,6 +39,9 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
39
39
|
- [Okta](https://mastra.ai/reference/auth/okta)
|
|
40
40
|
- [Supabase](https://mastra.ai/reference/auth/supabase)
|
|
41
41
|
- [WorkOS](https://mastra.ai/reference/auth/workos)
|
|
42
|
+
- [AgentBrowser](https://mastra.ai/reference/browser/agent-browser)
|
|
43
|
+
- [MastraBrowser Class](https://mastra.ai/reference/browser/mastra-browser)
|
|
44
|
+
- [StagehandBrowser](https://mastra.ai/reference/browser/stagehand-browser)
|
|
42
45
|
- [create-mastra](https://mastra.ai/reference/cli/create-mastra)
|
|
43
46
|
- [mastra](https://mastra.ai/reference/cli/mastra)
|
|
44
47
|
- [Agents API](https://mastra.ai/reference/client-js/agents)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# ArthurExporter
|
|
2
|
+
|
|
3
|
+
Sends Tracing data to [Arthur Engine](https://github.com/arthur-ai/arthur-engine) using OpenTelemetry and OpenInference semantic conventions.
|
|
4
|
+
|
|
5
|
+
## Constructor
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
new ArthurExporter(config: ArthurExporterConfig)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## `ArthurExporterConfig`
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
type ArthurExporterConfig = Omit<OtelExporterConfig, 'provider' | 'exporter'> & {
|
|
15
|
+
apiKey?: string
|
|
16
|
+
endpoint?: string
|
|
17
|
+
taskId?: string
|
|
18
|
+
headers?: Record<string, string>
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Inherits from `OtelExporterConfig` (excluding `provider` and `exporter`), which includes:
|
|
23
|
+
|
|
24
|
+
- `timeout?: number` - Export timeout in milliseconds (default: 30000)
|
|
25
|
+
- `batchSize?: number` - Number of spans per batch (default: 512)
|
|
26
|
+
- `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - Log level (default: WARN)
|
|
27
|
+
- `resourceAttributes?: Record<string, any>` - Custom resource attributes
|
|
28
|
+
|
|
29
|
+
### Metadata passthrough
|
|
30
|
+
|
|
31
|
+
Non-reserved span attributes are serialized into the OpenInference `metadata` payload. Add them via `tracingOptions.metadata` (e.g., `companyId`, `tier`). Reserved fields such as `input`, `output`, `sessionId`, thread/user IDs, and OpenInference IDs are excluded automatically.
|
|
32
|
+
|
|
33
|
+
## Methods
|
|
34
|
+
|
|
35
|
+
### `exportTracingEvent`
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
async exportTracingEvent(event: TracingEvent): Promise<void>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Exports a tracing event to the configured endpoint.
|
|
42
|
+
|
|
43
|
+
### export
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
async export(spans: ReadOnlySpan[]): Promise<void>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Batch exports spans using OpenTelemetry with OpenInference semantic conventions.
|
|
50
|
+
|
|
51
|
+
### flush
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
async flush(): Promise<void>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Force flushes any buffered spans to the configured endpoint without shutting down the exporter. Useful in serverless environments where you need to ensure spans are exported before the runtime terminates.
|
|
58
|
+
|
|
59
|
+
### shutdown
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
async shutdown(): Promise<void>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Flushes pending data and shuts down the client.
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
### Zero-Config (using environment variables)
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { ArthurExporter } from '@mastra/arthur'
|
|
73
|
+
|
|
74
|
+
// Set ARTHUR_API_KEY and ARTHUR_BASE_URL (optionally ARTHUR_TASK_ID)
|
|
75
|
+
const exporter = new ArthurExporter()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Explicit Configuration
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { ArthurExporter } from '@mastra/arthur'
|
|
82
|
+
|
|
83
|
+
const exporter = new ArthurExporter({
|
|
84
|
+
apiKey: process.env.ARTHUR_API_KEY!,
|
|
85
|
+
endpoint: 'http://localhost:3030',
|
|
86
|
+
taskId: process.env.ARTHUR_TASK_ID, // Optional
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## `OpenInference` semantic conventions
|
|
91
|
+
|
|
92
|
+
The ArthurExporter implements [OpenInference Semantic Conventions](https://github.com/Arize-ai/openinference/tree/main/spec) for generative AI applications, providing standardized trace structure across different observability platforms.
|
|
93
|
+
|
|
94
|
+
## Tags support
|
|
95
|
+
|
|
96
|
+
The ArthurExporter supports trace tagging for categorization and filtering. Tags are only applied to root spans and are mapped to the native OpenInference `tag.tags` semantic convention.
|
|
97
|
+
|
|
98
|
+
### Usage
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const result = await agent.generate('Hello', {
|
|
102
|
+
tracingOptions: {
|
|
103
|
+
tags: ['production', 'experiment-v2', 'user-request'],
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### How Tags Are Stored
|
|
109
|
+
|
|
110
|
+
Tags are stored using the OpenInference `tag.tags` attribute:
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"tag.tags": ["production", "experiment-v2", "user-request"]
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Related
|
|
119
|
+
|
|
120
|
+
- [ArthurExporter Documentation](https://mastra.ai/docs/observability/tracing/exporters/arthur)
|
|
121
|
+
- [Arthur Engine documentation](https://docs.arthur.ai/)
|
|
122
|
+
- [Arthur Engine repository](https://github.com/arthur-ai/arthur-engine)
|
|
@@ -16,7 +16,8 @@ interface LangfuseExporterConfig extends BaseExporterConfig {
|
|
|
16
16
|
secretKey?: string
|
|
17
17
|
baseUrl?: string
|
|
18
18
|
realtime?: boolean
|
|
19
|
-
|
|
19
|
+
environment?: string
|
|
20
|
+
release?: string
|
|
20
21
|
}
|
|
21
22
|
```
|
|
22
23
|
|
|
@@ -25,23 +26,17 @@ Extends `BaseExporterConfig`, which includes:
|
|
|
25
26
|
- `logger?: IMastraLogger` - Logger instance
|
|
26
27
|
- `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - Log level (default: INFO)
|
|
27
28
|
|
|
28
|
-
##
|
|
29
|
+
## Properties
|
|
29
30
|
|
|
30
|
-
### `
|
|
31
|
+
### `client`
|
|
31
32
|
|
|
32
33
|
```typescript
|
|
33
|
-
|
|
34
|
+
get client(): LangfuseClient | undefined
|
|
34
35
|
```
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### export
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
async export(spans: ReadOnlySpan[]): Promise<void>
|
|
42
|
-
```
|
|
37
|
+
The `LangfuseClient` instance for advanced Langfuse features. Returns `undefined` when the exporter is disabled (missing credentials). Use this for prompt management, evaluations, datasets, and direct API access.
|
|
43
38
|
|
|
44
|
-
|
|
39
|
+
## Methods
|
|
45
40
|
|
|
46
41
|
### flush
|
|
47
42
|
|
|
@@ -49,7 +44,7 @@ Batch exports spans to Langfuse.
|
|
|
49
44
|
async flush(): Promise<void>
|
|
50
45
|
```
|
|
51
46
|
|
|
52
|
-
Force flushes any buffered spans to Langfuse without shutting down
|
|
47
|
+
Force flushes any buffered spans and scores to Langfuse without shutting down. Useful in serverless environments where you need to ensure data is exported before the runtime terminates.
|
|
53
48
|
|
|
54
49
|
### shutdown
|
|
55
50
|
|
|
@@ -57,7 +52,7 @@ Force flushes any buffered spans to Langfuse without shutting down the exporter.
|
|
|
57
52
|
async shutdown(): Promise<void>
|
|
58
53
|
```
|
|
59
54
|
|
|
60
|
-
Flushes pending data and shuts down the client.
|
|
55
|
+
Flushes pending data and shuts down both the span processor and the client.
|
|
61
56
|
|
|
62
57
|
## Usage
|
|
63
58
|
|
|
@@ -85,10 +80,11 @@ const exporter = new LangfuseExporter({
|
|
|
85
80
|
|
|
86
81
|
## Span mapping
|
|
87
82
|
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
Mastra spans are converted to OTel format and sent to Langfuse via `LangfuseSpanProcessor`. Langfuse automatically maps spans based on their `gen_ai.*` attributes:
|
|
84
|
+
|
|
85
|
+
- Spans with a `model` attribute → Langfuse generations
|
|
90
86
|
- All other spans → Langfuse spans
|
|
91
|
-
-
|
|
87
|
+
- Parent-child relationships are preserved via OTel trace/span IDs
|
|
92
88
|
|
|
93
89
|
## Prompt linking
|
|
94
90
|
|
|
@@ -96,22 +92,21 @@ Link LLM generations to [Langfuse Prompt Management](https://langfuse.com/docs/p
|
|
|
96
92
|
|
|
97
93
|
```typescript
|
|
98
94
|
import { buildTracingOptions } from '@mastra/observability'
|
|
99
|
-
import { withLangfusePrompt } from '@mastra/langfuse'
|
|
100
|
-
import { Langfuse } from 'langfuse'
|
|
95
|
+
import { LangfuseExporter, withLangfusePrompt } from '@mastra/langfuse'
|
|
101
96
|
|
|
102
|
-
const
|
|
103
|
-
publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
|
|
104
|
-
secretKey: process.env.LANGFUSE_SECRET_KEY!,
|
|
105
|
-
})
|
|
97
|
+
const exporter = new LangfuseExporter()
|
|
106
98
|
|
|
107
|
-
|
|
99
|
+
// Fetch prompt via the Langfuse client
|
|
100
|
+
const prompt = await exporter.client.prompt.get('customer-support', { type: 'text' })
|
|
108
101
|
|
|
109
102
|
const agent = new Agent({
|
|
110
103
|
name: 'support-agent',
|
|
111
|
-
instructions: prompt.
|
|
104
|
+
instructions: prompt.compile(),
|
|
112
105
|
model: 'openai/gpt-5.4',
|
|
113
106
|
defaultGenerateOptions: {
|
|
114
|
-
tracingOptions: buildTracingOptions(
|
|
107
|
+
tracingOptions: buildTracingOptions(
|
|
108
|
+
withLangfusePrompt({ name: prompt.name, version: prompt.version }),
|
|
109
|
+
),
|
|
115
110
|
},
|
|
116
111
|
})
|
|
117
112
|
```
|
|
@@ -123,12 +118,8 @@ const agent = new Agent({
|
|
|
123
118
|
Adds Langfuse prompt metadata to tracing options.
|
|
124
119
|
|
|
125
120
|
```typescript
|
|
126
|
-
//
|
|
127
|
-
withLangfusePrompt(prompt)
|
|
128
|
-
|
|
129
|
-
// With manual fields
|
|
121
|
+
// Link by name and version (required for Langfuse v5)
|
|
130
122
|
withLangfusePrompt({ name: 'my-prompt', version: 1 })
|
|
131
|
-
withLangfusePrompt({ id: 'prompt-uuid' })
|
|
132
123
|
```
|
|
133
124
|
|
|
134
|
-
|
|
125
|
+
The prompt metadata is passed through as span attributes and Langfuse links the generation to the corresponding prompt.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 1.1.22-alpha.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`a50d220`](https://github.com/mastra-ai/mastra/commit/a50d220b01ecbc5644d489a3d446c3bd4ab30245)]:
|
|
8
|
+
- @mastra/core@1.23.0-alpha.9
|
|
9
|
+
|
|
10
|
+
## 1.1.22-alpha.12
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [[`ac7baf6`](https://github.com/mastra-ai/mastra/commit/ac7baf66ef1db15e03975ef4ebb02724f015a391), [`0df8321`](https://github.com/mastra-ai/mastra/commit/0df832196eeb2450ab77ce887e8553abdd44c5a6), [`61109b3`](https://github.com/mastra-ai/mastra/commit/61109b34feb0e38d54bee4b8ca83eb7345b1d557), [`33f1ead`](https://github.com/mastra-ai/mastra/commit/33f1eadfa19c86953f593478e5fa371093b33779)]:
|
|
15
|
+
- @mastra/core@1.23.0-alpha.8
|
|
16
|
+
|
|
3
17
|
## 1.1.22-alpha.10
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "1.1.22-alpha.
|
|
3
|
+
"version": "1.1.22-alpha.13",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"jsdom": "^26.1.0",
|
|
30
30
|
"local-pkg": "^1.1.2",
|
|
31
31
|
"zod": "^4.3.6",
|
|
32
|
-
"@mastra/core": "1.23.0-alpha.
|
|
32
|
+
"@mastra/core": "1.23.0-alpha.9",
|
|
33
33
|
"@mastra/mcp": "^1.4.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"vitest": "4.0.18",
|
|
49
49
|
"@internal/lint": "0.0.79",
|
|
50
50
|
"@internal/types-builder": "0.0.54",
|
|
51
|
-
"@mastra/core": "1.23.0-alpha.
|
|
51
|
+
"@mastra/core": "1.23.0-alpha.9"
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://mastra.ai",
|
|
54
54
|
"repository": {
|