@mastra/mcp-docs-server 1.2.7-alpha.12 → 1.2.7-alpha.4
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/agent-builder/integrations.md +2 -44
- package/.docs/docs/agent-builder/overview.md +3 -4
- package/.docs/docs/agent-builder/skill-registries.md +3 -1
- package/.docs/docs/agent-controller/overview.md +2 -3
- package/.docs/docs/agent-controller/session.md +3 -1
- package/.docs/docs/agents/a2a.md +1 -2
- package/.docs/docs/agents/channels.md +225 -0
- package/.docs/docs/agents/code-mode.md +1 -1
- package/.docs/docs/agents/file-based-agents.md +297 -0
- package/.docs/docs/agents/guardrails.md +9 -10
- package/.docs/docs/agents/overview.md +4 -4
- package/.docs/docs/agents/skills.md +5 -3
- package/.docs/docs/agents/structured-output.md +1 -1
- package/.docs/docs/agents/supervisor-agents.md +4 -3
- package/.docs/docs/agents/using-tools.md +4 -2
- package/.docs/docs/browser/agent-browser.md +3 -1
- package/.docs/docs/browser/browser-viewer.md +3 -1
- package/.docs/docs/browser/overview.md +1 -2
- package/.docs/docs/browser/stagehand.md +1 -1
- package/.docs/docs/deployment/mastra-server.md +4 -2
- package/.docs/docs/editor/overview.md +6 -2
- package/.docs/docs/editor/prompts.md +1 -1
- package/.docs/docs/editor/tools.md +5 -3
- package/.docs/docs/evals/custom-scorers.md +3 -1
- package/.docs/docs/evals/datasets/overview.md +5 -4
- package/.docs/docs/evals/datasets/running-experiments.md +2 -4
- package/.docs/docs/evals/evals-with-memory.md +3 -1
- package/.docs/docs/evals/gates-and-verdicts.md +3 -1
- package/.docs/docs/evals/overview.md +1 -4
- package/.docs/docs/evals/quick-checks.md +3 -1
- package/.docs/docs/long-running-agents/background-tasks.md +1 -1
- package/.docs/docs/long-running-agents/durable-agents.md +5 -3
- package/.docs/docs/long-running-agents/goals.md +3 -1
- package/.docs/docs/long-running-agents/signal-providers.md +3 -1
- package/.docs/docs/long-running-agents/signals.md +22 -11
- package/.docs/docs/mastra-platform/observability.md +1 -5
- package/.docs/docs/mcp/mcp-apps.md +3 -3
- package/.docs/docs/mcp/overview.md +10 -6
- package/.docs/docs/memory/observational-memory.md +1 -2
- package/.docs/docs/memory/overview.md +4 -6
- package/.docs/docs/memory/semantic-recall.md +1 -1
- package/.docs/docs/memory/working-memory.md +3 -3
- package/.docs/docs/observability/integrations/exporters/mastra-platform.md +3 -1
- package/.docs/docs/observability/logging.md +1 -1
- package/.docs/docs/observability/tracing/overview.md +1 -1
- package/.docs/docs/server/auth/auth0.md +1 -1
- package/.docs/docs/server/auth/better-auth.md +2 -2
- package/.docs/docs/server/auth/clerk.md +1 -1
- package/.docs/docs/server/auth/firebase.md +1 -1
- package/.docs/docs/server/auth/google.md +2 -2
- package/.docs/docs/server/auth/jwt.md +2 -2
- package/.docs/docs/server/auth/okta.md +2 -2
- package/.docs/docs/server/auth/workos.md +1 -1
- package/.docs/docs/server/mastra-client.md +1 -1
- package/.docs/docs/server/mastra-server.md +1 -1
- package/.docs/docs/server/pubsub.md +1 -1
- package/.docs/docs/server/request-context.md +4 -4
- package/.docs/docs/server/server-adapters.md +8 -8
- package/.docs/docs/studio/auth.md +3 -1
- package/.docs/docs/studio/overview.md +1 -1
- package/.docs/docs/workflows/agents-and-tools.md +5 -3
- package/.docs/docs/workflows/control-flow.md +3 -1
- package/.docs/docs/workflows/overview.md +7 -6
- package/.docs/docs/workspace/overview.md +1 -2
- package/.docs/docs/workspace/sandbox.md +0 -2
- package/.docs/guides/build-your-ui/assistant-ui.md +1 -1
- package/.docs/guides/build-your-ui/copilotkit/overview.md +1 -1
- package/.docs/guides/concepts/streaming.md +3 -3
- package/.docs/guides/getting-started/quickstart.md +1 -3
- package/.docs/guides/guide/chef-michel.md +2 -0
- package/.docs/guides/guide/slack-assistant.md +2 -2
- package/.docs/guides/guide/stock-agent.md +2 -0
- package/.docs/models/environment-variables.md +0 -6
- package/.docs/models/gateways/netlify.md +1 -4
- package/.docs/models/gateways/openrouter.md +7 -8
- package/.docs/models/gateways/vercel.md +1 -6
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/abacus.md +14 -44
- package/.docs/models/providers/llmgateway.md +181 -185
- package/.docs/models/providers/nano-gpt.md +2 -2
- package/.docs/models/providers/neon.md +29 -40
- package/.docs/models/providers/nvidia.md +3 -1
- package/.docs/models/providers/openai.md +1 -6
- package/.docs/models/providers/opencode.md +2 -5
- package/.docs/models/providers/poolside.md +5 -6
- package/.docs/models/providers/routing-run.md +34 -23
- package/.docs/models/providers/the-grid-ai.md +3 -3
- package/.docs/models/providers.md +0 -6
- package/.docs/reference/agents/channels.md +2 -2
- package/.docs/reference/channels/channel-provider.md +1 -1
- package/.docs/reference/channels/slack-provider.md +2 -2
- package/.docs/reference/cli/mastra.md +10 -117
- package/.docs/reference/evals/create-scorer.md +0 -8
- package/.docs/reference/index.md +0 -15
- package/.docs/reference/memory/memory-class.md +1 -1
- package/.docs/reference/memory/serialized-memory-config.md +1 -1
- package/.docs/reference/project-structure.md +1 -1
- package/.docs/reference/pubsub/lease-provider.md +1 -1
- package/.docs/reference/server/express-adapter.md +3 -1
- package/.docs/reference/server/fastify-adapter.md +3 -1
- package/.docs/reference/server/hono-adapter.md +3 -1
- package/.docs/reference/server/koa-adapter.md +3 -1
- package/.docs/reference/server/nestjs-adapter.md +3 -1
- package/.docs/reference/storage/clickhouse.md +0 -32
- package/.docs/reference/storage/composite.md +1 -27
- package/.docs/reference/storage/retention.md +0 -11
- package/.docs/reference/tools/mcp-client.md +0 -22
- package/.docs/reference/tools/mcp-server.md +4 -161
- package/.docs/reference/workspace/agentcore-runtime-sandbox.md +3 -1
- package/.docs/reference/workspace/agentfs-filesystem.md +3 -1
- package/.docs/reference/workspace/apple-container-sandbox.md +3 -1
- package/.docs/reference/workspace/archil-filesystem.md +3 -1
- package/.docs/reference/workspace/azure-blob-filesystem.md +3 -1
- package/.docs/reference/workspace/blaxel-sandbox.md +3 -1
- package/.docs/reference/workspace/daytona-sandbox.md +3 -1
- package/.docs/reference/workspace/docker-sandbox.md +3 -1
- package/.docs/reference/workspace/e2b-sandbox.md +3 -1
- package/.docs/reference/workspace/files-sdk-filesystem.md +3 -1
- package/.docs/reference/workspace/gcs-filesystem.md +3 -1
- package/.docs/reference/workspace/google-drive-filesystem.md +3 -1
- package/.docs/reference/workspace/local-filesystem.md +3 -1
- package/.docs/reference/workspace/local-sandbox.md +3 -1
- package/.docs/reference/workspace/modal-sandbox.md +3 -1
- package/.docs/reference/workspace/railway-sandbox.md +3 -1
- package/.docs/reference/workspace/s3-filesystem.md +3 -1
- package/.docs/reference/workspace/vercel-sandbox.md +7 -5
- package/.docs/reference/workspace/vercel-serverless.md +3 -1
- package/CHANGELOG.md +0 -29
- package/package.json +4 -4
- package/.docs/docs/capabilities/channels/discord.md +0 -98
- package/.docs/docs/capabilities/channels/other-adapters.md +0 -68
- package/.docs/docs/capabilities/channels/overview.md +0 -255
- package/.docs/docs/capabilities/channels/slack.md +0 -225
- package/.docs/docs/capabilities/channels/teams.md +0 -100
- package/.docs/docs/capabilities/channels/telegram.md +0 -98
- package/.docs/docs/capabilities/channels/whatsapp.md +0 -99
- package/.docs/docs/getting-started/file-based-agents.md +0 -116
- package/.docs/models/providers/crossmodel.md +0 -109
- package/.docs/models/providers/empiriolabs.md +0 -106
- package/.docs/models/providers/meta.md +0 -101
- package/.docs/models/providers/model-oracle-ai.md +0 -87
- package/.docs/models/providers/pioneer.md +0 -148
- package/.docs/models/providers/unorouter.md +0 -95
- package/.docs/reference/file-based-agents/config.md +0 -97
- package/.docs/reference/file-based-agents/instructions.md +0 -54
- package/.docs/reference/file-based-agents/logger.md +0 -26
- package/.docs/reference/file-based-agents/memory.md +0 -58
- package/.docs/reference/file-based-agents/observability.md +0 -32
- package/.docs/reference/file-based-agents/processors.md +0 -56
- package/.docs/reference/file-based-agents/scorers.md +0 -54
- package/.docs/reference/file-based-agents/server.md +0 -37
- package/.docs/reference/file-based-agents/skills.md +0 -56
- package/.docs/reference/file-based-agents/storage.md +0 -30
- package/.docs/reference/file-based-agents/studio.md +0 -56
- package/.docs/reference/file-based-agents/subagents.md +0 -123
- package/.docs/reference/file-based-agents/tools.md +0 -63
- package/.docs/reference/file-based-agents/workflows.md +0 -52
- package/.docs/reference/file-based-agents/workspace.md +0 -74
|
@@ -8,17 +8,6 @@ Tool providers let Builder-created agents call tools from third-party apps such
|
|
|
8
8
|
|
|
9
9
|
This page covers what's specific to the Builder: setting up connections, choosing a connection scope, and managing connections. To register a provider and enable its toolkits, see [Tools](https://mastra.ai/docs/editor/tools).
|
|
10
10
|
|
|
11
|
-
## Setup at a glance
|
|
12
|
-
|
|
13
|
-
To connect a toolkit like Gmail and use it from a Builder agent:
|
|
14
|
-
|
|
15
|
-
1. [Register a tool provider](#register-a-tool-provider) on `MastraEditor` with your Composio API key.
|
|
16
|
-
2. [Set up a Composio auth config](#set-up-a-composio-auth-config) for the toolkit and enable it.
|
|
17
|
-
3. [Connect the toolkit](#connect-a-toolkit) from the Builder and complete the OAuth flow.
|
|
18
|
-
4. [Choose a connection scope](#connection-scope) if the default author-owned account isn't what you want.
|
|
19
|
-
|
|
20
|
-
The rest of this page covers each step in detail.
|
|
21
|
-
|
|
22
11
|
## Prerequisites
|
|
23
12
|
|
|
24
13
|
Before agents can use integration tools in the Builder:
|
|
@@ -53,8 +42,6 @@ export const mastra = new Mastra({
|
|
|
53
42
|
|
|
54
43
|
Each provider's toolkits become available in the Builder once it's registered. Use `allowedToolkits` to restrict which toolkits the provider exposes — by slug, such as `gmail` or `googlecalendar`. Omit it to expose every toolkit the provider offers. To add another provider, import it and add another entry to `toolProviders`. For the full list of providers and their options, see [Tools — Integration providers](https://mastra.ai/docs/editor/tools).
|
|
55
44
|
|
|
56
|
-
`ComposioToolProvider` needs a Composio **project** API key (the `x-api-key` type from a project's settings in the [Composio dashboard](https://dashboard.composio.dev)). Store it in an environment variable, as shown with `COMPOSIO_API_KEY` above.
|
|
57
|
-
|
|
58
45
|
## Set up a Composio auth config
|
|
59
46
|
|
|
60
47
|
Each toolkit a user can connect needs its own auth config in the [Composio dashboard](https://dashboard.composio.dev). An auth config defines how Composio authenticates with an app — its OAuth client, scopes, and credentials. Each toolkit needs its own because requirements vary by app: some share common OAuth methods, while others need extra setup. Without an enabled config, the connection flow fails.
|
|
@@ -65,7 +52,7 @@ Each toolkit a user can connect needs its own auth config in the [Composio dashb
|
|
|
65
52
|
|
|
66
53
|
Keep exactly one auth config enabled per toolkit. When a user connects the toolkit, the provider resolves the single enabled config for that toolkit and starts the OAuth flow against it.
|
|
67
54
|
|
|
68
|
-
> **Warning:** The provider throws if a toolkit has zero enabled auth configs or more than one.
|
|
55
|
+
> **Warning:** The provider throws if a toolkit has zero enabled auth configs or more than one. Enable exactly one auth config per toolkit you expose in the Builder.
|
|
69
56
|
|
|
70
57
|
## Connect a toolkit
|
|
71
58
|
|
|
@@ -78,36 +65,7 @@ The connected account is bound to the agent, and its tools are ready to use on t
|
|
|
78
65
|
|
|
79
66
|
## Connection scope
|
|
80
67
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
- `per-author` (default): the connection belongs to the agent's author. Any invoker runs the agent with the author's account. Use this for personal agents or a single shared team account.
|
|
84
|
-
- `shared`: every caller uses one shared bucket, regardless of who invokes the agent. Use this for a platform-owned account that all users should share.
|
|
85
|
-
- `caller-supplied`: each call is bucketed by the caller's `resourceId`, read from the request context. Use this for multi-tenant SaaS, where the host app authenticates the end user upstream and each tenant should use their own connected account.
|
|
86
|
-
|
|
87
|
-
Set `defaultScope` on the provider to apply a scope to every connection authorized against it:
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
const composio = new ComposioToolProvider({
|
|
91
|
-
apiKey: process.env.COMPOSIO_API_KEY!,
|
|
92
|
-
allowedToolkits: ['github'],
|
|
93
|
-
defaultScope: 'caller-supplied',
|
|
94
|
-
})
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
With `caller-supplied`, the host app must forward a `resourceId` on every request so each tenant lands in its own bucket. Set `mapUserToResourceId` on the server's auth config to derive the `resourceId` from the authenticated user, so every request carries it automatically:
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
export const mastra = new Mastra({
|
|
101
|
-
server: {
|
|
102
|
-
auth: {
|
|
103
|
-
authenticateToken: async token => verifyToken(token),
|
|
104
|
-
mapUserToResourceId: user => user.id,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
})
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
> **Warning:** When a `caller-supplied` connection runs without a `resourceId`, every tenant falls back to a single shared `default` bucket. All callers then share one set of credentials, which can expose one tenant's connected account to another. Always wire `mapUserToResourceId` (or otherwise set `resourceId` on the request context) for multi-tenant deployments.
|
|
68
|
+
When you select a toolkit's tools for an agent, you also pin a connection. The connection determines which account each tool call uses at runtime, with a scope that controls who shares the credential. Today connections are `per-author`: the connection belongs to the agent's author, and any invoker runs the agent with the author's account.
|
|
111
69
|
|
|
112
70
|
## Related
|
|
113
71
|
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
> **Note:** The Agent Builder is part of the Mastra Enterprise Edition. Production deployments require a valid EE license. [Contact sales](https://mastra.ai/contact) for more information.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[YouTube video player](https://www.youtube-nocookie.com/embed/AbdgIu4Z07I)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
The Agent Builder lets you build, configure, and operate Mastra agents all within the UI. It runs inside your Mastra server, persists everything to `Mastra.storage`, and supports multi-tenant agent workflows with RBAC and channel integrations.
|
|
10
10
|
|
|
11
11
|
- [**Configuration**](https://mastra.ai/docs/agent-builder/configuration): Toggle UI sections and pin admin-controlled defaults for every new agent.
|
|
12
12
|
- [**Model policy**](https://mastra.ai/docs/agent-builder/model-policy): Restrict which providers and models the Builder exposes, and pin a default.
|
|
@@ -108,5 +108,4 @@ Omitting the `builder` field has the same effect.
|
|
|
108
108
|
|
|
109
109
|
- [Configuration](https://mastra.ai/docs/agent-builder/configuration): Toggle Builder surfaces and pin defaults for new agents.
|
|
110
110
|
- [Access control](https://mastra.ai/docs/agent-builder/access-control): Gate the Builder with authentication and role-based access control.
|
|
111
|
-
- [Deploying](https://mastra.ai/docs/agent-builder/deploying): Replace local development primitives with production-ready storage, filesystems, and sandboxes.
|
|
112
|
-
- 📹 [Mastra Agent Builder workshop](https://www.youtube.com/watch?v=p2p_wb-rUPg\&t=666s)
|
|
111
|
+
- [Deploying](https://mastra.ai/docs/agent-builder/deploying): Replace local development primitives with production-ready storage, filesystems, and sandboxes.
|
|
@@ -23,7 +23,9 @@ new MastraEditor({
|
|
|
23
23
|
})
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
The Builder library tab now exposes a **Browse** view backed by skills.sh. End users can preview a skill, then install it into an agent.
|
|
26
|
+
The Builder library tab now exposes a **Browse** view backed by skills.sh. End users can preview a skill, then install it into an agent.
|
|
27
|
+
|
|
28
|
+
> **Note:** See the [AgentBuilderOptions reference](https://mastra.ai/reference/editor/agent-builder/agent-builder-options) for the full `registries` schema.
|
|
27
29
|
|
|
28
30
|
## Related
|
|
29
31
|
|
|
@@ -88,7 +88,7 @@ await agentController.selectOrCreateThread()
|
|
|
88
88
|
await agentController.sendMessage({ content: 'Hello!' })
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
Visit the [AgentController reference](https://mastra.ai/reference/agent-controller/agent-controller-class) for the full constructor parameters and method signatures.
|
|
91
|
+
> **Note:** Visit the [AgentController reference](https://mastra.ai/reference/agent-controller/agent-controller-class) for the full constructor parameters and method signatures.
|
|
92
92
|
|
|
93
93
|
## Architecture
|
|
94
94
|
|
|
@@ -128,5 +128,4 @@ Your app sends commands — send a message, switch mode, approve a tool call —
|
|
|
128
128
|
- [Threads and state](https://mastra.ai/docs/agent-controller/threads-and-state): Manage persistent conversations
|
|
129
129
|
- [Subagents](https://mastra.ai/docs/agent-controller/subagents): Delegate focused subtasks
|
|
130
130
|
- [Tool approvals and permissions](https://mastra.ai/docs/agent-controller/tool-approvals): Human-in-the-loop gating
|
|
131
|
-
- [API reference](https://mastra.ai/reference/agent-controller/agent-controller-class): Full constructor and method docs
|
|
132
|
-
- 📹 [Mastra AgentController harness workshop](https://www.youtube.com/watch?v=tV1pSleP-LM)
|
|
131
|
+
- [API reference](https://mastra.ai/reference/agent-controller/agent-controller-class): Full constructor and method docs
|
|
@@ -133,7 +133,9 @@ agentController.subscribe(event => {
|
|
|
133
133
|
})
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
This is the recommended pattern for most UIs. Subscribe to individual typed events only when you need to react to a specific transition rather than re-render the whole view.
|
|
136
|
+
This is the recommended pattern for most UIs. Subscribe to individual typed events only when you need to react to a specific transition rather than re-render the whole view.
|
|
137
|
+
|
|
138
|
+
> **Note:** Visit the [Session reference](https://mastra.ai/reference/agent-controller/session) for the full list of sub-objects and method signatures.
|
|
137
139
|
|
|
138
140
|
## Related
|
|
139
141
|
|
package/.docs/docs/agents/a2a.md
CHANGED
|
@@ -261,5 +261,4 @@ Use this hook to enforce expected providers, expected endpoints, certificate-bou
|
|
|
261
261
|
- [Agent reference](https://mastra.ai/reference/agents/agent)
|
|
262
262
|
- [JavaScript client agents reference](https://mastra.ai/reference/client-js/agents)
|
|
263
263
|
- [A2A core concepts](https://a2a-protocol.org/latest/topics/key-concepts/)
|
|
264
|
-
- [A2A discovery guide](https://a2a-protocol.org/latest/topics/agent-discovery/)
|
|
265
|
-
- 📹 [Agent-to-agent with Mastra workshop](https://www.youtube.com/watch?v=LQDzyNGm-aw)
|
|
264
|
+
- [A2A discovery guide](https://a2a-protocol.org/latest/topics/agent-discovery/)
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
+
|
|
3
|
+
# Channels
|
|
4
|
+
|
|
5
|
+
**Added in:** `@mastra/core@1.22.0`
|
|
6
|
+
|
|
7
|
+
Channels connect your agents to messaging platforms like Slack, Discord, and Telegram. When a user sends a message on a platform, the agent receives it, processes it through the normal agent pipeline, and streams the response back to the conversation.
|
|
8
|
+
|
|
9
|
+
## When to use channels
|
|
10
|
+
|
|
11
|
+
Use channels when you want your agent to:
|
|
12
|
+
|
|
13
|
+
- Respond to messages in Slack workspaces, Discord servers, or Telegram chats
|
|
14
|
+
- Handle both direct messages and mentions in group conversations
|
|
15
|
+
|
|
16
|
+
## Quickstart
|
|
17
|
+
|
|
18
|
+
Configure channels directly on your agent using adapters from the [Chat SDK](https://chat-sdk.dev/adapters):
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { Agent } from '@mastra/core/agent'
|
|
22
|
+
import { createSlackAdapter } from '@chat-adapter/slack'
|
|
23
|
+
|
|
24
|
+
export const supportAgent = new Agent({
|
|
25
|
+
id: 'support-agent',
|
|
26
|
+
name: 'Support Agent',
|
|
27
|
+
instructions: 'You are a helpful support assistant.',
|
|
28
|
+
model: 'openai/gpt-5.5',
|
|
29
|
+
channels: {
|
|
30
|
+
adapters: {
|
|
31
|
+
slack: createSlackAdapter(),
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Register the agent in your Mastra instance with storage so channel state persists across restarts:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { Mastra } from '@mastra/core'
|
|
41
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
42
|
+
import { supportAgent } from './agents/support-agent'
|
|
43
|
+
|
|
44
|
+
export const mastra = new Mastra({
|
|
45
|
+
agents: { supportAgent },
|
|
46
|
+
storage: new LibSQLStore({
|
|
47
|
+
url: process.env.DATABASE_URL,
|
|
48
|
+
}),
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Each adapter reads credentials from environment variables by default.
|
|
53
|
+
|
|
54
|
+
## Platform setup
|
|
55
|
+
|
|
56
|
+
Each platform requires credentials and event configuration. See the Chat SDK adapter docs for full setup: [Slack](https://chat-sdk.dev/adapters/slack), [Discord](https://chat-sdk.dev/adapters/discord), [Telegram](https://chat-sdk.dev/adapters/telegram).
|
|
57
|
+
|
|
58
|
+
Mastra generates a webhook route for each platform at:
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
/api/agents/{agentId}/channels/{platform}/webhook
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
For example: `/api/agents/support-agent/channels/slack/webhook`
|
|
65
|
+
|
|
66
|
+
Point your platform's webhook or interactions URL to this path.
|
|
67
|
+
|
|
68
|
+
### Local development
|
|
69
|
+
|
|
70
|
+
Platform webhooks need a public URL to reach your local server. Use a tunnel to expose `localhost:4111`:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# ngrok
|
|
74
|
+
ngrok http 4111
|
|
75
|
+
|
|
76
|
+
# cloudflared
|
|
77
|
+
npx cloudflared tunnel --url http://localhost:4111
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Copy the generated URL and use it as the base for your webhook paths (e.g. `https://abc123.ngrok.io/api/agents/support-agent/channels/slack/webhook`).
|
|
81
|
+
|
|
82
|
+
## Thread context
|
|
83
|
+
|
|
84
|
+
When a user mentions the agent mid-conversation in a channel thread, the agent may not have prior context. By default, Mastra fetches the last 10 messages from the platform on the first mention.
|
|
85
|
+
|
|
86
|
+
1. On the **first mention** in a thread, the agent fetches recent messages from the platform.
|
|
87
|
+
2. These messages are prepended to the user's message as conversation context.
|
|
88
|
+
3. After responding, the agent subscribes to the thread and has full history via Mastra's memory.
|
|
89
|
+
4. Subsequent messages in that thread **don't** re-fetch from the platform.
|
|
90
|
+
|
|
91
|
+
Set `threadContext: { maxMessages: 0 }` to disable this behavior. This only applies to non-DM threads.
|
|
92
|
+
|
|
93
|
+
Mastra also adds a short system message telling the agent which channel and platform the request came from (DM vs public channel, platform name, bot display name). Set `threadContext: { addSystemMessage: false }` to skip it.
|
|
94
|
+
|
|
95
|
+
## Tool approval
|
|
96
|
+
|
|
97
|
+
Tools with `requireApproval: true` render as interactive cards with Approve and Deny buttons:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { createTool } from '@mastra/core/tools'
|
|
101
|
+
import { z } from 'zod'
|
|
102
|
+
|
|
103
|
+
const deleteFile = createTool({
|
|
104
|
+
id: 'delete-file',
|
|
105
|
+
description: 'Delete a file from the system',
|
|
106
|
+
inputSchema: z.object({
|
|
107
|
+
path: z.string().describe('Path to the file to delete'),
|
|
108
|
+
}),
|
|
109
|
+
requireApproval: true,
|
|
110
|
+
execute: async ({ path }) => {
|
|
111
|
+
await fs.unlink(path)
|
|
112
|
+
return { deleted: path }
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
When the agent calls this tool, users see a card with the tool name, arguments, and Approve/Deny buttons. The tool only executes after approval.
|
|
118
|
+
|
|
119
|
+
Set `toolDisplay: 'text'` on an adapter to render tool calls as plain text instead of interactive cards. In `'hidden'` mode the agent uses `autoResumeSuspendedTools` to let the LLM decide based on the conversation context, since hidden mode doesn't post approval buttons.
|
|
120
|
+
|
|
121
|
+
## Multi-user awareness
|
|
122
|
+
|
|
123
|
+
In group conversations, Mastra automatically prefixes each message with the sender's name and platform ID so the agent can distinguish between speakers:
|
|
124
|
+
|
|
125
|
+
```text
|
|
126
|
+
[Alice (@U123ABC)]: Can you help me with this?
|
|
127
|
+
[Bob (@U456DEF)]: I have a question too.
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Multimodal content
|
|
131
|
+
|
|
132
|
+
Models like Gemini can natively process images, video, and audio. Combine `inlineMedia` and `inlineLinks` to let users share rich content with your agent across platforms:
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { Agent } from '@mastra/core/agent'
|
|
136
|
+
import { createDiscordAdapter } from '@chat-adapter/discord'
|
|
137
|
+
import { google } from '@ai-sdk/google'
|
|
138
|
+
|
|
139
|
+
export const visionAgent = new Agent({
|
|
140
|
+
id: 'vision-agent',
|
|
141
|
+
name: 'Vision Agent',
|
|
142
|
+
instructions: 'You can see images, watch videos, and listen to audio.',
|
|
143
|
+
model: google('gemini-3.1-flash-image-preview'),
|
|
144
|
+
channels: {
|
|
145
|
+
adapters: {
|
|
146
|
+
discord: createDiscordAdapter(),
|
|
147
|
+
},
|
|
148
|
+
inlineMedia: ['image/*', 'video/*', 'audio/*'],
|
|
149
|
+
inlineLinks: [
|
|
150
|
+
// Gemini treats YouTube URLs as native video file parts
|
|
151
|
+
{ match: 'youtube.com', mimeType: 'video/*' },
|
|
152
|
+
{ match: 'youtu.be', mimeType: 'video/*' },
|
|
153
|
+
'imgur.com', // HEAD-check imgur links; inline as file part if mimeType matches inlineMedia
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
})
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
With this configuration:
|
|
160
|
+
|
|
161
|
+
- A user uploads a screenshot and the agent describes what it sees
|
|
162
|
+
- A user uploads an `.mp4` clip and the agent summarizes the video
|
|
163
|
+
- A user pastes a YouTube link and the agent watches and discusses the video
|
|
164
|
+
- A user pastes an imgur link and the agent sees the image directly
|
|
165
|
+
|
|
166
|
+
By default, only images are sent inline (`inlineMedia: ['image/*']`). Unsupported types are described as text summaries so the agent knows about the file without crashing models that reject them.
|
|
167
|
+
|
|
168
|
+
> **Note:** See [Channels reference](https://mastra.ai/reference/agents/channels) for all `inlineMedia` patterns and [inlineLinks reference](https://mastra.ai/reference/agents/channels) for domain matching, HEAD detection, and forced mime types.
|
|
169
|
+
|
|
170
|
+
## Serverless deployment
|
|
171
|
+
|
|
172
|
+
On serverless platforms like Vercel, each request runs in a separate, short-lived instance. Channels need two things to work reliably in that environment: a way to keep the function alive while the agent responds, and a shared pub/sub so instances can coordinate.
|
|
173
|
+
|
|
174
|
+
### Keep the function alive with `waitUntil`
|
|
175
|
+
|
|
176
|
+
A channel webhook returns a `200` response right away, then the agent runs in the background to post its reply. On most serverless platforms the function is frozen as soon as it responds, which kills the run before the agent answers. Pass a `waitUntil` function so the platform keeps the instance alive until the run finishes.
|
|
177
|
+
|
|
178
|
+
On Vercel, pass `waitUntil` from `@vercel/functions`:
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { Agent } from '@mastra/core/agent'
|
|
182
|
+
import { createSlackAdapter } from '@chat-adapter/slack'
|
|
183
|
+
import { waitUntil } from '@vercel/functions'
|
|
184
|
+
|
|
185
|
+
export const agent = new Agent({
|
|
186
|
+
id: 'agent',
|
|
187
|
+
channels: {
|
|
188
|
+
adapters: {
|
|
189
|
+
slack: createSlackAdapter(),
|
|
190
|
+
},
|
|
191
|
+
waitUntil,
|
|
192
|
+
},
|
|
193
|
+
})
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Vercel and AWS Lambda require `waitUntil`, since they freeze the function as soon as the response is sent. Cloudflare Workers and Netlify Functions are detected automatically from the request context, so they don't need it. For runtimes where `waitUntil` lives on the request context but isn't detected automatically, use `resolveWaitUntil`. See the [Channels reference](https://mastra.ai/reference/agents/channels) for details.
|
|
197
|
+
|
|
198
|
+
### Coordinate instances with a shared pub/sub
|
|
199
|
+
|
|
200
|
+
Channels route messages through the agent's signal pipeline, and each run acquires a lease on its thread so a single run owns the conversation at a time. The default in-memory pub/sub can't cross instance boundaries, so on serverless a follow-up message can land on a different instance than the one running the agent. Without a shared pub/sub, that instance can't reach the active run and starts its own, leaving the original run untouched and the thread processed twice.
|
|
201
|
+
|
|
202
|
+
Configure a shared pub/sub backed by Redis Streams on the `Mastra` instance so leases and signals coordinate across instances:
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { Mastra } from '@mastra/core'
|
|
206
|
+
import { RedisStreamsPubSub } from '@mastra/redis-streams'
|
|
207
|
+
|
|
208
|
+
export const mastra = new Mastra({
|
|
209
|
+
agents: { agent },
|
|
210
|
+
pubsub: new RedisStreamsPubSub({
|
|
211
|
+
url: process.env.REDIS_URL,
|
|
212
|
+
keyPrefix: 'mastra:my-app',
|
|
213
|
+
}),
|
|
214
|
+
})
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Vercel's managed Redis integration and Upstash Redis both work well. For more on when a distributed pub/sub is needed, see the [PubSub guide](https://mastra.ai/docs/server/pubsub) and the [`RedisStreamsPubSub` reference](https://mastra.ai/reference/pubsub/redis-streams).
|
|
218
|
+
|
|
219
|
+
## Related
|
|
220
|
+
|
|
221
|
+
- [Guide: Building a Slack assistant](https://mastra.ai/guides/guide/slack-assistant)
|
|
222
|
+
- [Agent overview](https://mastra.ai/docs/agents/overview)
|
|
223
|
+
- [Tool approval](https://mastra.ai/docs/agents/agent-approval)
|
|
224
|
+
- [Channels reference](https://mastra.ai/reference/agents/channels)
|
|
225
|
+
- [Chat SDK adapters](https://chat-sdk.dev/adapters)
|
|
@@ -94,7 +94,7 @@ For `createCodeMode()` to work well, keep these tips in mind:
|
|
|
94
94
|
- Keep tools focused, so each does one thing well and the model composes them in code.
|
|
95
95
|
- Code mode helps most when calls can be parallelized with `Promise.all`.
|
|
96
96
|
|
|
97
|
-
Visit the [`createCodeMode()` reference](https://mastra.ai/reference/tools/create-code-mode) for configuration options, return values, result shape, and instructions inspection.
|
|
97
|
+
> **Note:** Visit the [`createCodeMode()` reference](https://mastra.ai/reference/tools/create-code-mode) for configuration options, return values, result shape, and instructions inspection.
|
|
98
98
|
|
|
99
99
|
## Scoping tools across multiple code tools
|
|
100
100
|
|