These steps are written so Grok Bot can follow them on its own. The person only signs in to Trustline and approves. Trustline's MCP server is at https://trustline.app/api/mcp.
Pick one path. Path A needs the person at a browser for one sign-in. Path B works headless: the person only clicks a link in an email.
Path A: OAuth
Call AddMcpServer with the Trustline URL and no headers:tool call
Grok Bot starts its OAuth connect flow. Trustline registers Grok Bot as a public client (Dynamic Client Registration).
The person signs in to Trustline with a magic link sent to their email.
Trustline shows a consent screen: the app name (marked "Unverified app", since it registered itself), the permissions as checkboxes, and the workspace. The person ticks the permissions to grant and presses Allow.
The Trustline tools appear in the next message.
Access tokens last 1 hour; the client renews them with a refresh token for up to 30 days. If the connection is ever refused with 401, run the connect flow again.
Path B: headless self-onboarding
Use this when there is no browser in the loop. It is the OAuth device flow (RFC 8628) with an email link. Ask the person for their email address first.
Request a code. credential=api_key returns a scoped API key that does not expire:terminal
Tell the person: "Trustline sent you an email. Open the link, check that the code on the page is <user_code>, and press Approve." The link signs them in (it creates a free account only at that moment if they have none). The page shows the agent name, the code and the permissions as checkboxes. If the code does not match, they should press Deny.
Poll for the key every interval seconds (5):terminal
curl -s https://trustline.app/oauth/token \
-d grant_type=urn:ietf:params:oauth:grant-type:device_code \
-d device_code=<device_code>
# {"error":"authorization_pending"} wait interval seconds, then ask again
# {"error":"slow_down"} add 5 seconds to the interval
# {"error":"access_denied"} the person pressed Deny: stop
# {"error":"expired_token"} 15 minutes passed: start over
# {"access_token":"tlk_...","token_type":"Bearer","scope":"tl:read tl:create tl:send","credential":"api_key"}
As a loop:terminal
i=5
while :; do
r=$(curl -s https://trustline.app/oauth/token \
-d grant_type=urn:ietf:params:oauth:grant-type:device_code -d device_code="$DEVICE_CODE")
case "$r" in
*authorization_pending*) ;;
*slow_down*) i=$((i+5)) ;;
*) echo "$r"; break ;;
esac
sleep "$i"
done
Add the server with the key. The key is returned exactly once, so use it now:tool call
Without credential=api_key the token endpoint returns an OAuth access token (tlo_..., 1 hour) and a refresh token (tlr_..., 30 days, rotated on use) instead. Requests are form-encoded or JSON. Limits: 3 pending requests and 5 per hour per email, 10 per hour per IP address.
Check it works end to end
Send a test envelope to an inbox you can read: the person's address, or the agent's own. Replace <name> and <address>.
tool call
tl_create {"op":"create","args":{"title":"Trustline test","text":"This is a test document.","signers":[{"name":"<name>","email":"<address>"}],"send":true}}
// -> includes the envelope id (env_...) and a resource_link to trustline://envelopes/<id>
Read the status. It is sent now.
Open the email from Trustline and sign.
Read the status again until it is completed, then download the signed PDF and the audit certificate, and read the audit trail:
Clients on MCP 2026-07-28 can wait for events instead of polling status. Start with "cursor":null (from now), then pass back the cursor from each answer and wait nextPollMs between calls. Older clients keep polling tl_read status.
terminal
curl -s https://trustline.app/api/mcp \
-H "Authorization: Bearer <key>" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "MCP-Protocol-Version: 2026-07-28" \
-H "Mcp-Method: events/poll" \
-H "Mcp-Name: envelope.lifecycle" \
-d '{"jsonrpc":"2.0","id":1,"method":"events/poll","params":{
"name":"envelope.lifecycle","arguments":{"envelopeId":"<envelope id>"},"cursor":null,
"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}'
# -> {"result":{"events":[],"cursor":"c1...","truncated":false,"hasMore":false,"nextPollMs":15000}}
# Next call: the same request with "cursor":"<cursor from the last answer>", after nextPollMs.
# Each event: {"eventId":"<envelope id>.<seq>","name":"envelope.lifecycle","timestamp":"...",
# "data":{"envelopeId":"...","title":"...","status":"...","at":"...","signer":{"email":"...","name":"..."},"event":"envelope.signed"}}
Event types and push or webhook delivery are on the agent quickstart.
xAI API
The xAI API remote MCP tool sends a static token as the Authorization header and has no OAuth flow. Use an API key from Path B or from the dashboard under API & Agents. Add this to the tools array of your request:
Each tool needs one scope: tl:read for tl_read (and resources and events), tl:create for tl_create, tl:update for tl_update, tl:send for tl_send, tl:delete for tl_delete. tl_help works with any valid token. A call without the scope fails with 403 insufficient_scope.
The person sees the key, named after agent_name, in the dashboard under API & Agents and can revoke it there. OAuth connections are listed there under Connected apps. A token or key can never approve a send that needs a person's approval.