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
- A Magic MCP server for the integration the job needs (set one up)
- Install
metorial-adminand sign in - A secret store in your CI system or scheduler
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.
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.
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:
Check the connection
Send an MCP initialize request. A 200 response means the token and URL are accepted.
To rotate, create a second token, update the secret in the job, then delete the old one:
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.
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:
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
- Whose identity does an agent act under?: how calls from tokens and service accounts are attributed
- One URL or one per server: the portal URL and per-server URLs
- Audit MCP tool calls: where each call is recorded