Security

MCP Permissions in Laravel: Least-Privilege Agent Tokens

By Lara Dashboard 1 view
MCP Permissions in Laravel: Least-Privilege Agent Tokens
MCP permissions in Laravel decide how much damage a confused or hijacked AI agent can do on your site. The safe pattern is simple: connect every agent as its own user, give that user a role with the fewest permissions that still get the job done, and keep a kill switch you can hit in one click. This guide shows how to do that in Lara Dashboard, and where the current code still leaves gaps you need to cover yourself.
Disclosure: we build Lara Dashboard, an MIT-licensed Laravel CMS and admin with a built-in MCP server. Everything below comes from the develop branch on GitHub as of December 2026 (v1.5.0 line, Laravel 13, laravel/mcp ^0.6.0, Sanctum 4). If you are new to MCP, read our plain-English guide to MCP servers for a CMS first.

Quick answer: five rules for least-privilege agent tokens

  1. Create a dedicated user for each agent or client app. Never connect as the superadmin.
  2. Give that user a custom role with only the permissions its tools need.
  3. Leave out post.delete, email_template.edit and module permissions unless a human really wants the agent to use them.
  4. Remember that abilities are copied onto the token when it is created, but every call also checks the user's live permissions.
  5. Use the role as your kill switch, and turn MCP off in Settings if you need everything to stop at once.
The rest of this post explains why each rule matters, using the real permission map from the code.

Every MCP call in Lara Dashboard is checked twice

Lara Dashboard issues MCP credentials as Laravel Sanctum personal access tokens. Sanctum lets each token carry a list of token abilities, and Lara Dashboard uses abilities such as mcp:posts.read and mcp:posts.write.
Each core tool then calls authorizeMcpAbility() from the InteractsWithMcpAuthorization trait before it does anything. That method checks two things.
The token ability. The token must hold the ability for that tool, for example mcp:posts.update for update-post. If it does not, the call returns an error.
The live user permission. The user behind the token must still hold the matching Spatie permission, for example post.edit, at the moment of the call.
This double check is the heart of least privilege here. The token ability is a snapshot. The permission check is live. An agent can only do something when both say yes.

Abilities come from the user's permissions, not from a checkbox

There is no screen where you tick abilities for a token. McpTokenService::resolveAbilitiesForUser() builds the list for you. Every token gets mcp:access, plus each ability whose mapped permission the user holds. Here is the core map.
Permission on the userAbility on the tokenTools it unlocks
post.viewmcp:posts.readlist-posts, get-post
post.createmcp:posts.writecreate-post (generate-seo-meta also needs post.edit)
post.editmcp:posts.updateupdate-post, assign-post-terms, attach-featured-image
post.deletemcp:posts.deletedelete-post
term.viewmcp:terms.readlist-terms
media.view / media.createmcp:media.read / mcp:media.writelist-media / upload-media, create-media-upload, finalize-media-upload
email_template.viewmcp:email_templates.readlist-email-templates, get-email-template
email_template.editmcp:email.sendsend-email
dashboard.viewmcp:briefing.read, mcp:ops.health.readget-daily-briefing, get-site-health
settings.editmcp:ops.cache, mcp:ops.logs.readclear-cache, list-logs, get-log-tail
module.viewmcp:modules.readlist-modules
Modules can add rows to this map with the McpFilterHook::ABILITY_PERMISSION_MAP filter. The CRM module does this for contacts, deals and tickets. Our post on custom MCP tools in Laravel shows how.
Two rows deserve a second look. email_template.edit also unlocks send-email, so anyone who can edit templates can have an agent send mail. And settings.edit unlocks log reading and cache clearing. Logs can contain email addresses, request data and stack traces, so treat that as sensitive.

Build a dedicated agent role, not a shared login

