# MythWeaver auth.md

You are an agent. MythWeaver supports **agentic registration**: discover, then
register, then have the person approve, then collect an access token and call
the MCP server. Follow the steps in order.

- Resource: `https://mcp.mythweaver.co/mcp` (the MythWeaver MCP server, Streamable HTTP)
- Authorization server: `https://api.mythweaver.co`

## Who this is for

Agents and AI tools (Claude, ChatGPT, Cursor and anything else that speaks MCP)
acting for a person who already has a MythWeaver account. Every connection acts
as that person and needs their approval, on a MythWeaver page, while signed in.
MythWeaver does not give agents accounts of their own and does not register
anonymous agents. Accounts are for people: `https://app.mythweaver.co/auth/signup`.

Connecting is invite only while we test it, so some accounts can't approve a
connection yet. The approval page says so when that's the case.

## Step 1: Discover

Call the MCP server with no credentials. The 401 points at the protected
resource metadata:

```http
POST /mcp HTTP/1.1
Host: mcp.mythweaver.co

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="mythweaver", resource_metadata="https://mcp.mythweaver.co/.well-known/oauth-protected-resource/mcp"
```

That document names the authorization server. Its metadata, at
`https://api.mythweaver.co/.well-known/oauth-authorization-server`, carries
both the standard OAuth fields and the `agent_auth` block:

```json
{
  "issuer": "https://api.mythweaver.co",
  "authorization_endpoint": "https://api.mythweaver.co/v1/oauth/authorize",
  "token_endpoint": "https://api.mythweaver.co/v1/oauth/token",
  "registration_endpoint": "https://api.mythweaver.co/v1/oauth/register",
  "revocation_endpoint": "https://api.mythweaver.co/v1/oauth/revoke",
  "grant_types_supported": ["authorization_code", "urn:workos:agent-auth:grant-type:claim"],
  "code_challenge_methods_supported": ["S256"],
  "token_endpoint_auth_methods_supported": ["none"],
  "scopes_supported": ["mcp"],
  "agent_auth": {
    "skill": "https://mythweaver.gg/auth.md",
    "identity_endpoint": "https://api.mythweaver.co/v1/agent/identity",
    "claim_endpoint": "https://api.mythweaver.co/v1/agent/identity/claim",
    "identity_types_supported": ["service_auth"]
  }
}
```

## Step 2: Pick a method

