Manage Agents
One list of the workspace's agents and the user's MCP apps, with activation, settings and runs.
Admins decide which agents of the app run and what they may do; users decide what their own MCP apps may do. Both fit in one Agents list with a type column.
| Type | What it is | Who sets it |
|---|---|---|
| Workspace | An agent defined in code (defineAgent). | Admins, for everyone. |
| MCP | An app a user connected, such as Claude. | The user, for themselves. |
The list
list: protectedProcedure.handler(async ({ context }) => {
const [apps, workspace] = await Promise.all([
listConnectedApps(context),
canManageAgents(context).then((allowed) => (allowed ? agents.list() : [])),
]);
return [
...workspace.map((agent) => ({
id: agent.name,
type: "workspace" as const,
name: agent.title,
status: agent.status,
lastRunAt: agent.lastRunAt,
})),
...apps.map((app) => ({ ...app, type: "mcp" as const })),
];
}),Only admins see the workspace agents. Give them a permission such as agent: ["manage"], and check
it on every procedure that calls agents.
A workspace agent's page
The page depends on the agent's status:
- New or off: an empty state with what the agent does and an Activate button
(
agents.setActive(name, true)). An agent no longer in code shows that it is removed, without a button. - Active: Turn off, a line with its own grants when it runs as itself, and per tool the
choices from
agents.get(name).tools: Allow, Ask first, Don't allow (agents.setPolicy(name, tool, policy)). - Always: its runs, newest first, a page at a time, also when it is off.
runs: protectedProcedure
.use(permissionMiddleware({ agent: ["manage"] }))
.input(z.object({ agent: z.string(), pagination: offsetPaginationSchema }))
.handler(async ({ input }) => {
const [data, total] = await Promise.all([
agents.runs.list({
agent: input.agent,
limit: input.pagination.limit,
offset: input.pagination.page * input.pagination.limit,
}),
agents.runs.count({ agent: input.agent }),
]);
return offsetPaginationResponse({ data, pagination: input.pagination, total });
}),Show per run when it started, its trigger, who it ran for (a user, or the agent itself), its status and error. A background run that failed is only visible here.
An MCP app's page
The user sets per tool of the catalog what the app may do (mcp.apps.get and setPolicy), turns the
app off or on (mcp.apps.setEnabled), and sees the changes it made from history (viaId is the
app's client id). Disconnect deletes the consent and the app's settings and revokes its tokens;
the MCP route refuses tokens without a consent, so the app must sign in again.
Record it in history
setActive and setPolicy of agents, and setPolicy and setEnabled of mcp.apps, return
{ before, after }, or null
when nothing changed. Publish the change as an event and record it, so there is a trail of who
activated an agent or allowed a tool:
const change = await agents.setPolicy(input.agent, input.tool, input.policy);
if (!change) return;
publishAgentAccessChange(context, agent, {
action: "updated",
before: { [input.tool]: change.before },
after: { [input.tool]: change.after },
});The changes agents make themselves are recorded by your existing history resources, with the agent
(or the user it acted for) as actor and the run as via (see
Changes made by agents).
Guidance
- Activate the assistant on deploy: until then the chat refuses messages.
- Explain refusals: the chat says that an admin can allow a tool in Agents.
- Never offer "ask first" where no one can be asked, such as MCP apps.
- Check the consent on every MCP request; access tokens outlive a disconnect.