Lara Dashboard seeds Superadmin, Admin, Editor, Subscriber and Contact roles. None of them fits an AI agent well. Admin has almost everything. Editor gets blog permissions, not the post.* permissions the MCP tools check, and it has no settings.edit, so it cannot create an MCP token at all.
So create a role for the job. Two recipes cover most teams.
Read-only reporter. post.view, term.view, media.view and dashboard.view. The agent can list content, read the daily briefing and check site health. It cannot change anything.
Draft writer. The reporter permissions plus post.create, post.edit and media.create. The agent can write posts, upload a cover, tag the post and fill SEO fields. Leave out post.delete, email_template.edit, settings.edit and any module permissions.
Then create one user per agent or per client app, such as agent-claude@yourdomain and agent-cursor@yourdomain, and give each the role. Separate users mean separate tokens, separate "last used" dates in the token list, and the option to cut off one agent without touching the others. Our guide to role-based access with Spatie and Lara Dashboard covers role design in more depth.

Token creation needs settings.edit, so plan for it

Here is the awkward part. McpTokenController::store() only lets a user create a token if they pass the manage settings policy, which checks settings.edit. The user also needs post.view or post.create, MCP must be switched on, and demo mode must be off. The Settings routes themselves sit behind can:settings.edit.
A token always belongs to the user who creates it. So an admin cannot mint a token for the agent user. Someone has to sign in as the agent user to do it. How you handle settings.edit depends on the connection type.
Agent tokens (Cursor, Claude Desktop, Claude Code, scripts). Give the agent role settings.edit for a few minutes, sign in as the agent user, create the token under Settings → MCP → Agent tokens, then remove settings.edit from the role. The token will still list mcp:ops.cache and mcp:ops.logs.read, because abilities were copied at creation. But the live permission check now fails, so clear-cache and the log tools return an error. The agent keeps only what the role still allows.
OAuth (Claude.ai custom connectors). According to docs/mcp.md, every refresh re-checks the same rules as token creation and recalculates abilities from current permissions. If the user loses settings.edit, the next refresh revokes the grant. So an OAuth agent user must keep settings.edit, which also keeps the log and cache tools open and gives that account wide access to the web admin settings. Protect that login with a long, unique password. Core leaves two-factor login to modules through a login hook, so add a 2FA module if you use one. Our Claude MCP OAuth guide walks through the connection itself.
If you want an OAuth agent without the log and cache tools, strip those abilities with the McpFilterHook::TOKEN_ABILITIES filter from a small module. It receives the final ability list and the user:
Hook::addFilter(McpFilterHook::TOKEN_ABILITIES, fn (array $abilities, $user) => $user->hasRole('AI Agent') ? array_values(array_diff($abilities, ['mcp:ops.cache', 'mcp:ops.logs.read'])) : $abilities, 10, 2);
Test this on staging first and confirm the result with list-mcp-tools, which returns only the tools the current token and user can actually call.

Your kill switch is the role, not the token

Because every call re-checks the user's live permissions, removing a permission from the agent role takes effect on the very next call, for every token that user holds. That is the fastest way to take write access away from an agent.
You have three levels of shutdown.
One permission. Remove, say, post.edit from the agent role. Reads keep working and edits stop at once.
One connection. Revoke the token under Settings → MCP → Agent tokens. For an OAuth connection, this also revokes its refresh token, so the client must ask for approval again. Note that the token list only shows the signed-in user's own tokens, so you revoke as the agent user.
Everything. Turn MCP off under Settings → MCP. The EnsureMcpEnabled middleware then returns 404 for /mcp and every OAuth endpoint.

Gaps to cover yourself

