MetorialDocs

Give a scheduled job, CI pipeline or background agent MCP access

A job cannot do a browser sign-in. Create a Magic MCP token for one server with metorial-admin magic-mcp tokens create and send it as a bearer token.

A scheduled job, CI pipeline or background agent cannot complete a browser sign-in, so it authenticates with a token. Create a Magic MCP token for one server with metorial-admin magic-mcp tokens create, and send it as Authorization: Bearer to that server's URL.

What you'll learn

  • How to create a token for one Magic MCP server
  • How to call the server from a job
  • How to rotate the token and see what the job did

Before you start

With the CLI

Find the server

List your Magic MCP servers and copy the ID of the one the job needs. get prints the server, including the url of each of its endpoints.

metorial-admin magic-mcp servers list --search github
metorial-admin magic-mcp servers get <server-id>

Create a token for that server

The token only works for the server you link it to. The output contains its secret. Put that in your secret store.

metorial-admin magic-mcp tokens create \
  --name nightly-report \
  --description "Nightly report job" \
  --magic-mcp-server-id <server-id>

Configure the job

Send the token in the Authorization header. For an MCP client that reads a JSON config, such as Claude Code in a pipeline, have the job write this file at run time:

{
  "mcpServers": {
    "metorial": {
      "type": "http",
      "url": "<your-server-url>",
      "headers": {
        "Authorization": "Bearer <your-token>"
      }
    }
  }
}

Check the connection

Send an MCP initialize request. A 200 response means the token and URL are accepted.

curl -i -X POST "<your-server-url>" \
  -H "Authorization: Bearer <your-token>" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"ci-check","version":"1.0.0"}}}'

To rotate, create a second token, update the secret in the job, then delete the old one:

metorial-admin magic-mcp tokens list --magic-mcp-server-id <server-id>
metorial-admin magic-mcp tokens delete <magic-mcp-token-id>

For a personal script

A person can create a token for one of their own integrations with the metorial CLI. The job then acts as that person.

metorial list
metorial install custom <integration-id>

install custom creates an installation token and prints the endpoint details. metorial tokens list shows a person's active tokens, and metorial tokens revoke <token-id> ends one.

In the dashboard

In the portal, open Connect and select Manage tokens, then Create Client Token. Copy the token from the MCP Server Token Created dialog. The server's URL is the Primary Endpoint on the integration's Overview under My Integrations. A token created this way needs a server URL. It does not work on the portal-wide Magic MCP URL.

A job that is not tied to a person

Create a service account: in organization settings, open Access, Service Accounts, and select Create Service Account. Choose that it acts as a consumer of a portal and pick the portal. It gets its own profile there, and its access comes from that portal's access groups. Select Create Client Secret on the service account. The secret is shown once.

Agents you build on the API use an API key instead. metorial-admin api-keys create creates one. See Sessions.

Check it worked

Run the job, then list the server's sessions and the job's tool calls:

metorial-admin magic-mcp sessions list --magic-mcp-server-id <server-id>
metorial-admin sessions tool-calls list --search <tool-key> --limit 10

Troubleshooting

"Missing access token. Please provide a valid token in the "Authorization" header or as a "token" query parameter."

The request had no token. Check that the job's secret is set and that the header is Authorization: Bearer followed by the token.

"Magic MCP token or API key is required"

Same cause on a server URL that is not served through a portal.

"A server- or endpoint-specific portal route is required unless you use a target-linked magic MCP token"

A token that is not linked to a server was sent to the portal-wide Magic MCP URL. Use the server's URL.

"Magic MCP token does not have access to this target"

The token is linked to a different server, or the server is no longer active.

Next steps