authentik Agent MCP server
authentik: 2026.8.0+Enterprise
The authentik Agent includes a Model Context Protocol (MCP) server, ak mcp. With it, AI clients such as Claude Code, Codex, or Cursor can send requests to applications that are protected by authentik, and to the authentik API, without receiving your credentials or tokens.
The AI client works through an agent account that it creates for you. Requests to applications carry a token for you, with the agent account recorded as the actor, so that events show both.
Agent accounts are a type of user account in authentik. The authentik Agent is the software that runs on your device. The MCP server is part of the authentik Agent and creates agent accounts.
How it works
- The AI client creates an agent account. You're its owner. The agent account expires after the default token duration of your authentik deployment, 1 day by default, and starts without access to any application.
- The AI client requests access to one or more applications for the agent account, and shows you a link to the request.
- You approve or deny the request in authentik.
- The MCP server exchanges your authentik token for a token for the application, with the agent account as the actor.
- The AI client asks the MCP server to send HTTP requests to the application. The MCP server adds the token to the requests, so the AI client never sees it.
Prerequisites
- authentik 2026.8 or later, with an Enterprise license.
- The authentik Agent 0.73 or later on the device, with a profile. Refer to Configure your authentik deployment and Deploy the authentik Agent. With authentik 2026.11 and later, older versions of the authentik Agent can't create agent accounts.
akon yourPATH. On Windows, keep Include CLI in PATH selected when you install the authentik Agent.- An internal user account with the Add an agent user (self-service) permission, for example through a role. Refer to Permissions for managing agent accounts.
Prepare an application
The AI client can reach an application through the MCP server if the following applies:
- The application uses an OAuth2/OpenID Connect provider with the
authentik-cliprovider in Federated OAuth2/OpenID Providers, under Machine-to-Machine authentication settings. This is the same configuration as for Kubernetes. - The application has a Launch URL, or its provider has a redirect URI. Without a launch URL, the MCP server uses the first redirect URI.
- You can access the application.
The MCP server only sends requests to URLs with the same scheme and the same registrable domain as the launch URL, on any port. For example, a launch URL of https://wiki.internal.example.com allows requests to https://example.com, https://wiki.internal.example.com, and https://api.example.com:8443, but not to http://wiki.internal.example.com. For localhost and IP addresses, the host must match exactly.
Add the MCP server to an AI client
The MCP Server page of the authentik Agent app shows the same instructions, with buttons that install the server in Cursor and VS Code.
- Claude Code
- Claude Desktop
- Codex CLI
- Cursor
- VS Code
- Gemini CLI
- Zed
- OpenCode
claude mcp add authentik -- ak mcp
Check the connection with /mcp in Claude Code.
Open Settings > Developer > Edit Config and add the server to claude_desktop_config.json, then restart Claude Desktop:
{
"mcpServers": {
"authentik": {
"command": "ak",
"args": ["mcp"]
}
}
}
codex mcp add authentik -- ak mcp
Alternatively, add the server to ~/.codex/config.toml:
[mcp_servers.authentik]
command = "ak"
args = ["mcp"]
Open Cursor Settings > MCP, select New MCP Server, and add the server:
{
"mcpServers": {
"authentik": {
"command": "ak",
"args": ["mcp"]
}
}
}
Run MCP: Add Server from the command palette, select Command (stdio), enter ak mcp, and name the server authentik. Alternatively, add the server to .vscode/mcp.json:
{
"servers": {
"authentik": {
"type": "stdio",
"command": "ak",
"args": ["mcp"]
}
}
}
Add the server to ~/.gemini/settings.json, then restart Gemini CLI:
{
"mcpServers": {
"authentik": {
"command": "ak",
"args": ["mcp"]
}
}
}
Add the server to the Zed settings:
{
"context_servers": {
"authentik": {
"command": "ak",
"args": ["mcp"]
}
}
}
Add the server to ~/.config/opencode/opencode.json, then restart OpenCode:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"authentik": {
"type": "local",
"command": ["ak", "mcp"]
}
}
}
The MCP server uses the active profile. To use a different profile, add -p <profile>, for example ak -p work mcp.
Approve access requests
When the AI client requests access to an application, it shows you a link to the request. AI clients that support MCP Apps show a card with a Review in authentik button instead.
- Open the link. The request opens in the authentik user interface.
- Approve or deny the request.
Only you, as the owner of the agent account, can approve its requests, and the agent account can only request applications that you can access. A request expires if you don't approve it within 1 hour. Approved access lasts 1 hour, and never longer than the agent account. For more information, refer to Requests from agent accounts.
Tools
| Tool | Description | Authenticates as |
|---|---|---|
list_applications | Lists the applications that you can access, with their pbm_uuid and launch URL. | You |
create_agent | Creates an agent account that you own. | You |
request_access | Requests access to applications for an agent account. | The agent account |
grant_status | Checks whether an access request was approved or denied, and can wait for about 50 seconds. | You |
token_exchange | Gets a token for an application. | You, with the agent account as actor |
http_fetch | Sends a GET or HEAD request to an application. | You, with the agent account as actor |
http_send | Sends a POST, PUT, PATCH, or DELETE request to an application. | You, with the agent account as actor |
api_search | Searches the authentik API commands of ak api. | No request is sent |
api_describe | Shows the arguments of an authentik API command. | No request is sent |
api_call | Runs an authentik API command. | The agent account |
api_call_dangerous | Runs an authentik API command. Only available if ak mcp runs with --allow-dangerous-api. | You |
token_exchange takes the pbm_uuid of the application, which list_applications returns.
http_fetch and http_send only work after a token_exchange for the application, and only for URLs that the application's launch URL allows. They don't follow redirects, they set the Authorization, Cookie, Host, and Proxy-Authorization headers themselves, they time out after 30 seconds, and they return at most 256 KiB of a response body. Applications see your user as the subject of the token. Applications that read the act claim of the token also see the agent account.
Agent accounts that create_agent creates have no permissions in authentik, so api_call can only run commands that you grant the agent account access to.
The MCP server also provides two skills, authentik-app-access and authentik-api, that describe how to use these tools. AI clients that support MCP skills load them automatically.
Security considerations
- The AI client doesn't receive your authentik token or the tokens for applications. The MCP server adds them to requests.
- Each token exchange goes through the authentik Agent's authorization prompt for
token_exchange. To limit the applications that the MCP server can get tokens for, setauthorization.allowed_exchange_audiencesto the UUIDs of these applications. http_fetchandhttp_sendsend an application's token to every host in the registrable domain of its launch URL. If other services in that domain shouldn't receive the token, give the application its own domain.http_fetchandhttp_sendhave aninsecureoption, off by default, that skips TLS certificate verification.--allow-dangerous-apiadds theapi_call_dangeroustool, which can do anything that your authentik account can do. Only use it in sessions that you trust.- The MCP server only knows the agent accounts that it created while it runs. When the AI client restarts, it creates new agent accounts. The previous agent accounts remain until they expire. You can delete them on the Agents page of the user interface.
Troubleshooting
| Error | Solution |
|---|---|
Self-service agent creation is not enabled. | Give the user the Add an agent user (self-service) permission. |
Only internal user accounts can create agents. | Only internal users can create agent accounts. |
You can only create agents for yourself. | Update the authentik Agent to 0.73 or later. |
Cannot request access to '<application>' | You don't have access to the application. |
Unknown agent or Agent identity not found | The MCP server restarted. Ask the AI client to create a new agent account. |
No launch URL could be resolved | Set a Launch URL for the application, and pass the application's pbm_uuid to token_exchange. |
<url> is not adjacent to any application | The URL isn't in the registrable domain of the application's launch URL. Refer to Prepare an application. |
failed to exchange token | Check that the authentik-cli provider is federated with the application's provider, and that you can access the application. |