@mastra/mcp-docs-server 1.0.0-beta.4 → 1.0.0-beta.6
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/%40internal%2Fstorage-test-utils.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +29 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +411 -211
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +42 -0
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +52 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Flance.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Frag.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Freact.md +89 -1
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +42 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +92 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +67 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +201 -1
- package/.docs/organized/changelogs/create-mastra.md +201 -1
- package/.docs/organized/changelogs/mastra.md +201 -1
- package/.docs/organized/code-examples/agui.md +1 -0
- package/.docs/organized/code-examples/ai-sdk-v5.md +1 -0
- package/.docs/organized/code-examples/mcp-server-adapters.md +721 -0
- package/.docs/organized/code-examples/memory-with-processors.md +1 -1
- package/.docs/organized/code-examples/quick-start.md +1 -1
- package/.docs/organized/code-examples/server-app-access.md +342 -0
- package/.docs/raw/agents/adding-voice.mdx +7 -10
- package/.docs/raw/agents/agent-approval.mdx +189 -0
- package/.docs/raw/agents/guardrails.mdx +26 -23
- package/.docs/raw/agents/networks.mdx +2 -2
- package/.docs/raw/agents/overview.mdx +27 -62
- package/.docs/raw/agents/processors.mdx +279 -0
- package/.docs/raw/agents/using-tools.mdx +4 -5
- package/.docs/raw/course/01-first-agent/05-running-playground.md +5 -5
- package/.docs/raw/course/01-first-agent/09-testing-your-agent.md +3 -3
- package/.docs/raw/course/01-first-agent/13-testing-your-tool.md +3 -3
- package/.docs/raw/course/01-first-agent/17-testing-memory.md +2 -2
- package/.docs/raw/course/04-workflows/07-using-playground.md +1 -1
- package/.docs/raw/deployment/building-mastra.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +20 -27
- package/.docs/raw/deployment/cloud-providers/netlify-deployer.mdx +44 -13
- package/.docs/raw/deployment/mastra-cloud/observability.mdx +19 -17
- package/.docs/raw/deployment/mastra-cloud/setting-up.mdx +1 -1
- package/.docs/raw/deployment/overview.mdx +2 -2
- package/.docs/raw/deployment/web-framework.mdx +5 -5
- package/.docs/raw/evals/custom-scorers.mdx +3 -5
- package/.docs/raw/evals/overview.mdx +2 -3
- package/.docs/raw/evals/running-in-ci.mdx +0 -2
- package/.docs/raw/{guides/guide → getting-started}/manual-install.mdx +2 -2
- package/.docs/raw/getting-started/project-structure.mdx +1 -1
- package/.docs/raw/getting-started/start.mdx +72 -0
- package/.docs/raw/getting-started/studio.mdx +1 -1
- package/.docs/raw/{frameworks/agentic-uis/ai-sdk.mdx → guides/build-your-ui/ai-sdk-ui.mdx} +113 -11
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/astro.mdx +23 -25
- package/.docs/raw/{frameworks/servers → guides/getting-started}/express.mdx +3 -4
- package/.docs/raw/guides/{quickstarts/nextjs.mdx → getting-started/next-js.mdx} +11 -11
- package/.docs/raw/guides/{quickstarts/standalone-server.mdx → getting-started/quickstart.mdx} +7 -7
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/sveltekit.mdx +23 -25
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/vite-react.mdx +7 -7
- package/.docs/raw/guides/guide/ai-recruiter.mdx +2 -3
- package/.docs/raw/guides/guide/chef-michel.mdx +2 -3
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +2 -2
- package/.docs/raw/guides/guide/research-assistant.mdx +7 -8
- package/.docs/raw/guides/guide/stock-agent.mdx +4 -6
- package/.docs/raw/guides/guide/web-search.mdx +12 -10
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +421 -0
- package/.docs/raw/guides/index.mdx +3 -35
- package/.docs/raw/guides/migrations/agentnetwork.mdx +4 -4
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +1 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +40 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +5 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +51 -0
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +2 -2
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/mcp/overview.mdx +3 -5
- package/.docs/raw/memory/memory-processors.mdx +264 -79
- package/.docs/raw/memory/semantic-recall.mdx +7 -7
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-pg.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +2 -4
- package/.docs/raw/memory/threads-and-resources.mdx +3 -3
- package/.docs/raw/memory/working-memory.mdx +14 -7
- package/.docs/raw/{logging.mdx → observability/logging.mdx} +1 -1
- package/.docs/raw/observability/overview.mdx +2 -3
- package/.docs/raw/observability/tracing/bridges/otel.mdx +176 -0
- package/.docs/raw/observability/tracing/exporters/arize.mdx +17 -0
- package/.docs/raw/observability/tracing/exporters/braintrust.mdx +19 -0
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +20 -0
- package/.docs/raw/observability/tracing/exporters/langsmith.mdx +12 -0
- package/.docs/raw/observability/tracing/exporters/otel.mdx +25 -5
- package/.docs/raw/observability/tracing/exporters/posthog.mdx +107 -0
- package/.docs/raw/observability/tracing/overview.mdx +74 -8
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +0 -1
- package/.docs/raw/rag/chunking-and-embedding.mdx +16 -17
- package/.docs/raw/rag/overview.mdx +3 -2
- package/.docs/raw/rag/retrieval.mdx +43 -38
- package/.docs/raw/rag/vector-databases.mdx +93 -2
- package/.docs/raw/reference/agents/agent.mdx +7 -10
- package/.docs/raw/reference/agents/generate.mdx +55 -6
- package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/network.mdx +46 -3
- package/.docs/raw/reference/cli/mastra.mdx +2 -1
- package/.docs/raw/reference/client-js/agents.mdx +3 -3
- package/.docs/raw/reference/client-js/memory.mdx +43 -0
- package/.docs/raw/reference/client-js/workflows.mdx +92 -63
- package/.docs/raw/reference/core/getLogger.mdx +1 -1
- package/.docs/raw/reference/core/listLogs.mdx +1 -1
- package/.docs/raw/reference/core/listLogsByRunId.mdx +1 -1
- package/.docs/raw/reference/core/mastra-model-gateway.mdx +5 -19
- package/.docs/raw/reference/core/setLogger.mdx +1 -1
- package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
- package/.docs/raw/reference/deployer/netlify.mdx +1 -2
- package/.docs/raw/reference/evals/answer-relevancy.mdx +28 -98
- package/.docs/raw/reference/evals/answer-similarity.mdx +12 -258
- package/.docs/raw/reference/evals/bias.mdx +29 -87
- package/.docs/raw/reference/evals/completeness.mdx +31 -90
- package/.docs/raw/reference/evals/content-similarity.mdx +28 -88
- package/.docs/raw/reference/evals/context-precision.mdx +28 -130
- package/.docs/raw/reference/evals/context-relevance.mdx +11 -11
- package/.docs/raw/reference/evals/faithfulness.mdx +28 -101
- package/.docs/raw/reference/evals/hallucination.mdx +28 -103
- package/.docs/raw/reference/evals/keyword-coverage.mdx +28 -107
- package/.docs/raw/reference/evals/noise-sensitivity.mdx +11 -11
- package/.docs/raw/reference/evals/prompt-alignment.mdx +15 -15
- package/.docs/raw/reference/evals/scorer-utils.mdx +362 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +27 -100
- package/.docs/raw/reference/evals/tone-consistency.mdx +25 -98
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +7 -7
- package/.docs/raw/reference/evals/toxicity.mdx +29 -92
- package/.docs/raw/reference/index.mdx +1 -0
- package/.docs/raw/reference/memory/memory-class.mdx +5 -7
- package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +150 -0
- package/.docs/raw/reference/observability/tracing/configuration.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +4 -0
- package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +17 -1
- package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +6 -0
- package/.docs/raw/reference/observability/tracing/exporters/posthog.mdx +132 -0
- 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/batch-parts-processor.mdx +1 -1
- package/.docs/raw/reference/processors/language-detector.mdx +10 -3
- package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
- package/.docs/raw/reference/processors/moderation-processor.mdx +12 -5
- package/.docs/raw/reference/processors/pii-detector.mdx +12 -5
- package/.docs/raw/reference/processors/processor-interface.mdx +502 -0
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +10 -3
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +3 -4
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +1 -1
- package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
- package/.docs/raw/reference/rag/embeddings.mdx +5 -5
- package/.docs/raw/reference/rag/rerank.mdx +1 -2
- package/.docs/raw/reference/rag/rerankWithScorer.mdx +0 -1
- 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 +64 -2
- 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/templates/overview.mdx +1 -4
- package/.docs/raw/reference/tools/client.mdx +1 -2
- package/.docs/raw/reference/tools/create-tool.mdx +132 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +5 -5
- package/.docs/raw/reference/tools/mcp-client.mdx +76 -21
- package/.docs/raw/reference/tools/mcp-server.mdx +1 -2
- package/.docs/raw/reference/tools/vector-query-tool.mdx +14 -15
- package/.docs/raw/reference/vectors/chroma.mdx +81 -1
- package/.docs/raw/reference/vectors/convex.mdx +429 -0
- package/.docs/raw/reference/vectors/couchbase.mdx +24 -17
- package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
- package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
- package/.docs/raw/reference/vectors/lance.mdx +38 -22
- package/.docs/raw/reference/vectors/libsql.mdx +35 -2
- package/.docs/raw/reference/vectors/mongodb.mdx +35 -2
- package/.docs/raw/reference/vectors/opensearch.mdx +37 -16
- package/.docs/raw/reference/vectors/pg.mdx +43 -36
- package/.docs/raw/reference/vectors/pinecone.mdx +48 -1
- package/.docs/raw/reference/vectors/qdrant.mdx +36 -1
- package/.docs/raw/reference/vectors/turbopuffer.mdx +74 -0
- package/.docs/raw/reference/voice/google.mdx +159 -20
- package/.docs/raw/reference/voice/openai-realtime.mdx +2 -2
- package/.docs/raw/reference/voice/voice.addInstructions.mdx +2 -3
- package/.docs/raw/reference/voice/voice.addTools.mdx +1 -1
- package/.docs/raw/reference/voice/voice.answer.mdx +1 -1
- package/.docs/raw/reference/voice/voice.close.mdx +1 -1
- package/.docs/raw/reference/voice/voice.connect.mdx +1 -1
- package/.docs/raw/reference/voice/voice.off.mdx +1 -1
- package/.docs/raw/reference/voice/voice.on.mdx +1 -1
- package/.docs/raw/reference/voice/voice.send.mdx +1 -1
- package/.docs/raw/reference/voice/voice.updateConfig.mdx +1 -1
- 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.mdx +13 -5
- package/.docs/raw/reference/workflows/step.mdx +13 -0
- package/.docs/raw/reference/workflows/workflow.mdx +19 -0
- package/.docs/raw/server-db/mastra-client.mdx +1 -2
- package/.docs/raw/server-db/mastra-server.mdx +30 -1
- package/.docs/raw/server-db/request-context.mdx +0 -1
- package/.docs/raw/server-db/storage.mdx +11 -0
- package/.docs/raw/streaming/overview.mdx +26 -15
- package/.docs/raw/streaming/tool-streaming.mdx +48 -5
- package/.docs/raw/streaming/workflow-streaming.mdx +5 -11
- package/.docs/raw/tools-mcp/advanced-usage.mdx +1 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +3 -5
- package/.docs/raw/voice/overview.mdx +21 -41
- package/.docs/raw/voice/speech-to-speech.mdx +4 -4
- package/.docs/raw/voice/speech-to-text.mdx +1 -2
- package/.docs/raw/voice/text-to-speech.mdx +1 -2
- package/.docs/raw/workflows/control-flow.mdx +180 -0
- 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 +18 -0
- package/dist/{chunk-5NJC7NRO.js → chunk-4CM2BQNP.js} +24 -4
- package/dist/prepare-docs/package-changes.d.ts.map +1 -1
- package/dist/prepare-docs/prepare.js +1 -1
- package/dist/stdio.js +1 -1
- package/package.json +7 -7
- package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +0 -90
- package/.docs/raw/frameworks/agentic-uis/cedar-os.mdx +0 -102
- package/.docs/raw/frameworks/agentic-uis/openrouter.mdx +0 -179
- package/.docs/raw/frameworks/web-frameworks/next-js.mdx +0 -379
- package/.docs/raw/getting-started/quickstart.mdx +0 -27
- package/.docs/raw/getting-started/templates.mdx +0 -73
- package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
- /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/assistant-ui.mdx +0 -0
- /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/copilotkit.mdx +0 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Processor Interface | Processors"
|
|
3
|
+
description: "API reference for the Processor interface in Mastra, which defines the contract for transforming, validating, and controlling messages in agent pipelines."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Processor Interface
|
|
7
|
+
|
|
8
|
+
The `Processor` interface defines the contract for all processors in Mastra. Processors can implement one or more methods to handle different stages of the agent execution pipeline.
|
|
9
|
+
|
|
10
|
+
## When processor methods run
|
|
11
|
+
|
|
12
|
+
The four processor methods run at different points in the agent execution lifecycle:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
16
|
+
│ Agent Execution Flow │
|
|
17
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
18
|
+
│ │
|
|
19
|
+
│ User Input │
|
|
20
|
+
│ │ │
|
|
21
|
+
│ ▼ │
|
|
22
|
+
│ ┌─────────────────┐ │
|
|
23
|
+
│ │ processInput │ ← Runs ONCE at start │
|
|
24
|
+
│ └────────┬────────┘ │
|
|
25
|
+
│ │ │
|
|
26
|
+
│ ▼ │
|
|
27
|
+
│ ┌─────────────────────────────────────────────────────────┐ │
|
|
28
|
+
│ │ Agentic Loop │ │
|
|
29
|
+
│ │ ┌─────────────────────┐ │ │
|
|
30
|
+
│ │ │ processInputStep │ ← Runs at EACH step │ │
|
|
31
|
+
│ │ └──────────┬──────────┘ │ │
|
|
32
|
+
│ │ │ │ │
|
|
33
|
+
│ │ ▼ │ │
|
|
34
|
+
│ │ LLM Execution │ │
|
|
35
|
+
│ │ │ │ │
|
|
36
|
+
│ │ ▼ │ │
|
|
37
|
+
│ │ ┌──────────────────────┐ │ │
|
|
38
|
+
│ │ │ processOutputStream │ ← Runs on EACH stream chunk │ │
|
|
39
|
+
│ │ └──────────┬───────────┘ │ │
|
|
40
|
+
│ │ │ │ │
|
|
41
|
+
│ │ ▼ │ │
|
|
42
|
+
│ │ Tool Execution (if needed) │ │
|
|
43
|
+
│ │ │ │ │
|
|
44
|
+
│ │ └──────── Loop back if tools called ────────│ │
|
|
45
|
+
│ └─────────────────────────────────────────────────────────┘ │
|
|
46
|
+
│ │ │
|
|
47
|
+
│ ▼ │
|
|
48
|
+
│ ┌─────────────────────┐ │
|
|
49
|
+
│ │ processOutputResult │ ← Runs ONCE after completion │
|
|
50
|
+
│ └─────────────────────┘ │
|
|
51
|
+
│ │ │
|
|
52
|
+
│ ▼ │
|
|
53
|
+
│ Final Response │
|
|
54
|
+
│ │
|
|
55
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
| Method | When it runs | Use case |
|
|
59
|
+
|--------|--------------|----------|
|
|
60
|
+
| `processInput` | Once at the start, before the agentic loop | Validate/transform initial user input, add context |
|
|
61
|
+
| `processInputStep` | At each step of the agentic loop, before each LLM call | Transform messages between steps, handle tool results |
|
|
62
|
+
| `processOutputStream` | On each streaming chunk during LLM response | Filter/modify streaming content, detect patterns in real-time |
|
|
63
|
+
| `processOutputResult` | Once after generation completes | Post-process final response, log results |
|
|
64
|
+
|
|
65
|
+
## Interface definition
|
|
66
|
+
|
|
67
|
+
```typescript copy
|
|
68
|
+
interface Processor<TId extends string = string> {
|
|
69
|
+
readonly id: TId;
|
|
70
|
+
readonly name?: string;
|
|
71
|
+
|
|
72
|
+
processInput?(args: ProcessInputArgs): Promise<ProcessInputResult> | ProcessInputResult;
|
|
73
|
+
processOutputStream?(args: ProcessOutputStreamArgs): Promise<ChunkType | null | undefined>;
|
|
74
|
+
processOutputResult?(args: ProcessOutputResultArgs): ProcessorMessageResult;
|
|
75
|
+
processInputStep?(args: ProcessInputStepArgs): ProcessorMessageResult;
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Properties
|
|
80
|
+
|
|
81
|
+
<PropertiesTable
|
|
82
|
+
content={[
|
|
83
|
+
{
|
|
84
|
+
name: "id",
|
|
85
|
+
type: "string",
|
|
86
|
+
description: "Unique identifier for the processor. Used for tracing and debugging.",
|
|
87
|
+
isOptional: false,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "name",
|
|
91
|
+
type: "string",
|
|
92
|
+
description: "Optional display name for the processor. Falls back to id if not provided.",
|
|
93
|
+
isOptional: true,
|
|
94
|
+
},
|
|
95
|
+
]}
|
|
96
|
+
/>
|
|
97
|
+
|
|
98
|
+
## Methods
|
|
99
|
+
|
|
100
|
+
### processInput
|
|
101
|
+
|
|
102
|
+
Processes input messages before they are sent to the LLM. Runs once at the start of agent execution.
|
|
103
|
+
|
|
104
|
+
```typescript copy
|
|
105
|
+
processInput?(args: ProcessInputArgs): Promise<ProcessInputResult> | ProcessInputResult;
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### ProcessInputArgs
|
|
109
|
+
|
|
110
|
+
<PropertiesTable
|
|
111
|
+
content={[
|
|
112
|
+
{
|
|
113
|
+
name: "messages",
|
|
114
|
+
type: "MastraDBMessage[]",
|
|
115
|
+
description: "User and assistant messages to process (excludes system messages).",
|
|
116
|
+
isOptional: false,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "systemMessages",
|
|
120
|
+
type: "CoreMessage[]",
|
|
121
|
+
description: "All system messages (agent instructions, memory context, user-provided). Can be modified and returned.",
|
|
122
|
+
isOptional: false,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "messageList",
|
|
126
|
+
type: "MessageList",
|
|
127
|
+
description: "Full MessageList instance for advanced message management.",
|
|
128
|
+
isOptional: false,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: "abort",
|
|
132
|
+
type: "(reason?: string) => never",
|
|
133
|
+
description: "Function to abort processing. Throws a TripWire error that stops execution.",
|
|
134
|
+
isOptional: false,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "tracingContext",
|
|
138
|
+
type: "TracingContext",
|
|
139
|
+
description: "Tracing context for observability.",
|
|
140
|
+
isOptional: true,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "requestContext",
|
|
144
|
+
type: "RequestContext",
|
|
145
|
+
description: "Request-scoped context with execution metadata like threadId and resourceId.",
|
|
146
|
+
isOptional: true,
|
|
147
|
+
},
|
|
148
|
+
]}
|
|
149
|
+
/>
|
|
150
|
+
|
|
151
|
+
#### ProcessInputResult
|
|
152
|
+
|
|
153
|
+
The method can return one of three types:
|
|
154
|
+
|
|
155
|
+
<PropertiesTable
|
|
156
|
+
content={[
|
|
157
|
+
{
|
|
158
|
+
name: "MastraDBMessage[]",
|
|
159
|
+
type: "array",
|
|
160
|
+
description: "Transformed messages array. System messages remain unchanged.",
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "MessageList",
|
|
164
|
+
type: "MessageList",
|
|
165
|
+
description: "The same messageList instance passed in. Indicates you've mutated it directly.",
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "{ messages, systemMessages }",
|
|
169
|
+
type: "object",
|
|
170
|
+
description: "Object with both transformed messages and modified system messages.",
|
|
171
|
+
},
|
|
172
|
+
]}
|
|
173
|
+
/>
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### processInputStep
|
|
178
|
+
|
|
179
|
+
Processes input messages at each step of the agentic loop, before they are sent to the LLM. Unlike `processInput` which runs once at the start, this runs at every step including tool call continuations.
|
|
180
|
+
|
|
181
|
+
```typescript copy
|
|
182
|
+
processInputStep?(args: ProcessInputStepArgs): ProcessorMessageResult;
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### Execution order in the agentic loop
|
|
186
|
+
|
|
187
|
+
1. `processInput` (once at start)
|
|
188
|
+
2. `processInputStep` (at each step, before LLM call)
|
|
189
|
+
3. `prepareStep` callback (if provided)
|
|
190
|
+
4. LLM execution
|
|
191
|
+
5. Tool execution (if needed)
|
|
192
|
+
6. Repeat from step 2 if tools were called
|
|
193
|
+
|
|
194
|
+
#### ProcessInputStepArgs
|
|
195
|
+
|
|
196
|
+
<PropertiesTable
|
|
197
|
+
content={[
|
|
198
|
+
{
|
|
199
|
+
name: "messages",
|
|
200
|
+
type: "MastraDBMessage[]",
|
|
201
|
+
description: "All messages including tool calls and results from previous steps.",
|
|
202
|
+
isOptional: false,
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "messageList",
|
|
206
|
+
type: "MessageList",
|
|
207
|
+
description: "MessageList instance for managing messages.",
|
|
208
|
+
isOptional: false,
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: "stepNumber",
|
|
212
|
+
type: "number",
|
|
213
|
+
description: "Current step number (0-indexed). Step 0 is the initial LLM call.",
|
|
214
|
+
isOptional: false,
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: "systemMessages",
|
|
218
|
+
type: "CoreMessage[]",
|
|
219
|
+
description: "All system messages for read/modify access.",
|
|
220
|
+
isOptional: false,
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: "abort",
|
|
224
|
+
type: "(reason?: string) => never",
|
|
225
|
+
description: "Function to abort processing.",
|
|
226
|
+
isOptional: false,
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: "tracingContext",
|
|
230
|
+
type: "TracingContext",
|
|
231
|
+
description: "Tracing context for observability.",
|
|
232
|
+
isOptional: true,
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
name: "requestContext",
|
|
236
|
+
type: "RequestContext",
|
|
237
|
+
description: "Request-scoped context with execution metadata.",
|
|
238
|
+
isOptional: true,
|
|
239
|
+
},
|
|
240
|
+
]}
|
|
241
|
+
/>
|
|
242
|
+
|
|
243
|
+
#### Use cases
|
|
244
|
+
|
|
245
|
+
- Transforming message part types between providers (e.g., `reasoning` → `thinking` for Anthropic)
|
|
246
|
+
- Modifying messages based on step number or accumulated context
|
|
247
|
+
- Implementing per-step message filtering or enrichment
|
|
248
|
+
- Adding step-specific context or instructions
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
### processOutputStream
|
|
253
|
+
|
|
254
|
+
Processes streaming output chunks with built-in state management. Allows processors to accumulate chunks and make decisions based on larger context.
|
|
255
|
+
|
|
256
|
+
```typescript copy
|
|
257
|
+
processOutputStream?(args: ProcessOutputStreamArgs): Promise<ChunkType | null | undefined>;
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
#### ProcessOutputStreamArgs
|
|
261
|
+
|
|
262
|
+
<PropertiesTable
|
|
263
|
+
content={[
|
|
264
|
+
{
|
|
265
|
+
name: "part",
|
|
266
|
+
type: "ChunkType",
|
|
267
|
+
description: "The current stream chunk being processed.",
|
|
268
|
+
isOptional: false,
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: "streamParts",
|
|
272
|
+
type: "ChunkType[]",
|
|
273
|
+
description: "All chunks seen so far in the stream.",
|
|
274
|
+
isOptional: false,
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
name: "state",
|
|
278
|
+
type: "Record<string, unknown>",
|
|
279
|
+
description: "Mutable state object that persists across chunks within a single stream.",
|
|
280
|
+
isOptional: false,
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: "abort",
|
|
284
|
+
type: "(reason?: string) => never",
|
|
285
|
+
description: "Function to abort the stream.",
|
|
286
|
+
isOptional: false,
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
name: "messageList",
|
|
290
|
+
type: "MessageList",
|
|
291
|
+
description: "MessageList instance for accessing conversation history.",
|
|
292
|
+
isOptional: true,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
name: "tracingContext",
|
|
296
|
+
type: "TracingContext",
|
|
297
|
+
description: "Tracing context for observability.",
|
|
298
|
+
isOptional: true,
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: "requestContext",
|
|
302
|
+
type: "RequestContext",
|
|
303
|
+
description: "Request-scoped context with execution metadata.",
|
|
304
|
+
isOptional: true,
|
|
305
|
+
},
|
|
306
|
+
]}
|
|
307
|
+
/>
|
|
308
|
+
|
|
309
|
+
#### Return value
|
|
310
|
+
|
|
311
|
+
- Return the `ChunkType` to emit it (possibly modified)
|
|
312
|
+
- Return `null` or `undefined` to skip emitting the chunk
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
### processOutputResult
|
|
317
|
+
|
|
318
|
+
Processes the complete output result after streaming or generation is finished.
|
|
319
|
+
|
|
320
|
+
```typescript copy
|
|
321
|
+
processOutputResult?(args: ProcessOutputResultArgs): ProcessorMessageResult;
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
#### ProcessOutputResultArgs
|
|
325
|
+
|
|
326
|
+
<PropertiesTable
|
|
327
|
+
content={[
|
|
328
|
+
{
|
|
329
|
+
name: "messages",
|
|
330
|
+
type: "MastraDBMessage[]",
|
|
331
|
+
description: "The generated response messages.",
|
|
332
|
+
isOptional: false,
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
name: "messageList",
|
|
336
|
+
type: "MessageList",
|
|
337
|
+
description: "MessageList instance for managing messages.",
|
|
338
|
+
isOptional: false,
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
name: "abort",
|
|
342
|
+
type: "(reason?: string) => never",
|
|
343
|
+
description: "Function to abort processing.",
|
|
344
|
+
isOptional: false,
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: "tracingContext",
|
|
348
|
+
type: "TracingContext",
|
|
349
|
+
description: "Tracing context for observability.",
|
|
350
|
+
isOptional: true,
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: "requestContext",
|
|
354
|
+
type: "RequestContext",
|
|
355
|
+
description: "Request-scoped context with execution metadata.",
|
|
356
|
+
isOptional: true,
|
|
357
|
+
},
|
|
358
|
+
]}
|
|
359
|
+
/>
|
|
360
|
+
|
|
361
|
+
## Processor types
|
|
362
|
+
|
|
363
|
+
Mastra provides type aliases to ensure processors implement the required methods:
|
|
364
|
+
|
|
365
|
+
```typescript copy
|
|
366
|
+
// Must implement processInput OR processInputStep (or both)
|
|
367
|
+
type InputProcessor = Processor & (
|
|
368
|
+
| { processInput: required }
|
|
369
|
+
| { processInputStep: required }
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
// Must implement processOutputStream OR processOutputResult (or both)
|
|
373
|
+
type OutputProcessor = Processor & (
|
|
374
|
+
| { processOutputStream: required }
|
|
375
|
+
| { processOutputResult: required }
|
|
376
|
+
);
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Usage examples
|
|
380
|
+
|
|
381
|
+
### Basic input processor
|
|
382
|
+
|
|
383
|
+
```typescript title="src/mastra/processors/lowercase.ts" showLineNumbers copy
|
|
384
|
+
import type { Processor, MastraDBMessage } from "@mastra/core";
|
|
385
|
+
|
|
386
|
+
export class LowercaseProcessor implements Processor {
|
|
387
|
+
id = "lowercase";
|
|
388
|
+
|
|
389
|
+
async processInput({ messages }): Promise<MastraDBMessage[]> {
|
|
390
|
+
return messages.map((msg) => ({
|
|
391
|
+
...msg,
|
|
392
|
+
content: {
|
|
393
|
+
...msg.content,
|
|
394
|
+
parts: msg.content.parts?.map((part) =>
|
|
395
|
+
part.type === "text"
|
|
396
|
+
? { ...part, text: part.text.toLowerCase() }
|
|
397
|
+
: part
|
|
398
|
+
),
|
|
399
|
+
},
|
|
400
|
+
}));
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### Per-step processor with processInputStep
|
|
406
|
+
|
|
407
|
+
```typescript title="src/mastra/processors/reasoning-transformer.ts" showLineNumbers copy
|
|
408
|
+
import type { Processor, MastraDBMessage } from "@mastra/core";
|
|
409
|
+
|
|
410
|
+
export class ReasoningTransformer implements Processor {
|
|
411
|
+
id = "reasoning-transformer";
|
|
412
|
+
|
|
413
|
+
async processInputStep({ messages, messageList, stepNumber }) {
|
|
414
|
+
// Transform reasoning parts to thinking parts at each step
|
|
415
|
+
// This is useful when switching between model providers
|
|
416
|
+
for (const msg of messages) {
|
|
417
|
+
if (msg.role === "assistant" && msg.content.parts) {
|
|
418
|
+
for (const part of msg.content.parts) {
|
|
419
|
+
if (part.type === "reasoning") {
|
|
420
|
+
(part as any).type = "thinking";
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return messageList;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### Hybrid processor (input and output)
|
|
431
|
+
|
|
432
|
+
```typescript title="src/mastra/processors/content-filter.ts" showLineNumbers copy
|
|
433
|
+
import type { Processor, MastraDBMessage, ChunkType } from "@mastra/core";
|
|
434
|
+
|
|
435
|
+
export class ContentFilter implements Processor {
|
|
436
|
+
id = "content-filter";
|
|
437
|
+
private blockedWords: string[];
|
|
438
|
+
|
|
439
|
+
constructor(blockedWords: string[]) {
|
|
440
|
+
this.blockedWords = blockedWords;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async processInput({ messages, abort }): Promise<MastraDBMessage[]> {
|
|
444
|
+
for (const msg of messages) {
|
|
445
|
+
const text = msg.content.parts
|
|
446
|
+
?.filter((p) => p.type === "text")
|
|
447
|
+
.map((p) => p.text)
|
|
448
|
+
.join(" ");
|
|
449
|
+
|
|
450
|
+
if (this.blockedWords.some((word) => text?.includes(word))) {
|
|
451
|
+
abort("Blocked content detected in input");
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return messages;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
async processOutputStream({ part, abort }): Promise<ChunkType | null> {
|
|
458
|
+
if (part.type === "text-delta") {
|
|
459
|
+
if (this.blockedWords.some((word) => part.textDelta.includes(word))) {
|
|
460
|
+
abort("Blocked content detected in output");
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return part;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
### Stream accumulator with state
|
|
469
|
+
|
|
470
|
+
```typescript title="src/mastra/processors/word-counter.ts" showLineNumbers copy
|
|
471
|
+
import type { Processor, ChunkType } from "@mastra/core";
|
|
472
|
+
|
|
473
|
+
export class WordCounter implements Processor {
|
|
474
|
+
id = "word-counter";
|
|
475
|
+
|
|
476
|
+
async processOutputStream({ part, state }): Promise<ChunkType> {
|
|
477
|
+
// Initialize state on first chunk
|
|
478
|
+
if (!state.wordCount) {
|
|
479
|
+
state.wordCount = 0;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// Count words in text chunks
|
|
483
|
+
if (part.type === "text-delta") {
|
|
484
|
+
const words = part.textDelta.split(/\s+/).filter(Boolean);
|
|
485
|
+
state.wordCount += words.length;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// Log word count on finish
|
|
489
|
+
if (part.type === "finish") {
|
|
490
|
+
console.log(`Total words: ${state.wordCount}`);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return part;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
## Related
|
|
499
|
+
|
|
500
|
+
- [Processors overview](/docs/v1/agents/processors) - Conceptual guide to processors
|
|
501
|
+
- [Guardrails](/docs/v1/agents/guardrails) - Security and validation processors
|
|
502
|
+
- [Memory Processors](/docs/v1/memory/memory-processors) - Memory-specific processors
|
|
@@ -13,7 +13,7 @@ The `PromptInjectionDetector` is an **input processor** that detects and prevent
|
|
|
13
13
|
import { PromptInjectionDetector } from "@mastra/core/processors";
|
|
14
14
|
|
|
15
15
|
const processor = new PromptInjectionDetector({
|
|
16
|
-
model: "openai/gpt-
|
|
16
|
+
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
17
17
|
threshold: 0.8,
|
|
18
18
|
strategy: "rewrite",
|
|
19
19
|
detectionTypes: ["injection", "jailbreak", "system-override"]
|
|
@@ -78,6 +78,13 @@ const processor = new PromptInjectionDetector({
|
|
|
78
78
|
isOptional: true,
|
|
79
79
|
default: "false",
|
|
80
80
|
},
|
|
81
|
+
{
|
|
82
|
+
name: "providerOptions",
|
|
83
|
+
type: "ProviderOptions",
|
|
84
|
+
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' } }`)",
|
|
85
|
+
isOptional: true,
|
|
86
|
+
default: "undefined",
|
|
87
|
+
},
|
|
81
88
|
]}
|
|
82
89
|
/>
|
|
83
90
|
|
|
@@ -115,10 +122,10 @@ import { PromptInjectionDetector } from "@mastra/core/processors";
|
|
|
115
122
|
export const agent = new Agent({
|
|
116
123
|
name: "secure-agent",
|
|
117
124
|
instructions: "You are a helpful assistant",
|
|
118
|
-
model: "openai/gpt-
|
|
125
|
+
model: "openai/gpt-5.1",
|
|
119
126
|
inputProcessors: [
|
|
120
127
|
new PromptInjectionDetector({
|
|
121
|
-
model: "openai/gpt-
|
|
128
|
+
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
122
129
|
detectionTypes: ['injection', 'jailbreak', 'system-override'],
|
|
123
130
|
threshold: 0.8,
|
|
124
131
|
strategy: 'rewrite',
|