| You have | Use |
| --- | --- |
| Only the person's email | [service_auth](#step-3a-register-with-the-persons-email-service_auth). They approve by typing a code you give them |
| A Connect button or a browser you can open (claude.ai, ChatGPT, MCP Inspector, desktop apps) | [OAuth authorization code with PKCE](#step-3b-register-an-oauth-client) |
| A config file that can send a header (Claude Code, Cursor) | [A key the person pastes in](#a-key-the-person-pastes-in) |

Not supported: `anonymous` (answers `anonymous_not_enabled`) and
`identity_assertion` with an ID-JAG (answers `issuer_not_enabled`: MythWeaver
trusts no outside identity provider yet).

## Step 3a: Register with the person's email (service_auth)

Before you send this, tell the person you're about to ask MythWeaver to
connect to their account, and confirm the email.

```http
POST /v1/agent/identity HTTP/1.1
Host: api.mythweaver.co
Content-Type: application/json

{ "type": "service_auth", "login_hint": "person@example.com", "agent_name": "Your agent" }
```

`agent_name` is optional (it's our extension); the connection is labelled with
it, or "AI agent". The pre-0.6 body
`{"type":"identity_assertion","assertion_type":"verified_email","assertion":"person@example.com"}`
is accepted too.

Response (200). It's the same whether or not the email has an account.

```json
{
  "registration_id": "reg_...",
  "registration_type": "service_auth",
  "claim_url": "https://api.mythweaver.co/v1/agent/identity/claim",
  "claim_token": "clm_...",
  "claim_token_expires": "2026-10-01T19:06:51.696Z",
  "post_claim_scopes": ["mcp"],
  "claim": {
    "user_code": "599654",
    "expires_in": 600,
    "verification_uri": "https://app.mythweaver.co/connect/claim?claim_attempt_token=...",
    "interval": 5
  }
}
```

`claim_token` is returned once. Hold it in memory until Step 4 is done; don't
persist it. MythWeaver sends no email: you hand the link and code to the person.

## Step 4: Claim ceremony

### 4a. Materials

You already have them, in the `claim` block above. If the code runs out
(`expired_token` while polling) or the person typed it wrong five times, ask
for a fresh one with the same `claim_token`:

```http
POST /v1/agent/identity/claim HTTP/1.1
Host: api.mythweaver.co
Content-Type: application/json

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

```json
{
  "registration_id": "reg_...",
  "claim_attempt_id": "cla_...",
  "status": "initiated",
  "expires_at": "...",
  "claim_attempt": {
    "user_code": "123456",
    "expires_in": 600,
    "verification_uri": "https://app.mythweaver.co/connect/claim?claim_attempt_token=...",
    "interval": 5
  }
}
```

Only the newest code works. A registration lasts 24 hours and 20 codes.

### 4b. Hand off to the person

Give them the link and the code in one message, for example:

> Open this link, sign in to MythWeaver, and type this 6-digit code: **599654**
> https://app.mythweaver.co/connect/claim?claim_attempt_token=...

They must be signed in as the email you registered with. The page tells them
if they're signed in as someone else and lets them switch.

### 4c. Poll for completion

```http
POST /v1/oauth/token HTTP/1.1
Host: api.mythweaver.co
Content-Type: application/x-www-form-urlencoded

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

While waiting you get `authorization_pending`. Honour `interval`; faster than
that gets `slow_down`. On success, exactly once:

```json
{ "access_token": "mw_mcp_...", "token_type": "Bearer", "scope": "mcp" }
```

There is no identity assertion, no JWT-bearer grant and no refresh token. The
access token doesn't expire, so there is nothing to refresh. It lasts until the
person disconnects it in account settings, under Your AI tools, or you revoke it.

Go to [Step 5](#step-5-use-the-access-token).

## Step 3b: Register an OAuth client

Registration is open (RFC 7591). Every client is a public client with no
secret; PKCE binds the code to you.

```http
POST /v1/oauth/register HTTP/1.1
Host: api.mythweaver.co
Content-Type: application/json

{
  "client_name": "Your agent",
  "redirect_uris": ["https://agent.example.com/oauth/callback"],
  "token_endpoint_auth_method": "none",
  "grant_types": ["authorization_code"],
  "response_types": ["code"]
}
```

Redirect addresses must be https, or http on `localhost` or `127.0.0.1` (any
port). The name you register is shown to the person next to the host of your
redirect address.

Then send the person's browser to the authorization endpoint:

```http
GET /v1/oauth/authorize?response_type=code&client_id=mwc_...&redirect_uri=https%3A%2F%2Fagent.example.com%2Foauth%2Fcallback&code_challenge=<S256 challenge>&code_challenge_method=S256&scope=mcp&state=<random>&resource=https%3A%2F%2Fmcp.mythweaver.co%2Fmcp HTTP/1.1
Host: api.mythweaver.co
```

They sign in if they need to and choose Allow or Cancel. You get them back
with `code`, `state` and `iss=https://api.mythweaver.co`, or with
`error=access_denied`. Exchange the code:

```http
POST /v1/oauth/token HTTP/1.1
Host: api.mythweaver.co
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=<code>&client_id=mwc_...&redirect_uri=https%3A%2F%2Fagent.example.com%2Foauth%2Fcallback&code_verifier=<verifier>&resource=https%3A%2F%2Fmcp.mythweaver.co%2Fmcp
```

```json
{ "access_token": "mw_mcp_...", "token_type": "Bearer", "scope": "mcp" }
```

Codes last ten minutes and work once. Using one twice is refused and also
disconnects the connection it made, in case it leaked.

### A key the person pastes in

The person signs in to MythWeaver, opens account settings and creates a
connection under Your AI tools. MythWeaver shows the key once and they paste
it into your config. It's the same kind of credential as the access tokens
above.

## Step 5: Use the access token

Send it on every MCP request as `Authorization: Bearer <access_token>` to
`https://mcp.mythweaver.co/mcp`.

- It acts as the person who approved it: it can do anything they can do in
  MythWeaver, and every change is saved as theirs.
- Limits are 120 calls and 40 writes a minute per connection. A 429 carries a
  Retry-After header.
- A 401 with `error="invalid_token"` means the person disconnected you or the
  token was copied wrong. Start again at Step 2.

## Errors

| Code | Where | What to do |
| --- | --- | --- |
| `anonymous_not_enabled` | `/v1/agent/identity` | Use service_auth with the person's email |
| `issuer_not_enabled` | `/v1/agent/identity` | Use service_auth with the person's email |
| `invalid_login_hint` | `/v1/agent/identity`, `/claim` | Send a plain email address |
| `invalid_request` | any | Fix the body; the description says what's wrong |
| `rate_limited` (429) | `/v1/agent/identity` | Wait for `Retry-After` |
| `invalid_claim_token` (401) | `/claim` | Register again |
| `claimed_or_in_flight` (409) | `/claim` | The person already decided; poll for the answer |
| `claim_expired` (410) | `/claim` | Register again |
| `authorization_pending` | token, claim grant | Keep polling at `interval` |
| `slow_down` | token, claim grant | Add 5 seconds to your interval |
| `expired_token` | token, claim grant | Ask `/claim` for a fresh code |
| `access_denied` | token, claim grant; OAuth redirect | The person said no. Don't retry unasked |
| `invalid_grant` | token | Code or claim_token is unknown, used, expired, or doesn't match. Start again |
| `invalid_target` | authorize, token | `resource` must be `https://mcp.mythweaver.co/mcp` |
| `invalid_redirect_uri` | `/v1/oauth/register` | Use https, or http on localhost |

A bad client_id or redirect address at the authorization endpoint shows the
person an error page and never redirects. The 401 body from the MCP server
also says, in words, what the person should do.

## Revocation

- **You:** `POST https://api.mythweaver.co/v1/oauth/revoke` with form body
  `token=mw_mcp_...&token_type_hint=access_token` (RFC 7009). Always an empty
  200, whether or not the token existed, and safe to repeat.
- **The person:** disconnects the tool in account settings, under Your AI
  tools. That ends it immediately, however it was made.

## Keeping it safe

Treat the token like a password. Don't log it, don't put it in a URL, and don't
send it anywhere except `mcp.mythweaver.co`. Never ask the person for their
MythWeaver password.
