mastra-ai/mastra · error
No agent or agent controller found with id "${agentId}"
Error message
No agent or agent controller found with id "${agentId}" What it means
In the object form connect({ id, name }), the id may belong to either a registered agent or an AgentController (since the agent may not exist yet). If #resolveAgent and #resolveAgentController both fail, the provider has no owner for the installation and throws this error.
Source
Thrown at channels/slack/src/provider.ts:1063
const baseUrl = this.#getBaseUrl();
if (!baseUrl) {
throw new Error(
'SlackProvider baseUrl not set. Configure studioHost/studioProtocol/studioPort in Mastra server config, or call setBaseUrl().',
);
}
// In the agentId form, the agent must exist. In the options form the id may
// belong to a registered agent or an AgentController — resolve which one so
// the installation records who owns it.
const agent = this.#resolveAgent(agentId);
if (isAgentIdForm && !agent) {
throw new Error(`Agent "${agentId}" not found`);
}
let ownerType: SlackOwnerType = 'agent';
if (!isAgentIdForm && !agent) {
const controller = this.#resolveAgentController(agentId);
if (!controller) {
throw new Error(`No agent or agent controller found with id "${agentId}"`);
}
ownerType = 'agentController';
}
// If there's already a pending installation, return its authorization URL
// instead of creating a duplicate Slack app
const storage = await this.#getStorage();
const existingRecord = await storage.getInstallationByAgent(PLATFORM, agentId);
if (existingRecord?.status === 'pending') {
try {
const pending = this.#parsePendingInstallation(existingRecord);
const decrypted = this.#decryptPendingInstallation(pending);
// The stored Slack app may have been deleted out-of-band (e.g. removed
// from the Slack admin UI). Reusing its authorizationUrl would hand the
// caller a dead link (`Invalid client_id`). Probe existence first and,
// if the app is gone, drop the pending record and create a fresh app.
let appStillExists = true;View on GitHub (pinned to 75dd419e61)
Solutions
- Register an AgentController with the given id on the Mastra instance, or use an id of an existing controller.
- Use an existing registered agent's id with connect(agentId) instead.
- Log/list available agents and controllers before connecting to pick a valid id.
Example fix
// before
await provider.connect({ id: 'ghost-controller', name: 'Bot' });
// after
mastra.registerAgentController(new AgentController({ id: 'ghost-controller' }));
await provider.connect({ id: 'ghost-controller', name: 'Bot' }); Defensive patterns
Strategy: validation
Validate before calling
const known = [...Object.keys(mastra.getAgents?.() ?? {}), ...listRegisteredControllerIds(mastra)];
if (!known.includes(id)) {
throw new Error(`id "${id}" is neither an agent nor an agent controller`);
} Try / catch
try {
await provider.connect({ id, name });
} catch (err) {
if (err instanceof Error && err.message.includes('No agent or agent controller found')) {
console.error('Register the agent or AgentController with this id before connecting');
} else throw err;
} Prevention
- Only pass ids that already exist as agents or registered AgentControllers.
- Keep controller registration in the same bootstrap file as SlackProvider setup.
- Log registered ids at startup to catch mismatches early.
When it happens
Trigger: provider.connect({ id: 'x', name: 'Y' }) where 'x' matches neither a registered Agent nor a registered AgentController on the attached Mastra instance.
Common situations: Passing a made-up id intending the library to create an agent (it does not); controller not registered with Mastra; id from another environment; typos in the id.
Related errors
- Agent "${agentId}" not found
- App creation failed: ${errorDetails}
- App manifest update failed: ${errorDetails}
- connect({ id, name }): "name" is required when connecting wi
- Agent ID is required
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/6fd095d5eea2ab8d.
Report an issue: GitHub.