Company-Scoped MCP Sessions

Mint a token restricted to a single company with the Tokens API, then use it to open a hosted MCP session that can only reach that company.

🚧

Early access

The Tokens API is enabled per organization. If it is not enabled for yours, the token endpoints respond as if they do not exist. Contact your Check representative to request access.

A Check API key acts as your whole partner account. When you connect the hosted Check MCP Server with an API key, the AI client can reach every company you manage. That is the right fit for an internal agent, but not for an assistant you hand to one employer.

The Tokens API solves this. You mint a short-lived token whose grant is restricted to one company and a controlled set of scopes, then pass that token's secret to the MCP endpoint in the Authorization header instead of your API key. The resulting session acts only within that company, and only within those scopes.

This guide covers the MCP side of that flow. For the Tokens API itself, including every minting rule, the full scope lists for each preset, and the error types, see the Tokens API guide.

How it works

  1. Call Create a token with your API key. The grant names the company and either a scope preset or an explicit scope list.
  2. Take the secret from the response. It is returned exactly once.
  3. Connect your MCP client to the hosted endpoint with Authorization: Bearer <secret>.
  4. Use the session. Every tool call the agent makes is executed as the token, so it cannot see other companies or exercise scopes it was not granted.
  5. Revoke the token when the session is over, or let it expire.

The hosted MCP server forwards the bearer credential to the Check API on every tool call. The server itself does not inspect the token; enforcement happens in the Check API, where a minted token is authenticated the same way as any other bearer credential.

Step 1: Mint a company-scoped token

From your backend, authenticate with your Check API key and call POST /tokens. Use the read_only preset for an inspect-only assistant, or read_write to let it make changes. Neither preset can approve a payroll or move money; those scopes must be named in an explicit scopes list. The Tokens API guide lists exactly what each preset contains.

curl -X POST https://sandbox.checkhq.com/tokens \
  -H "Authorization: Bearer your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "label": "Acme Co. assistant",
    "expires_at": "2026-12-02T18:30:00Z",
    "grants": [
      {
        "entity": { "type": "company", "id": "com_097YZQ" },
        "resource": null,
        "preset": "read_only"
      }
    ]
  }'

The response is the only time the secret is returned. It is an opaque 30-character string with no prefix. Store it where your agent can read it, and never log it.

{
  "id": "tok_abc123",
  "label": "Acme Co. assistant",
  "grants": [
    {
      "entity": { "type": "company", "id": "com_097YZQ" },
      "resource": null,
      "scopes": ["company:read", "employee:read", "..."]
    }
  ],
  "expires_at": "2026-12-02T18:30:00Z",
  "status": "active",
  "secret": "k3Vx9QmT2pLw8RzN5bHc1YfJ7sGd4A"
}

Three rules matter most for MCP sessions:

  • expires_at is capped at seven days ahead. Plan to mint a new token for each session, or on a schedule shorter than the expiry.
  • A token belongs to the environment it was minted in. Mint in sandbox for the sandbox MCP endpoint and in production for the production endpoint.
  • The grant can name an employee or contractor instead of a company. The same MCP flow applies, with the session restricted to that worker.

Step 2: Connect the MCP client with the token

Pass the secret as a bearer token on the connection to the hosted MCP endpoint, exactly as you would an API key. Use the sandbox endpoint for a sandbox token and the production endpoint for a production token.

EnvironmentURL
Sandboxhttps://mcp.sandbox.checkhq.com/check/mcp
Productionhttps://mcp.checkhq.com/check/mcp

Agents and server-to-server clients

This is the primary use case: an agent you run on your own infrastructure, acting on behalf of one employer. Mint the token in your backend, then open the MCP session with it.

from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

url = "https://mcp.sandbox.checkhq.com/check/mcp"
headers = {"Authorization": f"Bearer {COMPANY_TOKEN_SECRET}"}

async with streamablehttp_client(url, headers=headers) as (read, write, _):
    async with ClientSession(read, write) as session:
        await session.initialize()
        tools = await session.list_tools()

Claude Code (CLI)

claude mcp add --transport http check-acme https://mcp.sandbox.checkhq.com/check/mcp \
  --header "Authorization: Bearer <token secret>"

Because the token expires within seven days, you will need to re-add the server with a fresh secret when it lapses.

Other MCP clients

Any client that can send a custom header on a Streamable HTTP connection can use a minted token. Clients that only accept a URL and drive OAuth themselves, such as the ChatGPT and Gemini connectors, cannot. Those clients always act as the Console user who logged in.

Verify the session

A successful initialize does not prove the token is valid. The hosted server accepts the handshake for any well-formed bearer value and only checks the credential when the first tool call reaches the Check API. Confirm with a real tool call:

curl -sN https://mcp.sandbox.checkhq.com/check/mcp \
  -H "Authorization: Bearer <token secret>" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call",
       "params":{"name":"run_tool",
                 "arguments":{"tool_name":"get_company","arguments":{"company_id":"com_097YZQ"}}}}'

A revoked or expired token fails here with 401 and the error type authentication_failed. The message is Access token expired. in both cases, so do not rely on the message to tell a revoked token from an expired one. A tool that needs a scope the token does not hold fails with 403 and the error type permission_denied. A tool that targets another company fails with 404, the same as if the resource did not exist.

What the session can and cannot do

  • One company. Tools that take a company ID only succeed for the company in the grant. Tools that target another company return 404, the same as a resource that does not exist.
  • Filtered lists. List endpoints such as /companies and /employees return only resources that belong to the granted company. The agent sees a one-company account, not an empty one.
  • Only the granted scopes. The preset or scope list caps what the agent can do. A read_only token cannot create, update, approve, or delete anything, regardless of which tools the client exposes.
  • Cannot mint more tokens. A minted token cannot call the Tokens API, so a session cannot widen its own access.
  • Stackable with MCP access control. The access control headers still apply. For example, combine a read_write token with X-MCP-Toolsets: employees,payrolls to limit a writable session to specific toolsets.

Step 3: Revoke the token

Revoke a token as soon as the session is done, or when a credential may have leaked. Revocation is immediate. Any MCP session still using that secret fails on its next tool call with 401 and the message Access token expired.

curl -X POST https://sandbox.checkhq.com/tokens/tok_abc123/revoke \
  -H "Authorization: Bearer your-api-key-here"

Revoking an already-revoked token returns it unchanged. You can check a token's status at any time with Get a token; the response never includes the secret.

Example: an assistant for each employer

A common pattern is an assistant embedded in your product, where each employer talks to an agent that can only see their own payroll data.

  1. When an employer opens the assistant, your backend mints a read_only token for their company with an expires_at a few hours out.
  2. Your backend opens an MCP session with that token and runs the agent loop.
  3. When the employer closes the assistant, your backend revokes the token.

Each employer gets an isolated session, your API key never leaves your backend, and a leaked secret is bounded to one company, one scope set, and a short window.


Did this page help you?