# Authenticating to QuantLogix

How an AI agent gets and uses a credential for QuantLogix (https://quantlogix.ai), including how it signs a person up. Sections follow the auth.md convention (https://github.com/workos/auth.md). Reading public pages, `https://quantlogix.ai/ask`, `https://quantlogix.ai/llms.txt` and the MCP `initialize` and `tools/list` calls needs no credential at all.

Every credential belongs to a person who approved it. There are no anonymous credentials and no agent-only accounts.

## Discover

- Protected resource metadata (RFC 9728): `https://quantlogix.ai/.well-known/oauth-protected-resource/api/mcp` for the MCP server, and `https://quantlogix.ai/.well-known/oauth-protected-resource` for the site as a whole (the document `https://quantlogix.ai/.well-known/poppy.json` relies on)
- Authorization server metadata (RFC 8414): `https://quantlogix.ai/.well-known/oauth-authorization-server`. Its `agent_auth` block names the `identity_endpoint` and `claim_endpoint` used below and lists `identity_types_supported`.
- MCP server cards: `https://quantlogix.ai/.well-known/mcp/server-card.json` (OAuth) and `https://quantlogix.ai/.well-known/mcp/api-key-server-card.json` (API key)
- A `tools/call` without a token answers `401` with `WWW-Authenticate: Bearer ... resource_metadata="https://quantlogix.ai/.well-known/oauth-protected-resource/api/mcp"`, which points back to the MCP server's document.

## Pick a method

| Situation | Method |
| --- | --- |
| You have the person's email and no browser redirect (a chat agent, a CLI, a server) | Agent registration, `service_auth`: you start it, the person signs in or signs up and types a code, you collect the credential. Start at Register. |
| An MCP client that can open a browser and receive a redirect | OAuth 2.1 authorization code with PKCE, against `https://quantlogix.ai/api/mcp`. See "Browser OAuth" at the end. |
| The person already has a `ql_` API key and gave it to you | Send it to `https://quantlogix.ai/api/mcp/v1` or the REST API under `https://quantlogix.ai/api/v1`. Nothing to register. |

`identity_types_supported` is `service_auth`. An `anonymous` registration answers `anonymous_not_enabled`. An `identity_assertion` (for example an ID-JAG, `urn:ietf:params:oauth:token-type:id-jag`) answers `issuer_not_enabled`: QuantLogix has no provider trust list.

## Register

Tell the person which service you are connecting and get their email, then:

```http
POST https://quantlogix.ai/api/mcp/auth/identity
Content-Type: application/json

{"type": "service_auth", "login_hint": "person@example.com", "client_name": "Your agent's name"}
```

Response (200):

```json
{
  "registration_id": "reg_...",
  "registration_type": "service_auth",
  "claim_url": "https://quantlogix.ai/api/mcp/auth/claim",
  "claim_token": "clm_...",
  "claim_token_expires": "2026-12-03T15:00:00.000Z",
  "post_claim_scopes": ["mcp:tools"],
  "claim": {
    "user_code": "123456",
    "expires_in": 600,
    "verification_uri": "https://quantlogix.ai/agent-claim?t=cat_...",
    "interval": 5
  }
}
```

`claim_token` is returned once. Keep it in memory for the ceremony and do not show it to the person. `client_name` is shown to them as the name you gave for yourself. QuantLogix sends the person no email: you hand them the link and the code.

## Claim

1. Show the person `claim.verification_uri` and `claim.user_code` in one message, for example: "Open this link, sign in or create your QuantLogix account, and enter this code: 123456".
2. They open the link. Someone new to QuantLogix creates an account there; someone with an account signs in. The account's verified email must be the `login_hint` you sent, so nobody else can complete it.
3. They see what you will and will not be able to do, type the code on that page (never back to you), and choose Connect or Deny.

A `user_code` lasts 10 minutes; the registration lasts 24 hours. If the code expires first, ask for a new one with the same `claim_token` and email:

```http
POST https://quantlogix.ai/api/mcp/auth/claim
Content-Type: application/json

{"claim_token": "clm_...", "email": "person@example.com"}
```

The response carries a `claim_attempt` block with a new `user_code` and `verification_uri`.

## Exchange

Poll the token endpoint every `interval` seconds with the claim grant:

```http
POST https://quantlogix.ai/api/mcp/auth/token
Content-Type: application/x-www-form-urlencoded

grant_type=urn:workos:agent-auth:grant-type:claim&claim_token=clm_...
```

While the person has not finished it answers `400` with `{"error": "authorization_pending"}`. When they have:

```json
{
  "access_token": "...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "mcp:tools",
  "identity_assertion": "<service-signed JWT>",
  "assertion_expires": "2027-01-01T15:00:00.000Z"
}
```

This answer is given once; the `claim_token` is then spent. Keep the `identity_assertion`: it is how you get the next access token, and it lasts 30 days.

```http
POST https://quantlogix.ai/api/mcp/auth/token
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=<identity_assertion>
```

There is no refresh token in this flow. When the assertion expires or is revoked the exchange answers `invalid_grant`: start again at Register.

## Use the access_token

- `Authorization: Bearer <access_token>` on requests to `https://quantlogix.ai/api/mcp`. Access tokens last about 60 minutes.
- A credential obtained by agent registration acts for the person on their plan: market data and research tools, and their plan, usage and billing status. It cannot read their saved portfolio or watchlists, and it cannot use the tools that read or change their CRM, Collab documents, QL Agents, agent mailbox and phone line, community, connected Google account, brokerage connection or saved credentials; it cannot set up webhooks or change their spend caps; and it never has admin access. Tools that analyse a portfolio work when you pass the holdings in the call. Those need the browser OAuth grant below. `tools/list` with your token shows exactly what you can call.
- On a free plan a paid tool says which plan it needs and offers pay-as-you-go: `start_pay_as_you_go` returns a card-setup link for the person to open. You never handle card details.
- An API key: `Authorization: Bearer ql_...` (or `X-API-Key: ql_...`) on `https://quantlogix.ai/api/mcp/v1` and `https://quantlogix.ai/api/v1/*`.

## Errors

| Code | Where | What to do |
| --- | --- | --- |
| `anonymous_not_enabled`, `issuer_not_enabled` | identity endpoint | Use `service_auth` with the person's email. |
| `service_auth_not_enabled` | identity and claim endpoints | Agent registration is switched off. Use Browser OAuth, or ask the person for an API key. |
| `invalid_request` | identity and claim endpoints | Fix the body: `type`, a valid `login_hint`, the same `email` on a claim restart. |
| `invalid_claim_token`, `claimed_or_in_flight` | claim endpoint | The token is wrong, or the registration is already claimed. Start again at Register if you hold no assertion. |
| `claim_expired` (410) | claim endpoint | The 24-hour window closed. Start again at Register. |
| `authorization_pending` | token endpoint, claim grant | Keep polling at `interval`. |
| `slow_down` | token endpoint, claim grant | Add at least 5 seconds to your interval. |
| `expired_token` | token endpoint, claim grant | The code expired. Ask the claim endpoint for a new one. |
| `access_denied` | token endpoint, claim grant | The person declined. Do not retry without asking them. |
| `invalid_grant` | token endpoint | Claim token spent, or assertion expired or revoked. Start again at Register. |
| `rate_limited` (429) | any | Wait `retry_after_s` seconds (also sent as `Retry-After`). |
| `401` on `https://quantlogix.ai/api/mcp` | resource | The access token expired or was revoked. Exchange the assertion once; if that fails, start again at Register. |
| `403`, or an MCP tool result marked as an error | resource | The plan does not include the tool, or the tool is outside what this credential may call ("not available to an agent connected with a code"). The message says which. Do not retry; your token is still valid. |

## Revocation

- You: `POST https://quantlogix.ai/api/mcp/auth/revoke` (RFC 7009) with `token=<access_token>` ends one access token; with `token=<identity_assertion>` it ends the whole registration and every access token minted from it.
- The person: `https://quantlogix.ai/agent-claim?manage=1` lists the agents connected to their account and disconnects any of them at once. Your next exchange then answers `invalid_grant`.
- API keys: the account owner revokes the key at `https://quantlogix.ai/profile` (API keys, Revoke). A revoked key cannot be restored.

## Browser OAuth

For a client that can open a browser and receive a redirect. Clients register themselves (RFC 7591), no pre-arranged client id is needed:

```http
POST https://quantlogix.ai/api/mcp/register
Content-Type: application/json

{"client_name": "Your agent", "redirect_uris": ["https://your-agent.example/callback"]}
```

1. Send the person to `https://quantlogix.ai/api/mcp/auth/authorize` with `response_type=code`, your `client_id`, `redirect_uri`, `state`, and a PKCE `code_challenge` (`code_challenge_method=S256`).
2. They sign in to QuantLogix, or create an account, and approve.
3. Exchange the returned `code` at `https://quantlogix.ai/api/mcp/auth/token` with `grant_type=authorization_code` and the `code_verifier`.

Scopes: `openid`, `email`, `mcp:tools`, `copilot:read`. Token endpoint authentication methods: `none`, `client_secret_post`. Refresh with `grant_type=refresh_token`; refresh tokens last 30 days and are single-use: each refresh returns a new one. This grant reaches the full tool set of the person's plan, including the workspace tools.

Data handling: `https://quantlogix.ai/data-handling`. Security contact: `https://quantlogix.ai/.well-known/security.txt`.
