Developer tools over MCP
Point Claude Code, Cursor or any MCP client at your running app and let it read your Aviary consoles (agent runs, spend, approvals and more) through one endpoint, gated by each console's own authorize.
AgentMcpServerModule mounts a second MCP endpoint, /mcp/aviary. It serves the developer tools that your Aviary libraries register. The agent dashboard registers its governance reads there, and the other Aviary consoles add their own. You list nothing. Each library's tools are gated by the authorize you already gave its console.
Connect a client
Protect the consoles with a token (or any authorize):
import { AgentDashboardModule, authorizeByToken } from '@dudousxd/nestjs-agent-dashboard';
import { AgentMcpServerModule } from '@dudousxd/nestjs-agent-mcp-server';
@Module({
imports: [
AgentModule.forRoot({ /* … */ }),
AgentDashboardModule.forRoot({
authorize: authorizeByToken({ token: process.env.CONSOLE_TOKEN }),
}),
AgentMcpServerModule.forRoot({ name: 'Acme', version: '1.0.0', auth: myResolver }),
],
})
export class AppModule {}Then add the endpoint to Claude Code:
claude mcp add --transport http aviary http://localhost:3000/mcp/aviary --header "Authorization: Bearer $CONSOLE_TOKEN"Ask it things like "why did the last support run fail?" or "what did we spend on models this week?".
With a global prefix
app.setGlobalPrefix('api') moves the endpoint to /api/mcp/aviary. Point the client there, or keep it at /mcp/aviary by excluding it from the prefix:
app.setGlobalPrefix('api', { exclude: ['mcp/aviary'] });The boot log shows the path the endpoint answers at.
How access works
Every request is authorized again, per library:
- A
tools/listruns theauthorizeof every library that registered tools. The caller sees the tools of the libraries that allowed it, and nothing else. A library that denied the caller does not appear at all. - A
tools/callruns only theauthorizeof the library that owns the tool. - When no library allows the caller, the endpoint answers like a console:
401 { error: 'unauthenticated' }withWWW-Authenticate: Bearer realm="aviary-dev", or403 { error: 'forbidden' }. The endpoint writes these itself, so your app's exception filters do not change them. - A console with no
authorizefollows its usual rule: open outside production, denied in production. - A library with no console at all (resilience, authz, diagnostics, filter) is gated by
devTools.authorize. See Libraries without a console.
The authorize runs with the MCP request's own ExecutionContext, so authorizeByToken reads the Authorization header the client sends. A rule that needs a signed-in session (request.user) needs a guard that sets it on this endpoint too. Pass that guard in devTools.decorators.
Token or session: anyAuthorize
A browser session and a CLI token usually need different rules. anyAuthorize allows a request when any of its rules allows it:
import { anyAuthorize, authorizeByToken } from '@dudousxd/nestjs-agent-dashboard';
AgentDashboardModule.forRoot({
decorators: [UseGuards(SessionGuard)],
authorize: anyAuthorize(
authorizeByToken({ token: process.env.CONSOLE_TOKEN }),
(ctx) => ctx.switchToHttp().getRequest().user?.role === 'admin',
),
});Each argument is any authorize form: a function, a class, a lazy import, { policy, ability } or a gate name. When none allows the request, the result is unauthenticated if any rule said so, otherwise forbidden.
Options
AgentMcpServerModule.forRoot({
// …
devTools: {
path: 'mcp/aviary', // default
exclude: ['agent_get_spend'], // lib ids or tool names
actions: 'refuse', // default; see Actions below
decorators: [UseGuards(SessionGuard)], // run before the per-lib authorize
authorize: authorizeByToken({ token: process.env.DEV_TOOLS_TOKEN }), // libs without a console
},
});| Option | Default | What it does |
|---|---|---|
path | 'mcp/aviary' | Where the endpoint mounts. It must differ from the product endpoint's path, or the boot fails |
exclude | [] | Library ids or full tool names that are never served |
actions | 'refuse' | Which tools that change data each caller gets. 'execute' allows them all; a list allows the actions of these library ids or tool names; a map or a function decides per caller. See Actions |
decorators | [] | Class decorators on the endpoint, before the per-library check: an authentication guard, a rate limit |
authorize | open outside production, denied in production | The gate of libraries that have no console. Any authorize form. See Libraries without a console |
devTools: false mounts nothing. The dev endpoint shares nothing with the product endpoint: not its auth, its tools, its allowedTools nor its actions. A product key opens nothing here unless a console's authorize accepts it. It also inherits the product endpoint's mcp.http allowedHosts and allowedOrigins checks.
The boot log lists what is served:
[AgentDevTools] dev tools at /mcp/aviary: agent (7), durable (8)Actions
Tools that change data (retry, cancel, refund…) are hidden by default. devTools.actions decides
which ones each caller gets. An action it refuses is not listed in tools/list and cannot be
called. The library's console authorize still runs first: actions only narrows what a library
already lets the caller see.
Give each library, or each tool, its own authorize. These take the same forms as a console's
authorize: a function, a class with authorize(), a lazy import, { policy, ability } or a gate
name.
import { authorizeByToken } from '@dudousxd/nestjs-agent-dashboard';
AgentMcpServerModule.forRoot({
// …
devTools: {
actions: {
durable: authorizeByToken({ token: process.env.DEV_TOOLS_TOKEN }),
durable_cancel_run: (ctx) => ctx.switchToHttp().getRequest().user?.role === 'owner',
payments_refund_payment: () => false,
},
},
});- A tool-name key (
durable_cancel_run) wins over its library's key (durable). - An action that matches neither key is refused.
- An
authorizethat throws, or answers{ redirectTo }orunauthenticated, refuses. - Each
authorizeruns once per request, however many tools point at it.
For full control, pass a function. It gets the Nest request (Express's, or Fastify's request) and is asked once per action tool, per request:
devTools: {
actions: async (req, { lib, tool, destructive, caller }) => {
const user = req.user;
if (!user) return false;
return destructive ? user.role === 'owner' : user.role === 'admin';
},
},Anything but true (a false, a truthy non-boolean) or a throw refuses. A refused action is logged
at debug level only. The endpoint's instructions tell the client it is read-only unless this request
is actually served at least one action.
The shorthands still work: 'refuse' (the default), 'execute' (every action of every library the
caller gets in), or a list of library ids and tool names (['durable', 'payments_refund_payment']).
The product endpoint's actions: 'execute' does not apply here.
The types are exported from @dudousxd/nestjs-agent-mcp-server: DevToolsActions,
DevToolsActionsMap, DevToolsActionsAuthorizer and DevToolsActionRequest.
Libraries without a console
Some libraries register developer tools but have no console, so no authorize of their own:
resilience, authz, diagnostics and filter. devTools.authorize gates their tools:
import { authorizeByToken } from '@dudousxd/nestjs-agent-dashboard';
AgentMcpServerModule.forRoot({
// …
devTools: { authorize: authorizeByToken({ token: process.env.DEV_TOOLS_TOKEN }) },
});It takes every form a console's authorize takes: a function, a class with authorize(), a lazy
import, { policy, ability } or a gate name. It runs at most once per request, whatever the number
of libraries it gates. A library that has a console keeps its own authorize; devTools.authorize
never opens it.
Without devTools.authorize, those libraries follow the consoles' rule: open outside production,
denied in production. The boot logs one warning naming them:
[@dudousxd/nestjs-agent-mcp-server] dev tools for resilience, authz have no authorize: open outside production, denied in production. Set devTools.authorize in AgentMcpServerModule.forRoot().To keep the agent dashboard's tools while mounting its routes yourself (routes: false), set devTools: true on AgentDashboardModule.forRoot. To turn off the dashboard's tools only, set devTools: false.
What the tools return
- Tools return what the console shows, through the same service methods. List tools take
pageandlimit(at most 100) and return{ items, next, total }. To get the next page, passnextaspage. - A result over 48 KB is cut and marked
truncated: true. - Keys that look like secrets (
secret,token,password,authorization,cookie,api_key) are redacted. Token counts are kept. - Every call writes one log line: the tool, the library, the caller, the duration and whether it worked. Read tools log at
debugand actions atlog. With@dudousxd/nestjs-diagnosticsinstalled, each call is also anagent:devtools.callevent. - A tool that cannot find what you asked for (
agent_get_runwith an unknown id) answers an MCP error, such asrun <id> not found.
The caller comes from whatever let the request in:
| Allowed by | Caller |
|---|---|
authorizeByToken | token:<hash>, never the token |
an authorize that answers { allowed: true, caller } | that caller |
any other authorize, with request.user.id set | user:<id> |
any other authorize, without request.user | session |
no authorize (outside production) | dev-open |
A Bearer header that no authorize accepted never becomes the caller.
The agent's tools
| Tool | Returns |
|---|---|
agent_list_runs | Runs, newest first. Filters: agent, status, errorCode, threadId, from/to |
agent_get_run | One run with its thread, tool calls and timings. includeMessages: true adds the thread's latest 50 messages, each cut to 2 KB. An unknown id is an error |
agent_get_spend | Spend by model, actor and feature, and the trend. by returns one of them |
agent_get_tool_stats | Calls, failures, rejections and latency per tool |
agent_get_reliability | Run metrics, breakdowns by agent and by error, and the trend |
agent_list_pending_approvals | Tool calls waiting for a human. Approve them in the app |
agent_list_recent_tool_calls | Tool calls of every agent, newest first |
Days are UTC YYYY-MM-DD and default to the last 30 days. None of these tools changes data.
Cost & Governance
The usage ledger and read-model — spend per model and actor, a gateway's reported cost preferred over a cache-aware estimate, daily quota, and the console that surfaces it all.
Federated console
One agent console on a central app that shows the threads, runs, tool calls and approvals of several apps, reading each app's own store and sending its approvals back to that app.