# Agent sign-in for Dub

> Dub makes short links you can share and track: use your own domain, sort links into folders and tags, see clicks, leads and sales, and run a partner program. Dub's assistant does this for you when you ask in plain words, and asks you first before big changes like deleting links.

## Discover

- Authorization-server metadata: https://neutral-state-jev-dub-bench.vercel.app/.well-known/oauth-authorization-server (its `agent_auth` block names the endpoints below)
- identity_endpoint: https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/agent/identity
- claim_endpoint: https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/agent/identity/claim
- token_endpoint: https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/oauth/token

Errors are JSON with `error`; a 429 carries `retryAfterMs` and `Retry-After`.

## Sign in as an existing user

1. `POST https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/agent/identity` with `{"type":"service_auth","login_hint":"<the person's email>"}`.
2. Give the person `claim.verification_uri` and `claim.user_code`. They sign in on this app and type the code.
3. Poll `POST https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/oauth/token` (form-encoded) with `grant_type=urn:workos:agent-auth:grant-type:claim&claim_token=<claim_token>` every `interval` seconds. On `authorization_pending`, keep polling. On `slow_down`, add 5 s. On `expired_token`, start again.
4. On success: `access_token` (15 min) and `refresh_token` (30 days). Renew with `grant_type=refresh_token&refresh_token=<token>&client_id=<registration_id>`.

## Start without an account

1. `POST https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/agent/identity` with `{"type":"anonymous"}`.
2. Exchange `identity_assertion` at `POST https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/oauth/token` with `grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=<identity_assertion>&resource=https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/mcp`. The token lasts until `assertion_expires`, and the assertion can be exchanged again until then. Keep the `identity_assertion` and reuse it: there are at most 3 live trials per address, and a 429 says when one frees.
3. Trial limits:
   - Reads: all. Writes: only the tools the trial allows (their names are not published here).
   - Nothing needs approval during the trial; anything outside this list is refused with `TRIAL_NOT_ALLOWED`.
4. Hand over: `POST https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/agent/identity/claim` with `{"claim_token":"…","email":"<the person's email>"}`. Give the person `claim_attempt.verification_uri` and `claim_attempt.user_code`, then poll the claim grant as above. After the claim, the trial token stops working, and the next poll returns a token under the profile the person chose.
5. Unclaimed after 1 h, the trial account and what it made are deleted.

## Use the token

MCP:

```sh
claude mcp add --transport http --scope user app-dub-nsjev-cfe68eb1c605edfa8c089d72 https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/mcp --header "Authorization: Bearer $NEUTRAL_AGENT_TOKEN"
codex mcp add app-dub-nsjev-cfe68eb1c605edfa8c089d72 --url https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/mcp --bearer-token-env-var NEUTRAL_AGENT_TOKEN
```

HTTPS, one tool per request:

```sh
curl -sS -X POST https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/tools/<name> -H "Authorization: Bearer $NEUTRAL_AGENT_TOKEN" -H "content-type: application/json" -d '<arguments JSON>'
curl -sS -X POST https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/mcp -H "Authorization: Bearer $NEUTRAL_AGENT_TOKEN" -H "content-type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
```

## A person connecting their own agent

Connector URL: https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/mcp

- **claude.ai or Claude Desktop:** In Customize → Connectors, choose + Add → Add custom connector, paste the connector URL, then sign in when asked.
- **ChatGPT:** At chatgpt.com/plugins, choose + → Add custom MCP server and paste the connector URL under Connection.
- **Claude Code:** Then run /mcp in Claude Code and choose Authenticate.

  ```sh
  claude mcp add --transport http --scope user app-dub-nsjev-cfe68eb1c605edfa8c089d72 https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/mcp
  ```
- **Codex:** Then run codex mcp login app-dub-nsjev-cfe68eb1c605edfa8c089d72.

  ```sh
  codex mcp add app-dub-nsjev-cfe68eb1c605edfa8c089d72 --url https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/mcp
  ```
- **Cursor:** Add it to ~/.cursor/mcp.json, or .cursor/mcp.json for one project.

  ```json
  {
    "mcpServers": {
      "app-dub-nsjev-cfe68eb1c605edfa8c089d72": {
        "url": "https://neutral-state-jev-dub-bench.vercel.app/api/neutral-state/mcp"
      }
    }
  }
  ```
