@mastra/mcp-docs-server 0.0.0-studio-deploy-20260404182525 → 0.0.0-studio-cli-20260504022012
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/docs/agents/adding-voice.md +18 -17
- package/.docs/docs/agents/background-tasks.md +242 -0
- package/.docs/docs/agents/channels.md +2 -1
- package/.docs/docs/agents/overview.md +4 -0
- package/.docs/docs/agents/processors.md +177 -5
- package/.docs/docs/agents/structured-output.md +66 -1
- package/.docs/docs/agents/supervisor-agents.md +65 -0
- package/.docs/docs/agents/using-tools.md +73 -0
- package/.docs/docs/browser/agent-browser.md +78 -0
- package/.docs/docs/browser/browser-viewer.md +144 -0
- package/.docs/docs/browser/overview.md +168 -0
- package/.docs/docs/browser/stagehand.md +129 -0
- package/.docs/docs/deployment/cloud-providers.md +5 -1
- package/.docs/docs/deployment/mastra-server.md +4 -4
- package/.docs/docs/deployment/monorepo.md +3 -3
- package/.docs/docs/deployment/overview.md +11 -8
- package/.docs/docs/editor/overview.md +290 -0
- package/.docs/docs/editor/prompts.md +134 -0
- package/.docs/docs/editor/tools.md +152 -0
- package/.docs/docs/evals/custom-scorers.md +63 -3
- package/.docs/docs/evals/datasets/overview.md +1 -1
- package/.docs/docs/index.md +2 -2
- package/.docs/docs/mastra-platform/configuration.md +36 -0
- package/.docs/docs/mastra-platform/overview.md +78 -0
- package/.docs/docs/mcp/overview.md +17 -0
- package/.docs/docs/memory/memory-processors.md +3 -3
- package/.docs/docs/memory/message-history.md +8 -2
- package/.docs/docs/memory/observational-memory.md +65 -8
- package/.docs/docs/memory/storage.md +1 -2
- package/.docs/docs/memory/working-memory.md +2 -2
- package/.docs/docs/observability/logging.md +1 -1
- package/.docs/docs/observability/metrics/overview.md +2 -2
- package/.docs/docs/observability/overview.md +1 -1
- package/.docs/docs/observability/tracing/bridges/datadog.md +217 -0
- package/.docs/docs/observability/tracing/bridges/otel.md +2 -2
- package/.docs/docs/observability/tracing/exporters/arthur.md +163 -0
- package/.docs/docs/observability/tracing/exporters/cloud.md +135 -63
- package/.docs/docs/observability/tracing/exporters/datadog.md +3 -1
- package/.docs/docs/observability/tracing/exporters/default.md +5 -5
- package/.docs/docs/observability/tracing/exporters/laminar.md +22 -14
- package/.docs/docs/observability/tracing/exporters/langfuse.md +50 -33
- package/.docs/docs/observability/tracing/overview.md +87 -20
- package/.docs/docs/server/custom-adapters.md +5 -5
- package/.docs/docs/server/custom-api-routes.md +3 -3
- package/.docs/docs/server/mastra-client.md +2 -2
- package/.docs/docs/server/mastra-server.md +1 -1
- package/.docs/docs/server/middleware.md +46 -42
- package/.docs/docs/server/request-context.md +13 -2
- package/.docs/docs/server/server-adapters.md +91 -8
- package/.docs/docs/streaming/background-task-streaming.md +80 -0
- package/.docs/docs/streaming/overview.md +3 -0
- package/.docs/docs/studio/deployment.md +24 -6
- package/.docs/docs/studio/observability.md +1 -1
- package/.docs/docs/studio/overview.md +4 -4
- package/.docs/docs/voice/overview.md +74 -5
- package/.docs/docs/voice/speech-to-speech.md +45 -1
- package/.docs/docs/voice/speech-to-text.md +7 -7
- package/.docs/docs/voice/text-to-speech.md +10 -10
- package/.docs/docs/workflows/agents-and-tools.md +1 -1
- package/.docs/docs/workflows/overview.md +105 -4
- package/.docs/docs/workflows/scheduled-workflows.md +181 -0
- package/.docs/docs/workspace/filesystem.md +64 -6
- package/.docs/docs/workspace/lsp.md +76 -4
- package/.docs/docs/workspace/overview.md +62 -15
- package/.docs/docs/workspace/sandbox.md +3 -1
- package/.docs/docs/workspace/search.md +41 -2
- package/.docs/docs/workspace/skills.md +19 -19
- package/.docs/guides/agent-frameworks/ai-sdk.md +4 -4
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +56 -9
- package/.docs/guides/build-your-ui/assistant-ui.md +1 -1
- package/.docs/guides/deployment/mastra-platform.md +191 -0
- package/.docs/guides/deployment/netlify.md +16 -1
- package/.docs/guides/getting-started/nestjs.md +238 -0
- package/.docs/guides/getting-started/next-js.md +0 -4
- package/.docs/guides/guide/code-review-bot.md +2 -2
- package/.docs/guides/guide/dev-assistant.md +4 -4
- package/.docs/{docs/mcp → guides/guide}/publishing-mcp-server.md +21 -1
- package/.docs/guides/guide/slack-assistant.md +191 -0
- package/.docs/guides/migrations/mastra-cloud.md +368 -0
- package/.docs/guides/migrations/upgrade-to-v1/tracing.md +1 -1
- package/.docs/models/embeddings.md +3 -3
- package/.docs/models/gateways/azure-openai.md +74 -35
- package/.docs/models/gateways/mastra.md +64 -0
- package/.docs/models/gateways/netlify.md +7 -3
- package/.docs/models/gateways/openrouter.md +28 -12
- package/.docs/models/gateways/vercel.md +22 -2
- package/.docs/models/gateways.md +1 -0
- package/.docs/models/index.md +43 -8
- package/.docs/models/providers/302ai.md +37 -4
- package/.docs/models/providers/abliteration-ai.md +71 -0
- package/.docs/models/providers/alibaba-cn.md +8 -2
- package/.docs/models/providers/alibaba-coding-plan-cn.md +3 -2
- package/.docs/models/providers/alibaba-coding-plan.md +3 -2
- package/.docs/models/providers/alibaba.md +8 -1
- package/.docs/models/providers/anthropic.md +18 -5
- package/.docs/models/providers/baseten.md +3 -1
- package/.docs/models/providers/berget.md +10 -12
- package/.docs/models/providers/chutes.md +4 -2
- package/.docs/models/providers/cloudflare-workers-ai.md +14 -48
- package/.docs/models/providers/cortecs.md +22 -2
- package/.docs/models/providers/deepinfra.md +8 -2
- package/.docs/models/providers/deepseek.md +6 -4
- package/.docs/models/providers/digitalocean.md +133 -0
- package/.docs/models/providers/fireworks-ai.md +6 -1
- package/.docs/models/providers/firmware.md +12 -10
- package/.docs/models/providers/friendli.md +6 -7
- package/.docs/models/providers/google.md +9 -3
- package/.docs/models/providers/helicone.md +1 -2
- package/.docs/models/providers/hpc-ai.md +73 -0
- package/.docs/models/providers/huggingface.md +6 -2
- package/.docs/models/providers/inception.md +9 -11
- package/.docs/models/providers/kilo.md +359 -339
- package/.docs/models/providers/kimi-for-coding.md +2 -1
- package/.docs/models/providers/llmgateway.md +67 -77
- package/.docs/models/providers/mistral.md +3 -2
- package/.docs/models/providers/mixlayer.md +75 -0
- package/.docs/models/providers/moonshotai-cn.md +3 -2
- package/.docs/models/providers/moonshotai.md +3 -2
- package/.docs/models/providers/nano-gpt.md +8 -2
- package/.docs/models/providers/neuralwatt.md +84 -0
- package/.docs/models/providers/novita-ai.md +19 -4
- package/.docs/models/providers/nvidia.md +8 -1
- package/.docs/models/providers/ollama-cloud.md +7 -2
- package/.docs/models/providers/openai.md +7 -2
- package/.docs/models/providers/opencode-go.md +21 -13
- package/.docs/models/providers/opencode.md +11 -4
- package/.docs/models/providers/ovhcloud.md +6 -8
- package/.docs/models/providers/poe.md +10 -15
- package/.docs/models/providers/regolo-ai.md +83 -0
- package/.docs/models/providers/siliconflow-cn.md +5 -2
- package/.docs/models/providers/siliconflow.md +6 -3
- package/.docs/models/providers/stepfun.md +8 -7
- package/.docs/models/providers/synthetic.md +5 -2
- package/.docs/models/providers/tencent-token-plan.md +71 -0
- package/.docs/models/providers/tencent-tokenhub.md +71 -0
- package/.docs/models/providers/togetherai.md +8 -7
- package/.docs/models/providers/vivgrid.md +7 -3
- package/.docs/models/providers/vultr.md +7 -6
- package/.docs/models/providers/wafer.ai.md +73 -0
- package/.docs/models/providers/wandb.md +3 -2
- package/.docs/models/providers/xai.md +6 -1
- package/.docs/models/providers/xiaomi-token-plan-ams.md +75 -0
- package/.docs/models/providers/xiaomi-token-plan-cn.md +75 -0
- package/.docs/models/providers/xiaomi-token-plan-sgp.md +75 -0
- package/.docs/models/providers/xiaomi.md +4 -2
- package/.docs/models/providers/zai-coding-plan.md +11 -19
- package/.docs/models/providers/zai.md +2 -1
- package/.docs/models/providers/zenmux.md +17 -6
- package/.docs/models/providers/zhipuai-coding-plan.md +11 -21
- package/.docs/models/providers/zhipuai.md +2 -1
- package/.docs/models/providers.md +11 -0
- package/.docs/reference/agents/agent.md +1 -1
- package/.docs/reference/agents/channels.md +3 -3
- package/.docs/reference/agents/generate.md +88 -6
- package/.docs/reference/agents/generateLegacy.md +1 -1
- package/.docs/reference/ai-sdk/chat-route.md +2 -0
- package/.docs/reference/ai-sdk/handle-chat-stream.md +19 -0
- package/.docs/reference/ai-sdk/handle-network-stream.md +2 -0
- package/.docs/reference/ai-sdk/network-route.md +2 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-messages.md +95 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +15 -0
- package/.docs/reference/browser/agent-browser.md +375 -0
- package/.docs/reference/browser/browser-viewer.md +228 -0
- package/.docs/reference/browser/mastra-browser.md +286 -0
- package/.docs/reference/browser/stagehand-browser.md +286 -0
- package/.docs/reference/cli/mastra.md +703 -0
- package/.docs/reference/client-js/agents.md +166 -0
- package/.docs/reference/client-js/conversations.md +1 -1
- package/.docs/reference/client-js/mastra-client.md +23 -0
- package/.docs/reference/client-js/observability.md +2 -2
- package/.docs/reference/client-js/responses.md +1 -1
- package/.docs/reference/client-js/workflows.md +62 -1
- package/.docs/reference/configuration.md +67 -1
- package/.docs/reference/core/addGateway.md +5 -5
- package/.docs/reference/core/getEditor.md +35 -0
- package/.docs/reference/core/getGateway.md +5 -5
- package/.docs/reference/core/getGatewayById.md +5 -5
- package/.docs/reference/core/getMCPServer.md +2 -2
- package/.docs/reference/core/getMCPServerById.md +2 -2
- package/.docs/reference/core/getScorer.md +3 -3
- package/.docs/reference/core/getScorerById.md +3 -3
- package/.docs/reference/core/listGateways.md +5 -5
- package/.docs/reference/core/listMCPServers.md +2 -2
- package/.docs/reference/core/listScorers.md +3 -3
- package/.docs/reference/core/mastra-class.md +11 -1
- package/.docs/reference/core/mastra-model-gateway.md +5 -5
- package/.docs/reference/datasets/create.md +4 -4
- package/.docs/reference/datasets/startExperiment.md +28 -2
- package/.docs/reference/datasets/update.md +4 -4
- package/.docs/reference/deployer/cloudflare.md +14 -1
- package/.docs/reference/deployer/netlify.md +50 -2
- package/.docs/reference/editor/mastra-editor.md +168 -0
- package/.docs/reference/editor/tool-provider.md +85 -0
- package/.docs/reference/evals/context-precision.md +3 -3
- package/.docs/reference/evals/context-relevance.md +3 -3
- package/.docs/reference/evals/create-scorer.md +5 -3
- package/.docs/reference/evals/filter-run.md +117 -0
- package/.docs/reference/evals/mastra-scorer.md +4 -4
- package/.docs/reference/evals/noise-sensitivity.md +6 -6
- package/.docs/reference/evals/prompt-alignment.md +12 -12
- package/.docs/reference/evals/run-evals.md +6 -6
- package/.docs/reference/evals/scorer-utils.md +3 -3
- package/.docs/reference/evals/trajectory-accuracy.md +3 -3
- package/.docs/reference/harness/harness-class.md +152 -53
- package/.docs/reference/index.md +25 -0
- package/.docs/reference/logging/pino-logger.md +0 -2
- package/.docs/reference/mastra-platform/api.md +108 -0
- package/.docs/reference/memory/clone-utilities.md +4 -2
- package/.docs/reference/memory/cloneThread.md +4 -2
- package/.docs/reference/memory/observational-memory.md +4 -0
- package/.docs/reference/observability/metrics/automatic-metrics.md +3 -3
- package/.docs/reference/observability/tracing/bridges/datadog.md +211 -0
- package/.docs/reference/observability/tracing/bridges/otel.md +3 -3
- package/.docs/reference/observability/tracing/configuration.md +18 -11
- package/.docs/reference/observability/tracing/exporters/arthur.md +122 -0
- package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +102 -21
- package/.docs/reference/observability/tracing/exporters/console-exporter.md +8 -8
- package/.docs/reference/observability/tracing/exporters/datadog.md +3 -1
- package/.docs/reference/observability/tracing/exporters/default-exporter.md +8 -8
- package/.docs/reference/observability/tracing/exporters/langfuse.md +25 -32
- package/.docs/reference/observability/tracing/exporters/otel.md +3 -3
- package/.docs/reference/observability/tracing/instances.md +7 -7
- package/.docs/reference/observability/tracing/interfaces.md +23 -6
- package/.docs/reference/observability/tracing/span-filtering.md +95 -0
- package/.docs/reference/observability/tracing/spans.md +6 -6
- package/.docs/reference/processors/prefill-error-handler.md +70 -0
- package/.docs/reference/processors/processor-interface.md +400 -40
- package/.docs/reference/processors/skill-search-processor.md +20 -1
- package/.docs/reference/processors/stream-error-retry-processor.md +54 -0
- package/.docs/reference/processors/tool-call-filter.md +23 -0
- package/.docs/reference/server/create-route.md +3 -3
- package/.docs/reference/server/express-adapter.md +4 -4
- package/.docs/reference/server/fastify-adapter.md +4 -4
- package/.docs/reference/server/hono-adapter.md +4 -4
- package/.docs/reference/server/koa-adapter.md +4 -4
- package/.docs/reference/server/mastra-server.md +3 -3
- package/.docs/reference/server/nestjs-adapter.md +169 -0
- package/.docs/reference/server/register-api-route.md +4 -4
- package/.docs/reference/server/routes.md +11 -10
- package/.docs/reference/storage/clickhouse.md +300 -0
- package/.docs/reference/storage/cloudflare-d1.md +42 -42
- package/.docs/reference/storage/composite.md +5 -3
- package/.docs/reference/storage/duckdb.md +150 -0
- package/.docs/reference/storage/overview.md +1 -1
- package/.docs/reference/storage/redis.md +266 -0
- package/.docs/reference/streaming/ChunkType.md +143 -3
- package/.docs/reference/streaming/agents/MastraModelOutput.md +2 -2
- package/.docs/reference/streaming/agents/stream.md +10 -2
- package/.docs/reference/streaming/agents/streamUntilIdle.md +94 -0
- package/.docs/reference/streaming/workflows/resumeStream.md +2 -0
- package/.docs/reference/templates/overview.md +88 -14
- package/.docs/reference/tools/create-tool.md +107 -5
- package/.docs/reference/tools/mcp-client.md +45 -0
- package/.docs/reference/tools/mcp-server.md +1 -3
- package/.docs/reference/tools/perplexity.md +155 -0
- package/.docs/reference/tools/tavily.md +307 -0
- package/.docs/reference/vectors/mongodb.md +0 -2
- package/.docs/reference/voice/aws-nova-sonic.md +247 -0
- package/.docs/reference/voice/cloudflare.md +3 -3
- package/.docs/reference/voice/sarvam.md +29 -23
- package/.docs/reference/voice/voice.connect.md +4 -4
- package/.docs/reference/voice/voice.listen.md +3 -3
- package/.docs/reference/workflows/run-methods/resume.md +24 -0
- package/.docs/reference/workflows/run-methods/startAsync.md +1 -1
- package/.docs/reference/workflows/step.md +88 -7
- package/.docs/reference/workflows/workflow-methods/foreach.md +14 -1
- package/.docs/reference/workflows/workflow.md +88 -4
- package/.docs/reference/workspace/azure-blob-filesystem.md +219 -0
- package/.docs/reference/workspace/docker-sandbox.md +196 -0
- package/.docs/reference/workspace/gcs-filesystem.md +1 -0
- package/.docs/reference/workspace/google-drive-filesystem.md +185 -0
- package/.docs/reference/workspace/modal-sandbox.md +168 -0
- package/.docs/reference/workspace/process-manager.md +1 -1
- package/.docs/reference/workspace/s3-filesystem.md +80 -5
- package/.docs/reference/workspace/vercel.md +1 -1
- package/.docs/reference/workspace/workspace-class.md +37 -6
- package/CHANGELOG.md +500 -4
- package/dist/stdio.js.map +1 -1
- package/dist/utils.d.ts +1 -4
- package/dist/utils.d.ts.map +1 -1
- package/package.json +11 -11
- package/.docs/docs/mastra-cloud/deployment.md +0 -77
- package/.docs/docs/mastra-cloud/observability.md +0 -38
- package/.docs/docs/mastra-cloud/overview.md +0 -23
- package/.docs/docs/mastra-cloud/setup.md +0 -42
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# Integrate Mastra in Your NestJS Project
|
|
2
|
+
|
|
3
|
+
In this guide, you'll build a tool-calling AI agent using Mastra and NestJS. The [NestJS server adapter](https://mastra.ai/reference/server/nestjs-adapter) registers Mastra's agent and workflow routes as a NestJS module, so they run inside your existing NestJS application.
|
|
4
|
+
|
|
5
|
+
## Before you begin
|
|
6
|
+
|
|
7
|
+
- You'll need an API key from a supported [model provider](https://mastra.ai/models). If you don't have a preference, use [OpenAI](https://mastra.ai/models/providers/openai).
|
|
8
|
+
- Install Node.js `v22.13.0` or later
|
|
9
|
+
- Use the NestJS Express platform (`@nestjs/platform-express`)
|
|
10
|
+
|
|
11
|
+
## Create a new NestJS app (optional)
|
|
12
|
+
|
|
13
|
+
If you already have a NestJS app, skip to the next step.
|
|
14
|
+
|
|
15
|
+
Run the following command to create a new NestJS app:
|
|
16
|
+
|
|
17
|
+
**npm**:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx @nestjs/cli new mastra-nest
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**pnpm**:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm dlx @nestjs/cli new mastra-nest
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Yarn**:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn dlx @nestjs/cli new mastra-nest
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Bun**:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
bun x @nestjs/cli new mastra-nest
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This creates a project called `mastra-nest`, but you can replace it with any name you want.
|
|
42
|
+
|
|
43
|
+
## Initialize Mastra
|
|
44
|
+
|
|
45
|
+
Navigate to your NestJS project directory:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
cd mastra-nest
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Run [`mastra init`](https://mastra.ai/reference/cli/mastra). When prompted, choose a provider (e.g. OpenAI) and enter your key:
|
|
52
|
+
|
|
53
|
+
**npm**:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx mastra@latest init
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**pnpm**:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm dlx mastra@latest init
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Yarn**:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
yarn dlx mastra@latest init
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Bun**:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
bun x mastra@latest init
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This creates a `src/mastra` folder with an example weather agent and the following files:
|
|
78
|
+
|
|
79
|
+
- `index.ts` - Mastra config, including memory
|
|
80
|
+
- `tools/weather-tool.ts` - a tool to fetch weather for a given location
|
|
81
|
+
- `agents/weather-agent.ts` - a weather agent with a prompt that uses the tool
|
|
82
|
+
|
|
83
|
+
You'll pass the `src/mastra/index.ts` file to the NestJS adapter in the next step.
|
|
84
|
+
|
|
85
|
+
## Add server adapter
|
|
86
|
+
|
|
87
|
+
Install the NestJS server adapter package:
|
|
88
|
+
|
|
89
|
+
**npm**:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npm install @mastra/nestjs@latest
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**pnpm**:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pnpm add @mastra/nestjs@latest
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Yarn**:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
yarn add @mastra/nestjs@latest
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Bun**:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
bun add @mastra/nestjs@latest
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Open `src/app.module.ts` and register `MastraModule`:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { Module } from '@nestjs/common'
|
|
117
|
+
import { MastraModule } from '@mastra/nestjs'
|
|
118
|
+
import { mastra } from './mastra'
|
|
119
|
+
|
|
120
|
+
@Module({
|
|
121
|
+
imports: [
|
|
122
|
+
MastraModule.register({
|
|
123
|
+
mastra,
|
|
124
|
+
}),
|
|
125
|
+
],
|
|
126
|
+
})
|
|
127
|
+
export class AppModule {}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
> **Note:** `MastraModule` registers a catch-all controller (`@All('*')`). If it is imported before your app modules, it can intercept unrelated routes and return 404s. To avoid conflicts, import `MastraModule` last or mount it under a dedicated prefix (e.g., `/api/v1/mastra`).
|
|
131
|
+
|
|
132
|
+
## Test your agent
|
|
133
|
+
|
|
134
|
+
By default, Mastra's endpoints are added under the `/api` subpath and use your agent/workflow IDs. The default `weather-agent` created by `mastra init` is available at `/api/agents/weather-agent`.
|
|
135
|
+
|
|
136
|
+
Start your NestJS server:
|
|
137
|
+
|
|
138
|
+
**npm**:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
npm run start
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**pnpm**:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
pnpm run start
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Yarn**:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
yarn run start
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Bun**:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
bun run start
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
In a separate terminal window, use `curl` to ask the weather agent:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
curl -X POST http://localhost:3000/api/agents/weather-agent/generate -H "Content-Type: application/json" -d "{\"messages\":[{\"role\":\"user\",\"content\":\"What is the weather like in Seoul?\"}]}"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Use Mastra in Your Own Services
|
|
169
|
+
|
|
170
|
+
The module exports two ways to access Mastra from your NestJS services: the `MastraService` wrapper and the `MASTRA` injection token.
|
|
171
|
+
|
|
172
|
+
### MastraService
|
|
173
|
+
|
|
174
|
+
`MastraService` is an injectable wrapper with convenience methods for common operations:
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import { Injectable } from '@nestjs/common'
|
|
178
|
+
import { MastraService } from '@mastra/nestjs'
|
|
179
|
+
|
|
180
|
+
@Injectable()
|
|
181
|
+
export class AgentService {
|
|
182
|
+
constructor(private readonly mastraService: MastraService) {}
|
|
183
|
+
|
|
184
|
+
async chat(agentId: string, message: string) {
|
|
185
|
+
const agent = this.mastraService.getAgent(agentId)
|
|
186
|
+
return agent.generate({
|
|
187
|
+
messages: [{ role: 'user', content: message }],
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async runWorkflow(workflowId: string, input: Record<string, unknown>) {
|
|
192
|
+
const workflow = this.mastraService.getWorkflow(workflowId)
|
|
193
|
+
return workflow.start({ inputData: input })
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`MastraService` exposes:
|
|
199
|
+
|
|
200
|
+
- `getMastra()` — returns the underlying `Mastra` instance
|
|
201
|
+
- `getAgent(id)` — shorthand for `mastra.getAgent(id)`
|
|
202
|
+
- `getWorkflow(id)` — shorthand for `mastra.getWorkflow(id)`
|
|
203
|
+
- `getOptions()` — returns the module configuration
|
|
204
|
+
- `isShuttingDown` — `true` after graceful shutdown begins
|
|
205
|
+
|
|
206
|
+
### MASTRA token
|
|
207
|
+
|
|
208
|
+
If you need the `Mastra` instance directly (e.g., to access storage, memory, or other core APIs), inject it with the `MASTRA` token:
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
import { Injectable, Inject } from '@nestjs/common'
|
|
212
|
+
import { MASTRA } from '@mastra/nestjs'
|
|
213
|
+
import type { Mastra } from '@mastra/core/mastra'
|
|
214
|
+
|
|
215
|
+
@Injectable()
|
|
216
|
+
export class MemoryService {
|
|
217
|
+
constructor(@Inject(MASTRA) private readonly mastra: Mastra) {}
|
|
218
|
+
|
|
219
|
+
async getThreadMessages(threadId: string) {
|
|
220
|
+
const memory = this.mastra.getMemory()
|
|
221
|
+
return memory?.getMessages({ threadId })
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Both approaches use the same singleton `Mastra` instance registered by `MastraModule`.
|
|
227
|
+
|
|
228
|
+
## Next steps
|
|
229
|
+
|
|
230
|
+
You now have a working Mastra agent running inside NestJS. To extend the project:
|
|
231
|
+
|
|
232
|
+
- [Agents overview](https://mastra.ai/docs/agents/overview)
|
|
233
|
+
- [Using tools](https://mastra.ai/docs/agents/using-tools)
|
|
234
|
+
- [Agent memory](https://mastra.ai/docs/memory/overview)
|
|
235
|
+
|
|
236
|
+
For details on the NestJS integration:
|
|
237
|
+
|
|
238
|
+
- [NestJS Adapter reference](https://mastra.ai/reference/server/nestjs-adapter)
|
|
@@ -4,10 +4,6 @@ In this guide, you'll build a tool-calling AI agent using Mastra, then connect i
|
|
|
4
4
|
|
|
5
5
|
You'll use [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) and [AI Elements](https://ai-sdk.dev/elements) to create a beautiful, interactive chat experience.
|
|
6
6
|
|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
What you'll build: an agent that can call a weather tool, display the JSON result, stream a weather summary in the chat UI, and persist conversation history across reloads.
|
|
10
|
-
|
|
11
7
|
## Before you begin
|
|
12
8
|
|
|
13
9
|
- You'll need an API key from a supported [model provider](https://mastra.ai/models). If you don't have a preference, use [OpenAI](https://mastra.ai/models/providers/openai).
|
|
@@ -21,7 +21,7 @@ const workspace = new Workspace({
|
|
|
21
21
|
filesystem: new LocalFilesystem({
|
|
22
22
|
basePath: resolve(import.meta.dirname, '../../workspace'),
|
|
23
23
|
}),
|
|
24
|
-
skills: ['
|
|
24
|
+
skills: ['skills'],
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
export const mastra = new Mastra({
|
|
@@ -138,7 +138,7 @@ const workspace = new Workspace({
|
|
|
138
138
|
filesystem: new LocalFilesystem({
|
|
139
139
|
basePath: resolve(import.meta.dirname, '../../workspace'),
|
|
140
140
|
}),
|
|
141
|
-
skills: ['
|
|
141
|
+
skills: ['skills'],
|
|
142
142
|
})
|
|
143
143
|
|
|
144
144
|
export const mastra = new Mastra({
|
|
@@ -57,9 +57,9 @@ import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace
|
|
|
57
57
|
const workspace = new Workspace({
|
|
58
58
|
filesystem: new LocalFilesystem({ basePath: resolve(import.meta.dirname, '../../workspace') }),
|
|
59
59
|
sandbox: new LocalSandbox({ workingDirectory: resolve(import.meta.dirname, '../../workspace') }),
|
|
60
|
-
skills: ['
|
|
60
|
+
skills: ['skills'],
|
|
61
61
|
bm25: true,
|
|
62
|
-
autoIndexPaths: ['
|
|
62
|
+
autoIndexPaths: ['docs', 'src'],
|
|
63
63
|
})
|
|
64
64
|
|
|
65
65
|
export const mastra = new Mastra({
|
|
@@ -210,9 +210,9 @@ import { devAssistant } from './agents/dev-assistant'
|
|
|
210
210
|
const workspace = new Workspace({
|
|
211
211
|
filesystem: new LocalFilesystem({ basePath: resolve(import.meta.dirname, '../../workspace') }),
|
|
212
212
|
sandbox: new LocalSandbox({ workingDirectory: resolve(import.meta.dirname, '../../workspace') }),
|
|
213
|
-
skills: ['
|
|
213
|
+
skills: ['skills'],
|
|
214
214
|
bm25: true,
|
|
215
|
-
autoIndexPaths: ['
|
|
215
|
+
autoIndexPaths: ['docs', 'src'],
|
|
216
216
|
})
|
|
217
217
|
|
|
218
218
|
export const mastra = new Mastra({
|
|
@@ -32,7 +32,7 @@ bun add @mastra/mcp @mastra/core tsup
|
|
|
32
32
|
|
|
33
33
|
## Setting up an MCP server
|
|
34
34
|
|
|
35
|
-
1. Create a file for your stdio server, for example,
|
|
35
|
+
1. Create a file for your stdio server, for example, `src/mastra/stdio.ts`.
|
|
36
36
|
|
|
37
37
|
2. Add the following code to the file. Remember to import your actual Mastra tools and name the server appropriately.
|
|
38
38
|
|
|
@@ -68,10 +68,30 @@ bun add @mastra/mcp @mastra/core tsup
|
|
|
68
68
|
|
|
69
69
|
4. Run the build command:
|
|
70
70
|
|
|
71
|
+
**npm**:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm run build:mcp
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**pnpm**:
|
|
78
|
+
|
|
71
79
|
```bash
|
|
72
80
|
pnpm run build:mcp
|
|
73
81
|
```
|
|
74
82
|
|
|
83
|
+
**Yarn**:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
yarn build:mcp
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Bun**:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
bun run build:mcp
|
|
93
|
+
```
|
|
94
|
+
|
|
75
95
|
This will compile your server code into both ESM and CJS formats and make the ESM output file executable. On Unix-like systems, the `chmod +x` step makes the file directly executable. Windows users may need to use WSL or handle execution through Node.js directly.
|
|
76
96
|
|
|
77
97
|
## Publishing to NPM
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Building a Slack assistant
|
|
2
|
+
|
|
3
|
+
In this guide, you'll build a Mastra agent that responds to messages and mentions on Slack. You'll learn how to configure a channel adapter, set up a Slack app with the right permissions, connect it to your agent via a webhook, and test the interaction.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js `v22.13.0` or later installed
|
|
8
|
+
- An API key from a supported [Model Provider](https://mastra.ai/models)
|
|
9
|
+
- An existing Mastra project. Follow the [installation guide](https://mastra.ai/guides/getting-started/quickstart) if needed.
|
|
10
|
+
- A [Slack workspace](https://slack.com/) where you can create apps
|
|
11
|
+
|
|
12
|
+
## Create the agent
|
|
13
|
+
|
|
14
|
+
Install the Slack adapter:
|
|
15
|
+
|
|
16
|
+
**npm**:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @chat-adapter/slack
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**pnpm**:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add @chat-adapter/slack
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Yarn**:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
yarn add @chat-adapter/slack
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Bun**:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
bun add @chat-adapter/slack
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Create a new file `src/mastra/agents/slack-agent.ts` and define your agent:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { Agent } from '@mastra/core/agent'
|
|
44
|
+
import { createSlackAdapter } from '@chat-adapter/slack'
|
|
45
|
+
|
|
46
|
+
export const slackAgent = new Agent({
|
|
47
|
+
id: 'slack-agent',
|
|
48
|
+
name: 'Slack Agent',
|
|
49
|
+
instructions:
|
|
50
|
+
'You are a helpful assistant. Answer questions, help with tasks, and have natural conversations.',
|
|
51
|
+
model: 'anthropic/claude-opus-4-6',
|
|
52
|
+
channels: {
|
|
53
|
+
adapters: {
|
|
54
|
+
slack: createSlackAdapter(),
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The `channels` property tells Mastra to generate a webhook endpoint for each adapter. In this case, the Slack adapter handles event verification, signature validation, and message formatting automatically.
|
|
61
|
+
|
|
62
|
+
Register the agent in your `src/mastra/index.ts` file:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { Mastra } from '@mastra/core'
|
|
66
|
+
import { slackAgent } from './agents/slack-agent'
|
|
67
|
+
|
|
68
|
+
export const mastra = new Mastra({
|
|
69
|
+
agents: { slackAgent },
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Create a Slack app
|
|
74
|
+
|
|
75
|
+
You need a Slack app to connect your agent to a workspace.
|
|
76
|
+
|
|
77
|
+
Go to <https://api.slack.com/apps> and select **Create New App** > **From scratch**. Give it a name and select your workspace.
|
|
78
|
+
|
|
79
|
+
Navigate to **OAuth & Permissions** and scroll to **Bot Token Scopes**. Add the following scopes:
|
|
80
|
+
|
|
81
|
+
- `app_mentions:read`
|
|
82
|
+
- `channels:history`
|
|
83
|
+
- `channels:read`
|
|
84
|
+
- `chat:write`
|
|
85
|
+
- `users:read`
|
|
86
|
+
|
|
87
|
+
At the top of **OAuth & Permissions**, select **Install to Workspace**. Copy the **Bot User OAuth Token** (`xoxb-...`).
|
|
88
|
+
|
|
89
|
+
Go to **Basic Information** > **App Credentials** and copy the **Signing Secret** (e.g. `c3a4...`).
|
|
90
|
+
|
|
91
|
+
Ensure **Socket Mode** is turned **off** under **Settings** > **Socket Mode**.
|
|
92
|
+
|
|
93
|
+
Add the credentials to your `.env` file:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
SLACK_SIGNING_SECRET=your-signing-secret
|
|
97
|
+
SLACK_BOT_TOKEN=xoxb-your-bot-token
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The adapter reads these environment variables by default. See the [Chat SDK Slack adapter docs](https://chat-sdk.dev/adapters/slack) for more details.
|
|
101
|
+
|
|
102
|
+
## Connect the webhook
|
|
103
|
+
|
|
104
|
+
Slack delivers events to your agent via a webhook. Mastra generates this endpoint automatically for each channel adapter.
|
|
105
|
+
|
|
106
|
+
Start the dev server:
|
|
107
|
+
|
|
108
|
+
**npm**:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm run dev
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**pnpm**:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pnpm run dev
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Yarn**:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
yarn dev
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Bun**:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
bun run dev
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
During local development, Slack needs a public URL to reach your local server. Open a new terminal and start a tunnel:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npx cloudflared tunnel --url http://localhost:4111
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
This outputs a temporary public URL like `https://triple-arms-solutions-kit.trycloudflare.com`. The URL changes each time you restart the tunnel.
|
|
139
|
+
|
|
140
|
+
In your Slack app settings, go to **Event Subscriptions** and toggle **Enable Events** to **On**.
|
|
141
|
+
|
|
142
|
+
Set the **Request URL** to your tunnel URL with the agent webhook path:
|
|
143
|
+
|
|
144
|
+
```text
|
|
145
|
+
https://<your-tunnel-url>/api/agents/slack-agent/channels/slack/webhook
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Slack sends a verification request. If your dev server is running, it responds with a green checkmark.
|
|
149
|
+
|
|
150
|
+
Under **Subscribe to bot events**, add:
|
|
151
|
+
|
|
152
|
+
- `app_mention`
|
|
153
|
+
- `message.channels`
|
|
154
|
+
|
|
155
|
+
Select **Save Changes**. Slack requires you to reinstall the app after changing event subscriptions. Go to **OAuth & Permissions** and select **Reinstall to Workspace** to apply the updated permissions.
|
|
156
|
+
|
|
157
|
+
> **Note:** The tunnel URL is for local development only. When you [deploy your application](https://mastra.ai/docs/deployment/overview), update the **Request URL** in your Slack app's **Event Subscriptions** to your production URL (e.g. `https://your-app.example.com/api/agents/slack-agent/channels/slack/webhook`).
|
|
158
|
+
|
|
159
|
+
## Test the agent
|
|
160
|
+
|
|
161
|
+
Before testing with Slack, you can refine your agent's behavior in [Studio](https://mastra.ai/docs/studio/overview). Open <http://localhost:4111/> to chat with your agent directly, adjust its instructions, and inspect traces to see how responses are generated.
|
|
162
|
+
|
|
163
|
+
Once you're happy with the agent's responses, test the Slack integration. Invite the bot to a channel in Slack:
|
|
164
|
+
|
|
165
|
+
```text
|
|
166
|
+
/invite @your-bot-name
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Mention the bot in the channel:
|
|
170
|
+
|
|
171
|
+
```text
|
|
172
|
+
@your-bot-name What can you help me with?
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The agent responds in the thread. Output may vary depending on the model and instructions.
|
|
176
|
+
|
|
177
|
+
## Next steps
|
|
178
|
+
|
|
179
|
+
You can extend this agent to:
|
|
180
|
+
|
|
181
|
+
- [Deploy your application](https://mastra.ai/docs/deployment/overview) and update the Slack **Request URL** to your production endpoint
|
|
182
|
+
- Add more adapters (Discord, Telegram) to the same agent so it responds on multiple platforms
|
|
183
|
+
- Configure [multimodal content](https://mastra.ai/docs/agents/channels) to let your agent process images, video, and audio shared in chat
|
|
184
|
+
- Add [tools](https://mastra.ai/docs/agents/using-tools) to give the agent access to external APIs and data
|
|
185
|
+
|
|
186
|
+
Learn more:
|
|
187
|
+
|
|
188
|
+
- [Channels overview](https://mastra.ai/docs/agents/channels)
|
|
189
|
+
- [Studio](https://mastra.ai/docs/studio/overview)
|
|
190
|
+
- [Deployment overview](https://mastra.ai/docs/deployment/overview)
|
|
191
|
+
- [Chat SDK adapter docs](https://chat-sdk.dev)
|