@mastra/mcp-docs-server 1.0.0-beta.5 → 1.0.0-beta.7
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/organized/changelogs/%40mastra%2Fagent-builder.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +67 -67
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +110 -110
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +60 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +358 -358
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +79 -79
- package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +42 -0
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +61 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Flance.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +55 -55
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +125 -125
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +36 -36
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +59 -59
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +77 -77
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Frag.md +43 -43
- package/.docs/organized/changelogs/%40mastra%2Freact.md +16 -0
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +113 -113
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +19 -19
- package/.docs/organized/changelogs/create-mastra.md +15 -15
- package/.docs/organized/changelogs/mastra.md +30 -30
- package/.docs/organized/code-examples/agui.md +1 -0
- package/.docs/organized/code-examples/ai-elements.md +1 -1
- package/.docs/organized/code-examples/ai-sdk-useChat.md +1 -1
- package/.docs/organized/code-examples/ai-sdk-v5.md +2 -1
- package/.docs/organized/code-examples/assistant-ui.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +1 -1
- package/.docs/organized/code-examples/crypto-chatbot.md +1 -1
- package/.docs/organized/code-examples/mcp-server-adapters.md +721 -0
- package/.docs/organized/code-examples/server-app-access.md +342 -0
- package/.docs/organized/code-examples/server-express-adapter.md +87 -0
- package/.docs/organized/code-examples/server-hono-adapter.md +85 -0
- package/.docs/raw/agents/agent-approval.mdx +189 -0
- package/.docs/raw/agents/guardrails.mdx +13 -9
- package/.docs/raw/agents/networks.mdx +1 -0
- package/.docs/raw/agents/overview.mdx +8 -152
- package/.docs/raw/agents/processors.mdx +279 -0
- package/.docs/raw/agents/structured-output.mdx +224 -0
- package/.docs/raw/deployment/cloud-providers/index.mdx +19 -26
- package/.docs/raw/deployment/cloud-providers/netlify-deployer.mdx +44 -13
- package/.docs/raw/evals/running-in-ci.mdx +0 -2
- package/.docs/raw/{guides/getting-started → getting-started}/manual-install.mdx +2 -2
- package/.docs/raw/getting-started/start.mdx +1 -1
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +8 -0
- package/.docs/raw/guides/getting-started/quickstart.mdx +1 -1
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +421 -0
- package/.docs/raw/guides/index.mdx +3 -35
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +11 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +37 -0
- package/.docs/raw/index.mdx +1 -1
- package/.docs/raw/memory/memory-processors.mdx +265 -79
- package/.docs/raw/memory/working-memory.mdx +11 -2
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +200 -0
- package/.docs/raw/observability/tracing/exporters/arize.mdx +36 -0
- package/.docs/raw/observability/tracing/exporters/braintrust.mdx +19 -0
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +83 -0
- package/.docs/raw/observability/tracing/exporters/langsmith.mdx +12 -0
- package/.docs/raw/observability/tracing/exporters/otel.mdx +34 -22
- package/.docs/raw/observability/tracing/exporters/posthog.mdx +20 -0
- package/.docs/raw/observability/tracing/overview.mdx +76 -6
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +0 -1
- package/.docs/raw/rag/retrieval.mdx +23 -6
- package/.docs/raw/rag/vector-databases.mdx +93 -2
- package/.docs/raw/reference/agents/generate.mdx +55 -6
- package/.docs/raw/reference/agents/network.mdx +44 -0
- package/.docs/raw/reference/client-js/memory.mdx +43 -0
- package/.docs/raw/reference/client-js/workflows.mdx +92 -63
- package/.docs/raw/reference/deployer/netlify.mdx +1 -2
- package/.docs/raw/reference/evals/scorer-utils.mdx +362 -0
- package/.docs/raw/reference/index.mdx +1 -0
- package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +177 -0
- package/.docs/raw/reference/observability/tracing/configuration.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +29 -0
- package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +43 -0
- package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +17 -1
- package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +33 -43
- package/.docs/raw/reference/observability/tracing/instances.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/interfaces.mdx +29 -4
- package/.docs/raw/reference/observability/tracing/spans.mdx +0 -4
- package/.docs/raw/reference/processors/language-detector.mdx +9 -2
- package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
- package/.docs/raw/reference/processors/moderation-processor.mdx +10 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +10 -3
- package/.docs/raw/reference/processors/processor-interface.mdx +502 -0
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +9 -2
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
- package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
- package/.docs/raw/reference/server/create-route.mdx +314 -0
- package/.docs/raw/reference/server/express-adapter.mdx +193 -0
- package/.docs/raw/reference/server/hono-adapter.mdx +174 -0
- package/.docs/raw/reference/server/mastra-server.mdx +316 -0
- package/.docs/raw/reference/server/routes.mdx +250 -0
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
- package/.docs/raw/reference/storage/convex.mdx +164 -0
- package/.docs/raw/reference/storage/lance.mdx +33 -0
- package/.docs/raw/reference/storage/libsql.mdx +37 -0
- package/.docs/raw/reference/storage/mongodb.mdx +39 -0
- package/.docs/raw/reference/storage/mssql.mdx +37 -0
- package/.docs/raw/reference/storage/postgresql.mdx +37 -0
- package/.docs/raw/reference/streaming/ChunkType.mdx +1 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +56 -1
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +7 -9
- package/.docs/raw/reference/streaming/workflows/{resumeStreamVNext.mdx → resumeStream.mdx} +51 -11
- package/.docs/raw/reference/streaming/workflows/stream.mdx +83 -24
- package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +170 -0
- package/.docs/raw/reference/tools/mcp-client.mdx +128 -18
- package/.docs/raw/reference/vectors/convex.mdx +429 -0
- package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
- package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
- package/.docs/raw/reference/voice/google.mdx +159 -20
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +142 -0
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +44 -0
- package/.docs/raw/reference/workflows/run-methods/start.mdx +44 -0
- package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +310 -0
- package/.docs/raw/reference/workflows/run.mdx +27 -5
- package/.docs/raw/reference/workflows/step.mdx +13 -0
- package/.docs/raw/reference/workflows/workflow.mdx +19 -0
- package/.docs/raw/server-db/custom-adapters.mdx +380 -0
- package/.docs/raw/server-db/mastra-server.mdx +16 -8
- package/.docs/raw/server-db/request-context.mdx +0 -1
- package/.docs/raw/server-db/server-adapters.mdx +286 -0
- package/.docs/raw/server-db/storage.mdx +11 -0
- package/.docs/raw/streaming/overview.mdx +6 -6
- package/.docs/raw/streaming/tool-streaming.mdx +2 -2
- package/.docs/raw/streaming/workflow-streaming.mdx +5 -11
- package/.docs/raw/workflows/error-handling.mdx +1 -0
- package/.docs/raw/workflows/human-in-the-loop.mdx +4 -4
- package/.docs/raw/workflows/overview.mdx +56 -44
- package/.docs/raw/workflows/snapshots.mdx +1 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +85 -16
- package/.docs/raw/workflows/time-travel.mdx +313 -0
- package/.docs/raw/workflows/workflow-state.mdx +191 -0
- package/CHANGELOG.md +16 -0
- package/package.json +4 -4
- package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +0 -91
- package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
|
@@ -7,12 +7,6 @@ import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
|
7
7
|
|
|
8
8
|
# OtelExporter
|
|
9
9
|
|
|
10
|
-
:::warning
|
|
11
|
-
|
|
12
|
-
The OtelExporter is currently **experimental**. APIs and configuration options may change in future releases.
|
|
13
|
-
|
|
14
|
-
:::
|
|
15
|
-
|
|
16
10
|
Sends Tracing data to any OpenTelemetry-compatible observability platform using standardized GenAI semantic conventions.
|
|
17
11
|
|
|
18
12
|
## Constructor
|
|
@@ -317,38 +311,6 @@ const exporter = new OtelExporter({
|
|
|
317
311
|
});
|
|
318
312
|
```
|
|
319
313
|
|
|
320
|
-
## Span Mapping
|
|
321
|
-
|
|
322
|
-
The exporter maps Mastra AI spans to OpenTelemetry spans following GenAI semantic conventions:
|
|
323
|
-
|
|
324
|
-
### Span Names
|
|
325
|
-
|
|
326
|
-
- `MODEL_GENERATION` → `chat {model}` or `tool_selection {model}`
|
|
327
|
-
- `TOOL_CALL` → `tool.execute {tool_name}`
|
|
328
|
-
- `AGENT_RUN` → `agent.{agent_id}`
|
|
329
|
-
- `WORKFLOW_RUN` → `workflow.{workflow_id}`
|
|
330
|
-
|
|
331
|
-
### Span Kinds
|
|
332
|
-
|
|
333
|
-
- Root agent/workflow spans → `SERVER`
|
|
334
|
-
- LLM calls → `CLIENT`
|
|
335
|
-
- Tool calls → `INTERNAL` or `CLIENT`
|
|
336
|
-
- Workflow steps → `INTERNAL`
|
|
337
|
-
|
|
338
|
-
### Attributes
|
|
339
|
-
|
|
340
|
-
The exporter maps to standard OTEL GenAI attributes:
|
|
341
|
-
|
|
342
|
-
| Mastra Attribute | OTEL Attribute |
|
|
343
|
-
| ----------------------------------- | -------------------------------- |
|
|
344
|
-
| `model` | `gen_ai.request.model` |
|
|
345
|
-
| `provider` | `gen_ai.system` |
|
|
346
|
-
| `inputTokens` / `promptTokens` | `gen_ai.usage.input_tokens` |
|
|
347
|
-
| `outputTokens` / `completionTokens` | `gen_ai.usage.output_tokens` |
|
|
348
|
-
| `temperature` | `gen_ai.request.temperature` |
|
|
349
|
-
| `maxOutputTokens` | `gen_ai.request.max_tokens` |
|
|
350
|
-
| `finishReason` | `gen_ai.response.finish_reasons` |
|
|
351
|
-
|
|
352
314
|
## Protocol Requirements
|
|
353
315
|
|
|
354
316
|
Different providers require different OTEL exporter packages:
|
|
@@ -360,10 +322,38 @@ Different providers require different OTEL exporter packages:
|
|
|
360
322
|
| HTTP/JSON | `@opentelemetry/exporter-trace-otlp-http` | Traceloop, Custom |
|
|
361
323
|
| Zipkin | `@opentelemetry/exporter-zipkin` | Zipkin collectors |
|
|
362
324
|
|
|
363
|
-
## Parent-Child Relationships
|
|
364
325
|
|
|
365
|
-
|
|
326
|
+
## Tags Support
|
|
327
|
+
|
|
328
|
+
The OtelExporter supports trace tagging for categorization and filtering. Tags are only applied to root spans and are stored as the `mastra.tags` attribute.
|
|
329
|
+
|
|
330
|
+
### Usage
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
const result = await agent.generate({
|
|
334
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
335
|
+
tracingOptions: {
|
|
336
|
+
tags: ["production", "experiment-v2", "user-request"],
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### How Tags Are Stored
|
|
342
|
+
|
|
343
|
+
Tags are stored as a JSON-stringified array in the `mastra.tags` span attribute for maximum backend compatibility:
|
|
344
|
+
|
|
345
|
+
```json
|
|
346
|
+
{
|
|
347
|
+
"mastra.tags": "[\"production\",\"experiment-v2\",\"user-request\"]"
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
:::note
|
|
352
|
+
While the OpenTelemetry specification supports native array attributes, many backends (Jaeger, Zipkin, Tempo) have limited array support. JSON strings ensure consistent behavior across all observability platforms.
|
|
353
|
+
:::
|
|
354
|
+
|
|
355
|
+
## Related
|
|
366
356
|
|
|
367
|
-
-
|
|
368
|
-
-
|
|
369
|
-
-
|
|
357
|
+
- [OtelExporter Guide](/docs/v1/observability/tracing/exporters/otel) - Setup guide with provider configurations
|
|
358
|
+
- [OtelBridge](/docs/v1/observability/tracing/bridges/otel) - For bidirectional OTEL context integration
|
|
359
|
+
- [Tracing Overview](/docs/v1/observability/tracing/overview) - General tracing concepts
|
|
@@ -157,10 +157,6 @@ class CustomObservabilityInstance extends BaseObservabilityInstance {
|
|
|
157
157
|
- [Interfaces Reference](/reference/v1/observability/tracing/interfaces) - Type definitions
|
|
158
158
|
- [Spans Reference](/reference/v1/observability/tracing/spans) - Span lifecycle and methods
|
|
159
159
|
|
|
160
|
-
### Examples
|
|
161
|
-
|
|
162
|
-
- [Basic Tracing](/examples/v1/observability/basic-ai-tracing) - Getting started example
|
|
163
|
-
|
|
164
160
|
### Exporters
|
|
165
161
|
|
|
166
162
|
- [DefaultExporter](/reference/v1/observability/tracing/exporters/default-exporter) - Storage persistence
|
|
@@ -90,6 +90,9 @@ interface Span<TType extends SpanType> {
|
|
|
90
90
|
output?: any;
|
|
91
91
|
errorInfo?: any;
|
|
92
92
|
|
|
93
|
+
/** Tags for categorizing traces (only present on root spans) */
|
|
94
|
+
tags?: string[];
|
|
95
|
+
|
|
93
96
|
/** End the span */
|
|
94
97
|
end(options?: EndSpanOptions<TType>): void;
|
|
95
98
|
|
|
@@ -549,6 +552,32 @@ Options passed when starting a new agent or workflow execution.
|
|
|
549
552
|
interface TracingOptions {
|
|
550
553
|
/** Metadata to add to the root trace span */
|
|
551
554
|
metadata?: Record<string, any>;
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Additional RequestContext keys to extract as metadata for this trace.
|
|
558
|
+
* These keys are added to the requestContextKeys config.
|
|
559
|
+
* Supports dot notation for nested values (e.g., 'user.id', 'session.data.experimentId').
|
|
560
|
+
*/
|
|
561
|
+
requestContextKeys?: string[];
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Trace ID to use for this execution (1-32 hexadecimal characters).
|
|
565
|
+
* If provided, this trace will be part of the specified trace rather than starting a new one.
|
|
566
|
+
*/
|
|
567
|
+
traceId?: string;
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Parent span ID to use for this execution (1-16 hexadecimal characters).
|
|
571
|
+
* If provided, the root span will be created as a child of this span.
|
|
572
|
+
*/
|
|
573
|
+
parentSpanId?: string;
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Tags to apply to this trace.
|
|
577
|
+
* Tags are string labels that can be used to categorize and filter traces
|
|
578
|
+
* Note: Tags are only applied to the root span of a trace.
|
|
579
|
+
*/
|
|
580
|
+
tags?: string[];
|
|
552
581
|
}
|
|
553
582
|
```
|
|
554
583
|
|
|
@@ -707,7 +736,3 @@ enum InternalSpans {
|
|
|
707
736
|
- [Configuration](/reference/v1/observability/tracing/configuration) - Registry and configuration
|
|
708
737
|
- [Tracing Classes](/reference/v1/observability/tracing/instances) - Core implementations
|
|
709
738
|
- [Spans Reference](/reference/v1/observability/tracing/spans) - Span lifecycle methods
|
|
710
|
-
|
|
711
|
-
### Examples
|
|
712
|
-
|
|
713
|
-
- [Basic Tracing](/examples/v1/observability/basic-ai-tracing) - Implementation example
|
|
@@ -386,7 +386,3 @@ A span that performs no operations. All methods are no-ops:
|
|
|
386
386
|
- [Tracing Classes](/reference/v1/observability/tracing/instances) - Core tracing classes
|
|
387
387
|
- [Interfaces](/reference/v1/observability/tracing/interfaces) - Complete type reference
|
|
388
388
|
- [Configuration](/reference/v1/observability/tracing/configuration) - Configuration options
|
|
389
|
-
|
|
390
|
-
### Examples
|
|
391
|
-
|
|
392
|
-
- [Basic Tracing](/examples/v1/observability/basic-ai-tracing) - Working with spans
|
|
@@ -13,7 +13,7 @@ The `LanguageDetector` is an **input processor** that identifies the language of
|
|
|
13
13
|
import { LanguageDetector } from "@mastra/core/processors";
|
|
14
14
|
|
|
15
15
|
const processor = new LanguageDetector({
|
|
16
|
-
model: "openai/gpt-
|
|
16
|
+
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
17
17
|
targetLanguages: ["English", "en"],
|
|
18
18
|
threshold: 0.8,
|
|
19
19
|
strategy: "translate"
|
|
@@ -99,6 +99,13 @@ const processor = new LanguageDetector({
|
|
|
99
99
|
isOptional: true,
|
|
100
100
|
default: "'quality'",
|
|
101
101
|
},
|
|
102
|
+
{
|
|
103
|
+
name: "providerOptions",
|
|
104
|
+
type: "ProviderOptions",
|
|
105
|
+
description: "Provider-specific options passed to the internal detection agent. Use this to control model behavior like reasoning effort for thinking models (e.g., `{ openai: { reasoningEffort: 'low' } }`)",
|
|
106
|
+
isOptional: true,
|
|
107
|
+
default: "undefined",
|
|
108
|
+
},
|
|
102
109
|
]}
|
|
103
110
|
/>
|
|
104
111
|
|
|
@@ -139,7 +146,7 @@ export const agent = new Agent({
|
|
|
139
146
|
model: "openai/gpt-5.1",
|
|
140
147
|
inputProcessors: [
|
|
141
148
|
new LanguageDetector({
|
|
142
|
-
model: "openai/gpt-
|
|
149
|
+
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
143
150
|
targetLanguages: ["English", "en"],
|
|
144
151
|
threshold: 0.8,
|
|
145
152
|
strategy: "translate",
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Message History Processor | Processors"
|
|
3
|
+
description: "Documentation for the MessageHistory processor in Mastra, which handles retrieval and persistence of conversation history."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# MessageHistory
|
|
7
|
+
|
|
8
|
+
The `MessageHistory` is a **hybrid processor** that handles both retrieval and persistence of message history. On input, it fetches historical messages from storage and prepends them to the conversation. On output, it persists new messages to storage.
|
|
9
|
+
|
|
10
|
+
## Usage example
|
|
11
|
+
|
|
12
|
+
```typescript copy
|
|
13
|
+
import { MessageHistory } from "@mastra/core/processors";
|
|
14
|
+
|
|
15
|
+
const processor = new MessageHistory({
|
|
16
|
+
storage: memoryStorage,
|
|
17
|
+
lastMessages: 50,
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Constructor parameters
|
|
22
|
+
|
|
23
|
+
<PropertiesTable
|
|
24
|
+
content={[
|
|
25
|
+
{
|
|
26
|
+
name: "options",
|
|
27
|
+
type: "MessageHistoryOptions",
|
|
28
|
+
description: "Configuration options for the message history processor",
|
|
29
|
+
isOptional: false,
|
|
30
|
+
},
|
|
31
|
+
]}
|
|
32
|
+
/>
|
|
33
|
+
|
|
34
|
+
### Options
|
|
35
|
+
|
|
36
|
+
<PropertiesTable
|
|
37
|
+
content={[
|
|
38
|
+
{
|
|
39
|
+
name: "storage",
|
|
40
|
+
type: "MemoryStorage",
|
|
41
|
+
description: "Storage instance for retrieving and persisting messages",
|
|
42
|
+
isOptional: false,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "lastMessages",
|
|
46
|
+
type: "number",
|
|
47
|
+
description: "Maximum number of historical messages to retrieve. If not specified, retrieves all messages",
|
|
48
|
+
isOptional: true,
|
|
49
|
+
},
|
|
50
|
+
]}
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
## Returns
|
|
54
|
+
|
|
55
|
+
<PropertiesTable
|
|
56
|
+
content={[
|
|
57
|
+
{
|
|
58
|
+
name: "id",
|
|
59
|
+
type: "string",
|
|
60
|
+
description: "Processor identifier set to 'message-history'",
|
|
61
|
+
isOptional: false,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "name",
|
|
65
|
+
type: "string",
|
|
66
|
+
description: "Processor display name set to 'MessageHistory'",
|
|
67
|
+
isOptional: false,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "processInput",
|
|
71
|
+
type: "(args: { messages: MastraDBMessage[]; messageList: MessageList; abort: (reason?: string) => never; tracingContext?: TracingContext; requestContext?: RequestContext }) => Promise<MessageList | MastraDBMessage[]>",
|
|
72
|
+
description: "Fetches historical messages from storage and adds them to the message list",
|
|
73
|
+
isOptional: false,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "processOutputResult",
|
|
77
|
+
type: "(args: { messages: MastraDBMessage[]; messageList: MessageList; abort: (reason?: string) => never; tracingContext?: TracingContext; requestContext?: RequestContext }) => Promise<MessageList>",
|
|
78
|
+
description: "Persists new messages (user input and assistant response) to storage, excluding system messages",
|
|
79
|
+
isOptional: false,
|
|
80
|
+
},
|
|
81
|
+
]}
|
|
82
|
+
/>
|
|
83
|
+
|
|
84
|
+
## Extended usage example
|
|
85
|
+
|
|
86
|
+
```typescript title="src/mastra/agents/memory-agent.ts" showLineNumbers copy
|
|
87
|
+
import { Agent } from "@mastra/core/agent";
|
|
88
|
+
import { MessageHistory } from "@mastra/core/processors";
|
|
89
|
+
import { PostgresStorage } from "@mastra/pg";
|
|
90
|
+
|
|
91
|
+
const storage = new PostgresStorage({
|
|
92
|
+
connectionString: process.env.DATABASE_URL,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export const agent = new Agent({
|
|
96
|
+
name: "memory-agent",
|
|
97
|
+
instructions: "You are a helpful assistant with conversation memory",
|
|
98
|
+
model: "openai:gpt-4o",
|
|
99
|
+
inputProcessors: [
|
|
100
|
+
new MessageHistory({
|
|
101
|
+
storage,
|
|
102
|
+
lastMessages: 100,
|
|
103
|
+
}),
|
|
104
|
+
],
|
|
105
|
+
outputProcessors: [
|
|
106
|
+
new MessageHistory({
|
|
107
|
+
storage,
|
|
108
|
+
}),
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Behavior
|
|
114
|
+
|
|
115
|
+
### Input processing
|
|
116
|
+
1. Retrieves `threadId` from the request context
|
|
117
|
+
2. Fetches historical messages from storage (ordered by creation date, descending)
|
|
118
|
+
3. Filters out system messages (they should not be stored in the database)
|
|
119
|
+
4. Merges historical messages with incoming messages, avoiding duplicates by ID
|
|
120
|
+
5. Adds historical messages with `source: 'memory'` tag
|
|
121
|
+
|
|
122
|
+
### Output processing
|
|
123
|
+
1. Retrieves `threadId` from the request context
|
|
124
|
+
2. Skips persistence if `readOnly` is set in memory config
|
|
125
|
+
3. Filters out incomplete tool calls from messages
|
|
126
|
+
4. Persists new user input and assistant response messages to storage
|
|
127
|
+
5. Updates the thread's `updatedAt` timestamp
|
|
128
|
+
|
|
129
|
+
## Related
|
|
130
|
+
|
|
131
|
+
- [Guardrails](/docs/v1/agents/guardrails)
|
|
@@ -13,7 +13,7 @@ The `ModerationProcessor` is a **hybrid processor** that can be used for both in
|
|
|
13
13
|
import { ModerationProcessor } from "@mastra/core/processors";
|
|
14
14
|
|
|
15
15
|
const processor = new ModerationProcessor({
|
|
16
|
-
model: "openai/gpt-
|
|
16
|
+
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
17
17
|
threshold: 0.7,
|
|
18
18
|
strategy: "block",
|
|
19
19
|
categories: ["hate", "harassment", "violence"]
|
|
@@ -85,6 +85,13 @@ const processor = new ModerationProcessor({
|
|
|
85
85
|
isOptional: true,
|
|
86
86
|
default: "0 (no context window)",
|
|
87
87
|
},
|
|
88
|
+
{
|
|
89
|
+
name: "providerOptions",
|
|
90
|
+
type: "ProviderOptions",
|
|
91
|
+
description: "Provider-specific options passed to the internal moderation agent. Use this to control model behavior like reasoning effort for thinking models (e.g., `{ openai: { reasoningEffort: 'low' } }`)",
|
|
92
|
+
isOptional: true,
|
|
93
|
+
default: "undefined",
|
|
94
|
+
},
|
|
88
95
|
]}
|
|
89
96
|
/>
|
|
90
97
|
|
|
@@ -133,7 +140,7 @@ export const agent = new Agent({
|
|
|
133
140
|
model: "openai/gpt-5.1",
|
|
134
141
|
inputProcessors: [
|
|
135
142
|
new ModerationProcessor({
|
|
136
|
-
model: "openai/gpt-
|
|
143
|
+
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
137
144
|
categories: ["hate", "harassment", "violence"],
|
|
138
145
|
threshold: 0.7,
|
|
139
146
|
strategy: "block",
|
|
@@ -163,7 +170,7 @@ export const agent = new Agent({
|
|
|
163
170
|
}),
|
|
164
171
|
// Then apply moderation on batched content
|
|
165
172
|
new ModerationProcessor({
|
|
166
|
-
model: "openai/gpt-
|
|
173
|
+
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
167
174
|
strategy: "filter",
|
|
168
175
|
chunkWindow: 1,
|
|
169
176
|
}),
|
|
@@ -13,7 +13,7 @@ The `PIIDetector` is a **hybrid processor** that can be used for both input and
|
|
|
13
13
|
import { PIIDetector } from "@mastra/core/processors";
|
|
14
14
|
|
|
15
15
|
const processor = new PIIDetector({
|
|
16
|
-
model: "openai/gpt-
|
|
16
|
+
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
17
17
|
threshold: 0.6,
|
|
18
18
|
strategy: "redact",
|
|
19
19
|
detectionTypes: ["email", "phone", "credit-card", "ssn"]
|
|
@@ -92,6 +92,13 @@ const processor = new PIIDetector({
|
|
|
92
92
|
isOptional: true,
|
|
93
93
|
default: "true",
|
|
94
94
|
},
|
|
95
|
+
{
|
|
96
|
+
name: "providerOptions",
|
|
97
|
+
type: "ProviderOptions",
|
|
98
|
+
description: "Provider-specific options passed to the internal detection agent. Use this to control model behavior like reasoning effort for thinking models (e.g., `{ openai: { reasoningEffort: 'low' } }`)",
|
|
99
|
+
isOptional: true,
|
|
100
|
+
default: "undefined",
|
|
101
|
+
},
|
|
95
102
|
]}
|
|
96
103
|
/>
|
|
97
104
|
|
|
@@ -140,7 +147,7 @@ export const agent = new Agent({
|
|
|
140
147
|
model: "openai/gpt-5.1",
|
|
141
148
|
inputProcessors: [
|
|
142
149
|
new PIIDetector({
|
|
143
|
-
model: "openai/gpt-
|
|
150
|
+
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
144
151
|
detectionTypes: ["email", "phone", "credit-card", "ssn"],
|
|
145
152
|
threshold: 0.6,
|
|
146
153
|
strategy: "redact",
|
|
@@ -172,7 +179,7 @@ export const agent = new Agent({
|
|
|
172
179
|
}),
|
|
173
180
|
// Then apply PII detection on batched content
|
|
174
181
|
new PIIDetector({
|
|
175
|
-
model: "openai/gpt-
|
|
182
|
+
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
176
183
|
strategy: "redact",
|
|
177
184
|
})
|
|
178
185
|
]
|