# Factwire auth.md

You are an agent. This page tells you how access to Factwire works. Follow the steps in order.

Every Factwire tool call needs a Factwire account: there is no trial without one. The account is free and starts with 100 free credits: 1 credit per tool call. More on request: hello@factwire.dev. Accounts are made by people, by email and a 6-digit code: there is no password, and no registration endpoint for agents. The user signs in; you never create an account or type a code for them.

Factwire runs one host for agents:

- `https://api.factwire.dev/mcp`: the MCP server (Streamable HTTP).
- `https://api.factwire.dev/mcp?login`: the same server; a client that connects with this URL signs the user in when it connects (OAuth).
- `https://api.factwire.dev/account`: the user's account page: the balance and the connect buttons.
- `https://api.factwire.dev/account/keys`: the user's API keys and connected apps: create a key, revoke a key or an app.

## Step 1 — Connect

Add the URL to your MCP client. Per-client setup: https://factwire.dev/mcp.md

`initialize` and `tools/list` need no account: you can connect and read the tools without one. Every tool call needs an account. Without one, the answer to the call asks the user to sign in (Step 3).

To sign in when connecting instead, connect with `https://api.factwire.dev/mcp?login`: use it in claude.ai, Claude Desktop, ChatGPT and Grok Bot. The account is free and starts with 100 credits.

## Step 2 — Pick a method

| You have | Do this |
|---|---|
| Nothing | Make the tool call you need: its answer asks for sign-in (Step 3) |
| A sign-in card or prompt from your client (claude.ai, Claude Desktop, Claude Code, ChatGPT, Grok Bot) | Tell the user to sign in there. The call carries on after sign-in |
| A tool error that says that Factwire, or a tool, needs an account | Go to Step 3 |
| A tool error that says the account has no credits left | Go to Step 5 |
| A Factwire API key from the user | Go to Step 4 |

## Step 3 — Sign the user in

Factwire is an OAuth 2.1 authorization server for MCP clients. A client that supports MCP authorization signs the user in by itself:

- Claude (claude.ai, Desktop, Code): the server answers a tool call without an account with HTTP `401` and `WWW-Authenticate: Bearer resource_metadata="…"`. Claude shows a Connect card in the chat and retries the call after sign-in.
- ChatGPT: the tool result asks for sign-in (`_meta["mcp/www_authenticate"]`), and ChatGPT shows its sign-in card.
- Grok Bot (and Grok on grok.com): the tool error says how to connect again with `https://api.factwire.dev/mcp?login`; Grok Bot signs in when it connects.
- Any other client: the tool error names the sign-in page, `https://api.factwire.dev/signin`. Then connect again with `https://api.factwire.dev/mcp?login`, which signs in when connecting.

The user signs in with their email and a 6-digit code that Factwire emails them; the same step creates the account. The client gets an access token, which works until the user revokes it at https://api.factwire.dev/account/keys.

A client that cannot sign in (no OAuth support): ask the user for an API key. The user signs in at https://api.factwire.dev/account/keys and creates one there; it spends the account's credits. Go to Step 4.

Discovery, for client developers:

- Protected resource metadata (RFC 9728): `https://api.factwire.dev/.well-known/oauth-protected-resource/mcp`
- Authorization server metadata (RFC 8414): `https://api.factwire.dev/.well-known/oauth-authorization-server`
- Authorization code with PKCE (S256) only, public clients only. Dynamic Client Registration at `https://api.factwire.dev/oauth/register`, or a Client ID Metadata Document URL as the `client_id`. Redirect URIs: Claude's, ChatGPT's and Grok Bot's callbacks (Grok Bot's are Cursor's web callbacks; also grok.com and console.x.ai), loopback (`http://localhost`, `http://127.0.0.1`), Cursor and VS Code.

## Step 4 — Use an API key

Send the key as a bearer token in the `Authorization` header of every request:

```http
POST https://api.factwire.dev/mcp
Authorization: Bearer factwire_v1_…
Content-Type: application/json
Accept: application/json, text/event-stream
```

Per-client setup: https://factwire.dev/mcp.md#with-a-key

Keep the key safe:

- Keep the key in an environment variable, such as `FACTWIRE_API_KEY`, or in your client's secret store.
- Never write the key into a file in a project, a commit, a log or a chat message.
- Never put the key in a URL.
- Never invent a key and never reuse one from another user. Keys start with `factwire_v1_`.

## Step 5 — Credits

Each tool call of an account takes 1 credit. A new account starts with 100 free credits. A call that fails costs nothing. When they are used up, the tool error says so and names the account page. Tell the user: they can see the balance at https://api.factwire.dev/account and ask for more at hello@factwire.dev.

## Errors

| Error | What to do |
|---|---|
| HTTP `401` with `WWW-Authenticate: Bearer resource_metadata="…"` and no key sent | Sign-in is asked for: let your client run it (Step 3) |
| A tool error that says that Factwire without an account is paused, or that a tool needs an account | Have the user sign in (Step 3) |
| A tool error that says the account has no credits left | Step 5 |
| `401` after you sent a Factwire key | The key is not valid or was revoked. Drop it and ask the user for a new one, or have the user sign in (Step 3). Do not retry with the same key |

A `401` to a key that is not valid looks like this, and its `Link` header points here:

```http
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="factwire", error="invalid_token"
Link: <https://factwire.dev/auth.md>; rel="help"
```

A token that does not start with `factwire_v1_`, or an empty one, counts as no key.

## Revocation

The user revokes a key or a connected app on the account page, and the Factwire team can revoke any key; a revoke applies at once. There is no refresh flow: an access token from sign-in is a key of the account and works until it is revoked.

## What access covers

The register tools are read-only: nothing in the register can be written or deleted, and no tool call can pay for anything. One tool writes: `submit_feedback` sends a report about a problem with the tools to the Factwire team, written by the agent in generic words. It costs no credits.

Factwire records each tool call in its log and as an event in its product analytics (PostHog): the caller, the tool, its input and the outcome. Never the result. The caller is the account, the key or, without a key, a salted hash of the IP address; the address itself is not recorded. The log never has an account's email. The analytics event of an account's call does, so that the team sees which account called. The team reads the inputs to improve the tools. No tool asks for the user's goal or for the conversation.

A `submit_feedback` call is recorded without its input: the report is in no log line and not in the event of the call. Factwire refuses a report that holds what looks like an e-mail address, a register number, a date, a long number or a key. The report goes to the same analytics service as an event of its own, with its category and severity, the tool and the register_key it names (if any), the use case if the agent gave one (one of `due_diligence`, `sales_prospecting`, `kyc_compliance`, `research`, `other`: a fixed choice, never free text; Factwire reads it to learn what the tools are used for), the server version, the client's name and the caller's id as above. That event does not carry the email; for an account, the id is the one the analytics knows the account by. The tool answers `queued` when Factwire has accepted the report for delivery, which does not confirm that the team received or stored it.
