Note
Giving an AI agent access to your admin without fearing for your data
The blog admin from the quick start, opened to an AI agent over MCP: find week-old drafts and publish the three oldest, from one real run. Then what protects your data, and where the limits are.
In the previous post we built a small blog admin on tbtop/admin 0.7: posts, categories, tags and a sign-in screen. This one picks up the same app and gives an AI client access to it over MCP, with one concrete job: find draft posts older than a week and publish the three oldest. Then it goes through, without hand-waving, what stops that client from doing something you didn't intend.
What was actually run. Every response below comes from a single run of a scripted client,scripts/mcp-e2e.sh. It usescurlandjqagainstphp artisan serve, on a fresh database (php artisan migrate:fresh --seed), on 2026-10-16. The captures are committed in the demo repo underdocs/screenshots/mcp/. The auth and visibility claims are backed by PHPUnit tests intests/Feature/AdminMcpTest.php. The Cursor and Claude Desktop configs near the end come from the tbtop docs and weren't run against the demo. They're marked as such.
The shape of it
Since 0.6, a tbtop panel can serve an opt-in MCP endpoint. It exposes exactly three tools. Here's how the server annotates them in tools/list (from 02-tools-list.json, with descriptions and input schemas left out):
{ "name": "search", "title": "Search Tool", "annotations": { "title": "Search Tool", "readOnlyHint": true } }
{ "name": "query", "title": "Query Tool", "annotations": { "title": "Query Tool", "readOnlyHint": true } }
{ "name": "execute", "title": "Execute Tool", "annotations": { "title": "Execute Tool", "destructiveHint": true } }searchlists the pages the user may open, with their tables and executables (actions and forms).queryreads rows from a table, with the table's own filters, tabs, sort and pagination.executeruns an action or form by id.
There's no separate API behind these. query and execute call the panel's own table, action and form controllers in-process. Whatever the browser UI enforces (page gates, ->authorize(), validation rules, checks inside your handler) applies to the agent too. The agent acts as a user of your app and can do exactly what that user can do in the browser.
Wiring: three lines that matter
On the panel:
->mcp(['auth:sanctum', 'abilities:tbtop-mcp', 'throttle:60,1']);In bootstrap/app.php, the Sanctum ability middleware needs an alias. Laravel doesn't register it by default, and it's the step that's easiest to miss:
use Laravel\Sanctum\Http\Middleware\CheckAbilities;
$middleware->alias([
'abilities' => CheckAbilities::class,
]);The User model uses Sanctum's HasApiTokens, and laravel/mcp is installed. That registers POST /admin/mcp.
A token for one client
Tokens come from your app. tbtop doesn't issue them. Give the admin token its own ability, so that the user's other Sanctum tokens can't reach the admin:
php artisan tinker
>>> $u = App\Models\User::where('email', 'admin@blog.demo')->first();
>>> $u->createToken('mcp-demo', ['tbtop-mcp'])->plainTextToken;Keep the plain-text value in an env var and never commit it.
The demo's tests check the door three ways: no token gets 401, a token with tbtop-mcp gets in, and a token minted for something else gets 403:
public function test_mcp_initialize_rejects_token_without_tbtop_mcp_ability(): void
{
$user = User::factory()->create();
$token = $user->createToken('other-app', ['read-posts'])->plainTextToken;
$this->withToken($token)
->postJson('/admin/mcp', [
'jsonrpc' => '2.0',
'id' => 1,
'method' => 'initialize',
'params' => [
'protocolVersion' => '2025-11-25',
'capabilities' => [],
'clientInfo' => ['name' => 'phpunit', 'version' => '1'],
],
], [
'Accept' => 'application/json, text/event-stream',
])
->assertForbidden();
}Make the question answerable
An agent can only filter and sort by what the table exposes. query refuses any filter, sort column or page size that search didn't list. The posts table from the quick start had no date to go by, so "older than a week" couldn't be asked. Two lines on PostsIndexPage fixed that, the same way they would for a human user:
Column::make('created_at')->label('Created')->date('Y-m-d')->sortable(),Daterange::make('created_at')->label('Created'),The seeder adds five drafts backdated 10 to 60 days, plus three recent drafts (2 to 3 days old) that must not match.
The run
The script mints a token, then sends five JSON-RPC calls. Each one goes through the same helper:
mcp_post() {
local outfile=$1
local body=$2
curl -sS "${BASE_URL}/admin/mcp" \
-H "Authorization: Bearer ${TOKEN}" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d "$body" > "$outfile"
}Note that there's no Origin header. That matters later.
initialize
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"mcp-e2e","version":"1"}}}The server introduces itself and tells the agent how to proceed (from 01-initialize.json, trimmed):
"serverInfo":{"name":"Tabletop Admin","version":"1.0.0"},"instructions":"An admin panel, acting as the signed-in user with exactly their permissions.\nStart with `search` to list pages and what each offers; `search` with a page (and its params)\nfor a record page. Read rows with `query`, then run actions and forms with `execute`."Next comes tools/list ({"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}), which returned the annotations shown at the top.
search: what may I touch?
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"search","arguments":{}}}The answer lists eight pages: dashboard, categories, category edit, post create, post edit, posts, tag edit, tags. The sign-in pages from admin:install --auth aren't there, and the test test_mcp_search_does_not_list_auth_pages asserts that. Here's the posts page from 03-search.json, with the tool's text payload decoded and trimmed (columns and the search field left out):
{
"page": "posts-index-page",
"title": "Posts",
"executables": [
{ "id": "posts-index-page:edit", "kind": "action", "label": "Edit", "needs": ["row"], "table": "posts" },
{ "id": "posts-index-page:togglePublish", "kind": "action", "label": "Publish / unpublish", "needs": ["row"], "table": "posts" },
{ "id": "posts-index-page:delete", "kind": "action", "label": "Delete", "confirm": "Delete record?", "needs": ["row"], "table": "posts" },
{ "id": "posts-index-page:bulkPublish", "kind": "action", "label": "Publish selected", "needs": ["selection"], "table": "posts" },
{ "id": "posts-index-page:delete-selected", "kind": "action", "label": "Delete selected", "confirm": "Delete selected records?", "needs": ["selection"], "table": "posts" }
],
"tables": [
{
"table": "posts",
"filters": [
{ "name": "status", "kind": "in", "label": "Status", "value": "array of values, a row matches any of them", … },
{ "name": "author_id", "kind": "select", "label": "Author", "value": "exact value", "options": "dynamic" },
{ "name": "created_at", "kind": "daterange", "label": "Created", "value": "{\"from\": \"Y-m-d\", \"to\": \"Y-m-d\"}, either bound optional" }
],
"tabs": ["all", "published", "draft"],
"sortable": ["title", "published_at", "created_at"],
"pagination": { "perPage": 25, "options": [10, 25, 50] }
}
],
"excluded": []
}That's the agent's whole map: a draft tab, a created_at date range, and created_at as a sortable column. Everything the task needs, and nothing more.
query: old drafts, oldest first
The script computes the cutoff as today minus seven days (date -u -d '7 days ago' +%Y-%m-%d). For this run that was 2026-10-09, and the to bound includes that day. The arguments it sent:
{
"page": "posts-index-page",
"table": "posts",
"tab": "draft",
"filters": { "created_at": { "to": "2026-10-09" } },
"sort": "created_at",
"dir": "asc",
"perPage": 25
}The rows that came back (04-query-old-drafts.json, decoded; the first two rows in full, the rest down to title, created_at and _key):
{
"data": [
{
"id": "#8",
"title": "Stale draft: onboarding doc",
"slug": "stale-draft-onboarding",
"status": "draft",
"category.name": "Product",
"author.name": "Demo Admin",
"published_at": null,
"created_at": "2026-08-17",
"_key": 8
},
{
"id": "#7",
"title": "Stale draft: perf audit backlog",
"slug": "stale-draft-perf-audit",
"status": "draft",
"category.name": "Engineering",
"author.name": "Demo Admin",
"published_at": null,
"created_at": "2026-09-01",
"_key": 7
},
{ "id": "#5", "title": "Stale draft: migration checklist", "created_at": "2026-09-25", "_key": 5, … },
{ "id": "#4", "title": "Stale draft: Q3 roadmap notes", "created_at": "2026-10-02", "_key": 4, … },
{ "id": "#6", "title": "Stale draft: interview questions", "created_at": "2026-10-06", "_key": 6, … }
],
"total": 5,
"page": 1,
"perPage": 25
}Five stale drafts, oldest first. The three recent drafts didn't make it past the date range. Note two things about the rows. First, the id column comes formatted ("#8"), because that's what formatUsing() renders in the UI. Second, the raw key travels separately as _key, which no column can overwrite. Agents and handlers should read _key.
execute: publish the three oldest
The script doesn't hardcode anything. It takes the first three _key values from the query response:
SELECTION=$(jq -r '
.result.content[0].text
| fromjson
| .data[0:3]
| map(._key | tostring)
| @json
' "$OUT_DIR/04-query-old-drafts.json")That gives ["8", "7", "5"], sent as:
{
"id": "posts-index-page:bulkPublish",
"selection": ["8", "7", "5"]
}The response (05-execute-bulk-publish.json, result.content[0].text) carries the same effects the UI would get:
{"ok":true,"effects":[{"kind":"notify","message":"Published 3 post(s)","level":"success"},{"kind":"refreshTable","table":"posts"}]}What ran on the server is the ordinary bulk action from the posts page. The agent sent keys, and the handler loaded the records itself:
$s->action('bulkPublish')->label('Publish selected')->color('primary')->handle(
function (ActionCtx $ctx): Effects {
$ids = $ctx->selection;
$published = Post::whereKey($ids)->update([
'status' => PostStatus::Published,
]);
Post::whereKey($ids)->whereNull('published_at')->update([
'published_at' => now(),
]);
return Effects::make()
->notify("Published {$published} post(s)")
->refreshTable('posts');
},
needs: ['selection'],
),"Three oldest" was the selection rule here because it's deterministic and scriptable. "The best three" would be the model's call, made from whatever it can see. A query row holds only the visible columns, formatted as they display, plus _key. To judge a post by its body, an agent has to open the record page (search with post-edit-page and {"post": "…"} params), which returns the form's current values.
Two things went wrong while the script was being written, both from the build log:
- The executable argument is
id, notexecutable. - The
pageinqueryis the slug thatsearchreturns (posts-index-page), not the URL path (posts).
What actually protects your data
In the order a request meets them:
- Origin check. The package checks
Originitself, before your middleware runs. A request with noOrigin(curl, Claude Desktop, Cursor, CLI clients) passes, which is why our script did. A browserOriginhas to match the origin ofAPP_URL, or one you list with->mcpAllowedOrigins([...]). Anything else gets403, which blocks DNS rebinding and calls from other sites' pages. The check readsAPP_URL, never the request's ownHost, which a rebound request controls. - Your middleware, and only yours. The list you pass to
mcp()is the whole stack for that route. The panel'sweb+auth:{guard}stack doesn't run. In the demo,auth:sanctumrequires a bearer token (no token gets401, tested);abilities:tbtop-mcprequires thetbtop-mcpability (a token minted for something else gets403, tested); andthrottle:60,1allows 60 calls a minute. Because the throttle comes after auth, the limit is per user, not per IP. The package sets no rate limit of its own. - No session. The stack starts none, so a signed-in browser cookie can't stand in for a token. Keep it that way: don't add
weborStartSessionto themcp()list. - Page and action gates.
Page::can(),->authorize()on actions andwhen()conditions run inside the controllers, so they hold over MCP. An action the user can't see is one the agent can't run. - Validation, and a fixed vocabulary. Field rules run the same as in the UI. Invalid input comes back as errors keyed by field, and the handler doesn't run.
queryaccepts only the filters, sorts, tabs and page sizessearchlisted, so the agent can't invent a query your table doesn't support. - What's hidden. The published sign-in pages declare
mcp(): falsein the package base class: signing in needs a browser session, and MCP calls don't carry one. Media and upload fields can't be filled over MCP.searchlists them underexcludedFields, for example{"name":"cover_media_id","kind":"media","reason":"media fields cannot be filled over MCP"}. Browser-only actions are listed as excluded too. - A destructive label. tbtop annotates
executewithdestructiveHint, always and for every action;searchandqueryare read-only. Actions are code you write, so the package can't tell a delete from an edit and doesn't guess. - Your handler.
rowandselectionare client input, from a browser or from an agent. An agent can send any key, not only the onesqueryreturned. The demo's handler re-loads bywhereKey(). In a real app, re-load through the same scope the table uses (owner, tenant, soft deletes) and authorize per record.
The annotation is a hint to the MCP client. Whether the user is asked to confirm a call is decided by the client and its settings, not by tbtop, which adds no confirmation step of its own. Theconfirmtexts you see insearch("Delete record?") are the UI's dialog titles, passed along as information. Over MCP they don't stop anything. AndbulkPublishhas noconfirmat all.
What MCP doesn't do
- No tokens, no token screen. Your app issues and revokes them.
- No access checks of its own. Panel and page middleware don't run on the MCP route. An access rule that lives only there doesn't apply to agents.
- No confirmation UI. See the note above.
- No files. Upload and media fields can't be set. Rich text is accepted only as Lexical JSON, and HTML is refused.
- No reach beyond the UI. The agent sees visible columns, the table's filters and sorts, and the form values a page would prefill. Nothing else on the record. If the agent needs to ask something, the table has to support it, as
created_atshowed. - No judgment. Picking "the best" is the model's call, made from whatever you exposed.
- No Laravel 11. MCP needs Laravel 12.41+ (via
laravel/mcp), even though the rest of tbtop/admin also runs on Laravel 11.
How to narrow access
The demo has no admin-only role, on purpose. It's a single-admin demo, so any signed-in user is an admin, and any token with tbtop-mcp can do everything that user can. Don't copy that into a real app. At minimum:
- Gate the panel, and repeat the gate in
mcp(). The docs' example stack is['auth:sanctum', 'abilities:tbtop-mcp', 'can:access-admin', 'throttle:60,1']. Panel middleware doesn't run for MCP, so the check has to be in both places. See Access control. - Give agents their own least-privileged user or role. A token has its user's whole reach, and every row the agent reads goes into the model provider's context.
- One token per client, with an expiry. Set
sanctum.expirationand revoke the token when the client goes away. - Hide what agents shouldn't run or don't need with
->mcp(false)on actions, orpublic static function mcp(): bool { return false; }on a page. The demo's ownsearchoutput shows candidates:categories-index-page:createCancelandtags-index-page:createCancelare the Cancel buttons of the create modals. They're harmless, but they're listed as executables, and every one costs the agent context. - Put irreversible actions behind
->authorize()for roles agents don't get, and re-check records in handlers. - Keep confirmation on in your client. Data can carry instructions: a post body or a customer message can tell the model to run something. An "always allow" setting in the client removes the human from the loop, and tbtop can't put them back.
Connecting a real client
These configs are from the tbtop docs (wiring.md, the MCP page). The demo repo commits the Cursor one as a template, but none of them was run against the demo. Only the scripted curl client above was.
Cursor connects over HTTP with a header. ${env:…} keeps the token out of the file (docs/mcp-http-client.json in the demo):
{
"mcpServers": {
"tbtop-blog-demo": {
"url": "http://127.0.0.1:8000/admin/mcp",
"headers": {
"Authorization": "Bearer ${env:TBTOP_TOKEN}"
}
}
}
}Claude Desktop only starts local (stdio) servers, so the docs bridge it to the HTTP endpoint with mcp-remote (Node 18+). Keep the header value in env, because a space inside args breaks on some platforms:
{
"mcpServers": {
"tbtop": {
"command": "npx",
"args": ["-y", "mcp-remote", "http://127.0.0.1:8000/admin/mcp", "--header", "Authorization:${TBTOP_AUTH}"],
"env": { "TBTOP_AUTH": "Bearer 1|your-token" }
}
}
}Claude Code, per the docs:
claude mcp add --transport http tbtop https://example.com/admin/mcp \
--header "Authorization: Bearer <token>"Before you wire up any client, the docs suggest the same smoke test our script starts with: send initialize with curl. You should get a JSON-RPC result with the token, and 401 without it.
Wrap-up
Connecting an agent to the blog admin took one mcp() line, one middleware alias and one token. Making the task answerable took one more column and one filter. The guarantees all come from places you already control: the token's ability, your middleware list, your gates, your validation rules and your handlers. tbtop's part is to route agent calls through the same controllers as the UI, check Origin, hide what can't work over MCP, and label execute honestly as destructive. Whether the human gets asked before each call is up to the client.
- Demo repo: DiVotek/tbtop-blog-demo (
docs/mcp-log.md,scripts/mcp-e2e.sh,docs/screenshots/mcp/) - Prequel: From an empty Laravel app to a blog admin with login
- Docs: AI agents (MCP) · docs.tbtop.dev
tbtop/admin is pre-1.0. 1.0 is planned for the end of 2026.