ChannelProvider
ChannelProvider is the interface that platform integrations implement to connect agents to a messaging platform. A provider owns the full lifecycle of an integration: app provisioning and OAuth, webhook routing and event handling, adapter creation and agent wiring, and credential management.
Register providers on the Mastra constructor under channels, keyed by an id you choose. Each provider's routes are merged into the server's API routes automatically, and initialize() runs during Mastra startup.
import { Mastra } from '@mastra/core/mastra'
import { SlackProvider } from '@mastra/slack'
export const mastra = new Mastra({
channels: {
slack: new SlackProvider({
refreshToken: process.env.SLACK_REFRESH_TOKEN!,
baseUrl: process.env.MASTRA_BASE_URL,
}),
},
})
The provider's baseUrl is the public URL the platform sends webhooks and events to. In production this is your deployed Mastra server URL. For local development, the platform can't reach http://localhost:4111, so run a tunnel (such as cloudflared or ngrok) and point baseUrl at the tunnel URL (for example https://abc123.trycloudflare.com) so events reach your local dev process.
SlackProvider is the first built-in implementation. Build a custom provider by implementing this interface.
PropertiesDirect link to Properties
id:
MethodsDirect link to Methods
getRoutes:
initialize?:
configure?:
getInfo?:
connect?:
disconnect?:
listInstallations?:
Accessing a providerDirect link to Accessing a provider
Access a registered provider through the channels getter, keyed by the id you registered it under. The getter is typed from the constructor config, so mastra.channels.slack is the concrete provider with its full method surface.
await mastra.channels.slack.configure({ refreshToken })
When the key is only known at runtime, look the provider up by string id instead. getChannelProvider takes the concrete type as a generic, and getChannelProviders returns every registered provider keyed by id.
import type { SlackProvider } from '@mastra/slack'
const slack = mastra.getChannelProvider<SlackProvider>('slack')
const all = mastra.getChannelProviders()