We would rather you hear these from us than find them in production. All of them are true of the develop branch as of December 2026.
An agent that can create posts can publish them. Core has a post.publish permission, but create-post only checks post.create and update-post only checks post.edit. Both accept status: published. If you need drafts only, enforce it with a team rule, a reviewer who publishes, or a module that adds its own guarded tool.
Agent tokens never expire. Manual agent tokens are created without an expiry date, and config/sanctum.php sets expiration to null. The Sanctum docs confirm that tokens then never expire until revoked. You can set a global expiration in that config file, but it applies to every Sanctum token in the app, including API tokens. Most teams are better off rotating agent tokens on a calendar. OAuth access tokens already last 60 minutes, with 30-day rotating refresh tokens.
New permissions do not reach old agent tokens. The snapshot cuts both ways. If you later add media.create to the role, an existing agent token still lacks mcp:media.write. Issue a fresh token. OAuth connections pick it up on their next refresh.
Scopes are not per tool on the consent screen. The OAuth server uses a single mcp:use scope, and abilities follow the user's role. The MCP project's security best practices recommend a progressive scope model with minimal initial scopes. In Lara Dashboard, the role is where you get that minimisation today.

When least privilege is overkill

Not every site needs all of this. If you are the only person on a local or staging install, connecting with your own account and a short-lived token is a fair trade. If no agent will ever write, a read-only role with no settings change is enough. And if your team does not use AI clients at all, leave MCP switched off. It is off by default for a reason.
Lara Dashboard is also not the right base if you need fine-grained, per-tool consent that end users approve one scope at a time. Today the role decides. If you need per-scope consent, plan to build it on top or pick a stack built around it. We compared approaches in WordPress MCP Adapter vs Lara Dashboard MCP.

Self-check before you hand an agent a token

  1. The agent connects as its own user, not as a human's account or the superadmin.
  2. Its role has only the permissions in the read-only or draft-writer recipe.
  3. post.delete, email_template.edit and module permissions are left out.
  4. For agent tokens, settings.edit was removed from the role after the token was created.
  5. For OAuth, the agent user has a strong password or 2FA, and the ops abilities are stripped with a filter if you don't want them.
  6. list-mcp-tools shows only the tools you expect.
  7. Someone reviews posts before they go live, because post.create can publish.
  8. Agent tokens have a rotation date in your calendar.
  9. You know the three kill switches: the role, the token list and the MCP toggle.

Verdict

Least privilege for MCP in Laravel is mostly role design. Lara Dashboard gives you the hard parts: Sanctum abilities, a live permission check on every call, rotating OAuth refresh tokens and a single switch to turn the server off. What it does not yet give you is per-tool consent, separate publish rights for agents or expiring agent tokens, so cover those with roles, reviews and rotation. If you want an open-source Laravel CMS where AI agents work inside the same permission system as your editors, try Lara Dashboard, create a read-only agent user first, and widen it only when you trust the workflow. The v1.5.0 release notes cover the OAuth and security work behind it.

FAQ

What are MCP permissions in Laravel?

They are the rules that decide which MCP tools an AI client may call. In Lara Dashboard, a tool runs only if the Sanctum token holds the right ability and the user behind it still holds the matching Spatie permission.

Can I pick abilities by hand when I create a token?

No. Lara Dashboard calculates abilities from the user's permissions when the token is created. To narrow a token, narrow the user's role, or remove abilities with the TOKEN_ABILITIES filter from a module.

Why does the agent user need settings.edit?

Creating an MCP token, or approving an OAuth client, requires the manage settings policy, which checks settings.edit. For agent tokens you can remove it after creation. OAuth grants re-check it on every refresh, so OAuth agent users must keep it.

How do I stop an agent immediately?

Remove the relevant permission from its role, which blocks the next call. Or revoke its token in Settings → MCP, or turn MCP off entirely so /mcp returns 404.

Do Lara Dashboard agent tokens expire?

Manual agent tokens do not expire unless you set a global Sanctum expiration, which affects all Sanctum tokens. OAuth access tokens expire after 60 minutes and refresh tokens after 30 days, rotating on each use.

Can an agent with post.create publish posts?

Yes, as of December 2026. The create-post and update-post tools accept a published status without checking post.publish. Keep a human review step if you want drafts only.
Laravel CMS laravel roles permissions spatie permission laravel authorization laravel access control

Try Lara Dashboard for Free

Explore every feature live — no sign-up required.

Launch Live Demo