Exposing Plugin Actions through MCP
Actions and MCP
What are Backstage Actions and MCP?
The Backstage Actions Registry is a shared list of tasks that backend plugins know how to perform. Each action has a name, a description, the information it needs, and the information it returns. Registering an action once allows other Backstage features to use it.
The MCP Actions backend makes selected actions available through the Model Context Protocol (MCP). MCP is a standard that allows an external tool, such as a coding assistant, to discover and run actions provided by Backstage.
What to expect
In this guide, an MCP client asks Backstage for the TODOs connected to a Component:
MCP client asks for a Component's TODOs
-> Backstage runs todo.list-for-entity
-> todo.read checks the signed-in user's access
-> Backstage returns only the TODOs that user may read
MCP does not decide who is allowed to see a TODO. Backstage still applies the
same todo.read permission used by the Component page and Search.
You will start with a read-only action, which looks up information without changing anything. Actions that create, update, or delete data need additional safety checks and are outside this walkthrough.
Prerequisites
Before starting:
- Complete Scaffolder so your test Component has onboarding TODOs.
- Choose an MCP client that can use Streamable HTTP and OAuth with Client ID Metadata Documents. These terms are explained when you configure the client.
Registering a TODO action
Step 1: Share the authorization helper
The Permissions chapter placed the getTodoReadFilter function inside the HTTP
router. Move it to plugins/todo-backend/src/authorization.ts so both HTTP
routes and Actions can call the same permission check:
import type {
BackstageCredentials,
PermissionsRegistryService,
PermissionsService,
} from '@backstage/backend-plugin-api';
import { NotAllowedError } from '@backstage/errors';
import { AuthorizeResult } from '@backstage/plugin-permission-common';
import { createConditionTransformer } from '@backstage/plugin-permission-node';
import { todoReadPermission } from '@internal/backstage-plugin-todo-common';
import { todoResourceRef } from './rules';
export async function getTodoReadFilter(options: {
credentials: BackstageCredentials;
permissions: PermissionsService;
permissionsRegistry: PermissionsRegistryService;
}) {
const decision = (
await options.permissions.authorizeConditional(
[{ permission: todoReadPermission }],
{ credentials: options.credentials },
)
)[0];
if (decision.result === AuthorizeResult.DENY) {
throw new NotAllowedError();
}
if (decision.result !== AuthorizeResult.CONDITIONAL) {
return undefined;
}
const transformConditions = createConditionTransformer(
options.permissionsRegistry.getPermissionRuleset(todoResourceRef),
);
return transformConditions(decision.conditions);
}
Update the HTTP routes to call this helper too. Keeping the check in one function prevents HTTP and MCP from applying different permission rules.
Step 2: Register list-for-entity
Register an action named list-for-entity. It accepts a Component reference
and returns the TODOs that the signed-in user may read:
import type {
PermissionsRegistryService,
PermissionsService,
} from '@backstage/backend-plugin-api';
import type { ActionsRegistryService } from '@backstage/backend-plugin-api/alpha';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { NotFoundError } from '@backstage/errors';
import type { CatalogService } from '@backstage/plugin-catalog-node';
import { getTodoReadFilter } from '../authorization';
import type { todoListServiceRef } from '../services/TodoListService';
export function createListTodosAction(options: {
actionsRegistry: ActionsRegistryService;
catalog: CatalogService;
permissions: PermissionsService;
permissionsRegistry: PermissionsRegistryService;
todoList: typeof todoListServiceRef.T;
}) {
options.actionsRegistry.register({
name: 'list-for-entity',
title: 'List TODOs for a Catalog entity',
description:
'Lists TODOs associated with a Catalog entity when the caller belongs to an owning Group.',
attributes: {
destructive: false,
readOnly: true,
idempotent: true,
},
schema: {
input: z =>
z.object({
entityRef: z
.string()
.describe('Entity ref in kind:namespace/name form'),
}),
output: z =>
z.object({
items: z.array(
z.object({
id: z.string(),
title: z.string(),
forEntityRef: z.string(),
dueAt: z.string().optional(),
}),
),
}),
},
action: async ({ input, credentials }) => {
const entity = await options.catalog.getEntityByRef(input.entityRef, {
credentials,
});
if (!entity) {
throw new NotFoundError(`Entity ${input.entityRef} was not found`);
}
const filter = await getTodoReadFilter({
credentials,
permissions: options.permissions,
permissionsRegistry: options.permissionsRegistry,
});
const { items } = await options.todoList.listTodosForEntity({
forEntityRef: stringifyEntityRef(entity),
filter,
});
return {
output: {
items: items.map(({ id, title, forEntityRef, dueAt }) => ({
id,
title,
forEntityRef,
dueAt,
})),
},
};
},
});
}
Register the action from the todo plugin by adding
actionsRegistryServiceRef to its initialization dependencies:
import { actionsRegistryServiceRef } from '@backstage/backend-plugin-api/alpha';
import { createListTodosAction } from './actions/createListTodosAction';
// Inside env.registerInit:
deps: {
actionsRegistry: actionsRegistryServiceRef,
catalog: catalogServiceRef,
permissions: coreServices.permissions,
permissionsRegistry: coreServices.permissionsRegistry,
todoList: todoListServiceRef,
// ...existing dependencies
},
async init({
actionsRegistry,
catalog,
permissions,
permissionsRegistry,
todoList,
}) {
createListTodosAction({
actionsRegistry,
catalog,
permissions,
permissionsRegistry,
todoList,
});
// ...existing initialization
}
The Actions Registry gives this action the ID todo:list-for-entity, using a
colon between the plugin ID and action name. The MCP server exposes the same
action as the tool todo.list-for-entity, using a dot because MCP tool names
cannot contain a colon.
Exposing the action through MCP
Step 3: Configure the MCP Actions backend
The following configuration lets the MCP Actions backend discover actions from
the todo plugin. It creates a focused MCP server that exposes only actions whose
names begin with todo::
backend:
actions:
pluginSources:
- todo
mcpActions:
servers:
todo:
name: Component TODOs
description: TODO tools restricted to the Component's owning Groups
filter:
include:
- id: 'todo:*'
The MCP client connects to this address using Streamable HTTP. This is the current way an MCP client and Backstage exchange requests over the web:
http://localhost:7007/api/mcp-actions/v1/todo
Do not configure the older, deprecated SSE address.
Step 4: Enable Client ID Metadata Documents
The MCP action must know which Backstage user is calling it so that
todo.read can check that user's Group ownership.
Client ID Metadata Documents
(CIMD) provide the sign-in flow. The MCP client opens Backstage in a browser,
where the user signs in and approves access. Backstage can then give the client
access on that user's behalf. The user does not need to copy a token into the
MCP settings.
This flow requires the new frontend system and the @backstage/plugin-auth
frontend plugin. Follow the
MCP Actions authentication documentation
to add the plugin if your app does not already include it.
Enable CIMD in app-config.yaml:
auth:
clientIdMetadataDocuments:
enabled: true
By default, Backstage allows a set of well-known MCP clients and loopback
redirect addresses. If your MCP client is not covered by the defaults, set
allowedClientIdPatterns and allowedRedirectUriPatterns to the values
documented by your client. Restricting these values to the chosen client is
safer than allowing every address.
Then configure the client with the server URL and no authorization header:
{
"mcpServers": {
"backstage-todos": {
"url": "http://localhost:7007/api/mcp-actions/v1/todo"
}
}
}
On the first connection, the client opens the Backstage authorization page. Sign in as the user who will use the tools and approve the request. Backstage then gives that MCP client the user's permitted access.
Review the allowed client and callback addresses before enabling this in production. See the MCP Actions authentication documentation for current details.
Step 5: Verify MCP authorization
- Connect an MCP client as a member of the Group that owns the component used in the Scaffolder chapter, then approve the request in Backstage.
- Run
todo.list-for-entitywith that Component's entity reference. - Confirm the result contains the onboarding TODOs created by the template.
- Use a separate client profile, approve the request as a non-owner, and run the same tool.
- Confirm the call returns no protected TODO data. Depending on the app policy, this can be an empty result or an authorization error.
The owner should now see the same TODOs through the Component page, Search, and
MCP. If MCP returns more TODOs, confirm that the action calls
getTodoReadFilter. If it returns fewer, confirm that the MCP client was
approved by the same user who tested the Component page.
What you did
You moved the todo.read logic into a helper shared by HTTP routes and Actions,
then registered the read-only todo.list-for-entity action. You exposed that
action through a focused MCP server and enabled browser-based approval with
Client ID Metadata Documents.
An MCP client now sees the same owner-authorized TODOs as the Component page and Search.
Going further
A future todo.create-for-entity action could call the owner-protected creation
route from the Scaffolder chapter. Actions that change data should clearly say
that they are not read-only and should not be exposed through MCP until their
permission and confirmation behavior has been tested.