tutorials
MCP bearer token: connect Claude Code and Cursor to your mail (headless)
October 2, 2026

A headless client can't click "approve" in a browser. A scoped bearer token is how Claude Code, Cursor, and CI reach your inbox safely, and scoping it correctly is the whole game.
The Claude desktop app connects to an MCP server with OAuth: you click connect, a consent screen opens, you approve, done. But Claude Code, Cursor, and a CI job have no browser to open and no human standing by to approve a popup. They authenticate the boring, durable way: a static bearer token passed in an Authorization header. This article is the headless, security-focused companion to the launch post. If you want the OAuth path and a primer on what MCP even is, start with the OAuth path and what MCP is. Here we go deep on tokens: scoping them, wiring real clients, and managing their lifecycle.
OAuth vs bearer: which path for which client?
Use OAuth for clients that can open a browser, and a static bearer token for everything headless. The split is about consent flow, not security level: both end up calling the same MCP tools against the same inbox.
| Client | Auth path | Why |
|---|---|---|
| Claude desktop / web app | OAuth 2.1 + PKCE + DCR | Can open a browser for one-click consent |
| Claude Code | Static bearer | Headless terminal client, no browser |
| Cursor | Static bearer | Editor MCP config, no interactive consent |
| CI job / script | Static bearer | Fully automated, no human present |
The Tinbox OAuth implementation handles dynamic client registration so the Claude app registers itself with no client-ID juggling. None of that helps a terminal or a CI runner, which is exactly why the bearer path exists. A bearer token is just a credential you mint once and hand to the client; the client sends it on every request.
One important property: the token is issued by your own Tinbox instance and prefixed tbx_. There is no Tinbox-hosted token broker in the middle. The credential, the validation, and the inbox all live on your Cloudflare account. That's the same reason your tools can reach an inbox you own without asking a vendor for an integration.
How do I mint a scoped MCP bearer token?
Run npx tinbox token create with a --scope and a --name. The scope is the safety boundary, and the name is how you'll find the token later to rotate or revoke it.
# Read-only token: search, read, summarize. Cannot send.
npx tinbox token create --scope read --name "cursor-ro"
Token created (read):
tbx_live_8f3a91c4d27b0e6a5f1c...
Store it securely. It won't be shown again.
Copy that value immediately. Tinbox stores a hash, not the token, so it cannot show it to you a second time. Lose it and you re-mint.
For a client that genuinely needs to send mail, mint a full-scope token instead:
# Full token: read plus draft and send.
npx tinbox token create --scope full --name "ci-deploy-notifier"
Token created (full):
tbx_live_b1d77e02a93f4c8e6a01...
Store it securely. It won't be shown again.
The scope is enforced server-side on every tool call, not advertised as a hint the client is trusted to honor. When a read-only token tries to call send_email, the server rejects it. That's what makes scoping a real boundary rather than a label.
How do I wire Claude Code to my inbox?
Add an mcpServers entry to .mcp.json (in your project root, or your user-level Claude Code settings) with your /mcp URL and an Authorization: Bearer header.
{
"mcpServers": {
"inbox": {
"url": "https://mail.yourdomain.com/mcp",
"headers": {
"Authorization": "Bearer tbx_live_8f3a91c4d27b0e6a5f1c..."
}
}
}
}
Put project-specific tokens in the project .mcp.json and add that file to .gitignore if it carries a real token; put a personal token in your user settings so it isn't in any repo at all. Once it's wired, Claude Code can call search_messages, read_thread, and summarize straight from the terminal. With a read-only token it stops there. To let it draft and send, swap in a full-scope token.
How do I wire Cursor to my inbox?
Cursor reads MCP servers from its MCP config and uses the same url plus headers shape, so the bearer token drops in the same way.
{
"mcpServers": {
"inbox": {
"url": "https://mail.yourdomain.com/mcp",
"headers": {
"Authorization": "Bearer tbx_live_8f3a91c4d27b0e6a5f1c..."
}
}
}
}
Give Cursor its own token (cursor-ro above), not the same one you handed Claude Code. One token per client means you can revoke Cursor's access without breaking your terminal, and your audit trail tells you which client did what. The url and headers form is the portable, standard MCP-server shape; if a future Cursor build adds client-specific fields, the bearer header stays the same.
How do I use an MCP bearer token in CI without leaking it?
Store the token as an encrypted CI secret, read it from an environment variable at runtime, and never write it into a file you commit. The token is a secret like any database URL or API key.
Mint a dedicated token for the job (read-only unless it must send), then add it to your CI provider's secret store. In a GitHub Actions step it becomes an env var:
# .github/workflows/inbox-check.yml
jobs:
inbox-check:
runs-on: ubuntu-latest
steps:
- name: Query the inbox over MCP
env:
TINBOX_MCP_TOKEN: ${{ secrets.TINBOX_MCP_TOKEN }}
run: node scripts/inbox-check.mjs
The script reads the token from the environment and never sees it as a literal:
#!/usr/bin/env bash
# Fail loudly if the secret wasn't provided, instead of sending an empty header.
: "${TINBOX_MCP_TOKEN:?TINBOX_MCP_TOKEN is not set}"
curl -sS https://mail.yourdomain.com/mcp \
-H "Authorization: Bearer ${TINBOX_MCP_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call",
"params":{"name":"search_messages","arguments":{"query":"invoice","limit":5}}}'
Note the ${TINBOX_MCP_TOKEN:?...} guard: if the secret is missing, the script aborts rather than sending Bearer with nothing after it, which would otherwise surface as a confusing 401. With a read-only token, all this job can do is read; it cannot send mail even if the script is compromised, which is the point of scoping CI tokens tight.
What is the security model for MCP bearer tokens?
Least privilege, one token per purpose, and scope as the enforced boundary. A bearer token is a long-lived credential, so the defense is making each one do as little as possible and keeping them isolated.
Three rules carry most of the weight:
- Read-only by default. Mint
--scope readunless a client must send. Most uses (triage, search, summaries, interpreter verdicts your headless client can read) need no write access at all. - One token per client or purpose. Cursor, Claude Code, and each CI job get their own named token. A leak or a departing laptop revokes one credential, not all of them.
- Scope is the safety boundary. A leaked read-only token can search and read your mail, which is not nothing, but it cannot send as you, cannot delete, and cannot exfiltrate via outbound mail. A full token can, so guard those harder and mint fewer of them.
This is also why a "send everything" master token is the wrong default. The blast radius of a credential should match the job in front of it.
How do I rotate and revoke tokens?
Rotate by creating the replacement first, swapping it into the client, then revoking the old one. Revoke immediately, and out of band, the moment a token might be exposed.
# 1. Mint the replacement
npx tinbox token create --scope read --name "cursor-ro-2"
# 2. Update the client config with the new token, confirm it works, then:
npx tinbox token revoke cursor-ro
Revoked token "cursor-ro" (tbx_live_8f3a91c4...).
Requests using this token will now return 401.
Revocation takes effect on the next request. Anything still configured with the old token starts failing with 401 Unauthorized until you give it the new value, which is exactly why you swap the config before revoking. List what's live with npx tinbox token list to catch tokens you minted and forgot:
npx tinbox token list
NAME SCOPE CREATED LAST USED
cursor-ro-2 read 2026-08-01 2026-08-01
claude-code-ro read 2026-07-12 2026-07-30
ci-deploy-notifier full 2026-06-20 2026-07-29
A token with an old or empty LAST USED is a candidate for revocation. Naming tokens after their client is what makes this list readable instead of a wall of tbx_ prefixes.
What failure modes will I actually hit?
Almost every headless MCP problem is one of four things: a bad token, a missing scope, a wrong URL, or an empty tool list. The error strings are the same ones the launch post documents.
401 Unauthorized: invalid or expired token
The token was revoked, mistyped, expired, or never set (the empty-env-var case above). Re-check the Authorization header and re-mint with npx tinbox token create if needed.
403 Forbidden: scope 'send' not granted for this token
You asked the client to send with a read-only token. This is the guardrail working as designed. Mint a --scope full token if that client really should be allowed to send.
Client connected but lists no tools
The configured URL is missing the /mcp path, or DNS for mail.yourdomain.com isn't resolving yet. Confirm the endpoint with npx tinbox mcp status and check the URL ends in /mcp.
curl: empty reply / connection refused
Usually the wrong host or a http:// instead of https://. The MCP endpoint is HTTPS-only.
Good hygiene checklist
A short list you can paste into a runbook:
- Mint read-only tokens unless the client must send.
- Use one token per client or purpose, named after the client.
- Never commit a token; use env vars and encrypted CI secrets.
- Rotate by creating the new token before revoking the old one.
- Revoke immediately if a token might be exposed, then audit
token list. - Keep full-scope tokens few and guarded; they are the ones that can send as you.
The bearer path is deliberately simple so it works anywhere a client can set an HTTP header. The discipline is all in the scoping and the lifecycle, and both are CLI commands you run against your own instance, with no vendor in the loop. For the bigger picture of where the MCP endpoint sits in the stack, see the MCP endpoint in the full stack.
Deploy this yourself: npx tinbox init yourdomain.com. Token commands and the /mcp endpoint ship with every deployment; see the docs for the full token reference.
Frequently asked questions
What is an MCP bearer token?
An MCP bearer token is a static API token that a headless Model Context Protocol client (Claude Code, Cursor, a CI job) sends in an Authorization header to authenticate to an MCP server. It replaces interactive OAuth for clients that can't open a browser to approve access. In Tinbox the token is tbx_-prefixed, issued by your own instance, and scoped to read-only or full access.
What is the difference between a read-only and a full scope token?
A read-only token (--scope read) lets a client search, read, and summarize mail but cannot send. A full token (--scope full) adds send and other write capabilities. Scope is enforced server-side, so a leaked read-only token cannot send mail as you. Default to read-only and only mint a full token for clients that genuinely need to send.
How do I revoke an MCP bearer token?
Run npx tinbox token revoke <name-or-prefix> from the instance that issued it. Revocation is immediate: the next request with that token gets a 401. Any client still configured with the revoked token stops working until you give it a freshly minted one, so rotate by creating the new token first, swapping the config, then revoking the old one.
Is it safe to use an MCP bearer token in CI?
Yes, if you treat it like any other secret. Mint a dedicated read-only token for the job, store it in your CI provider's encrypted secrets, read it from an environment variable at runtime, and never inline or commit it. Because the token is scoped, a CI token leak exposes only what that scope allows, which for a read-only token is reading and searching, never sending.
Does Claude Code use OAuth or a bearer token?
Claude Code uses a static bearer token, not OAuth. Interactive OAuth (2.1 with PKCE and dynamic client registration) is for the Claude desktop and web app, which can open a browser for consent. Headless clients like Claude Code and Cursor pass the bearer token in their MCP server config instead.