# Deco My Tree auth.md

You are an agent. Deco My Tree (decomytree.link) lets an agent act for a tree owner once the owner says yes: register, have the owner claim you, trade your identity assertion for an access token, call the MCP server, and start over when access ends. Follow the steps in order.

What you can get is the scope `trees:read`: the owner's trees, their links and codes, how many gifts they have and when they open. Messages are never available to agents; only the owner reads them, on the website.

You don't need any of this to look up a tree or leave a message for the person you act for: the MCP server at https://decomytree.link/mcp and the API at https://api.decomytree.link/v1 work without signing in.

## Step 1 — Discover

- Protected resource metadata: `GET https://decomytree.link/.well-known/oauth-protected-resource`. The resource is `https://decomytree.link/`, the scope `trees:read`, and the token goes in the `Authorization` header.
- Authorization server metadata: `GET https://decomytree.link/.well-known/oauth-authorization-server`. Its `agent_auth` block lists the endpoints below.
- An MCP client that supports OAuth doesn't need this file: connect to https://decomytree.link/mcp/account, follow its 401 to the metadata, register at `https://decomytree.link/oauth/register`, and let the owner sign in on the consent page (authorization code with PKCE).

## Step 2 — Pick a method

1. You know the owner's email → `service_auth`.
2. You don't → `anonymous`, and ask for the email when you start the claim.
3. `identity_assertion` (ID-JAG) isn't accepted yet: you get `issuer_not_enabled`.

Before you register with someone's email, tell them what you'll see (their trees, never their messages) and get their OK.

## Step 3 — Register

```http
POST https://decomytree.link/agent/identity
Content-Type: application/json

{"type": "service_auth", "login_hint": "owner@example.com"}
```

The answer has `registration_id`, `claim_token` (shown once; keep it in memory until the claim is done), `claim_token_expires` (24 hours), `post_claim_scopes` and a `claim` block: `user_code` (6 digits), `verification_uri`, `expires_in` (600 seconds) and `interval` (5 seconds). Go to Step 4b.

```http
POST https://decomytree.link/agent/identity
Content-Type: application/json

{"type": "anonymous"}
```

The answer has `registration_id`, an `identity_assertion` with no scopes yet (`pre_claim_scopes` is empty), `claim_url`, `claim_token` and `post_claim_scopes`. Until the owner claims you, a token from it can't see any trees.

## Step 4 — Claim

### 4a. Start a claim attempt (anonymous only)

```http
POST https://decomytree.link/agent/identity/claim
Content-Type: application/json

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

The answer's `claim_attempt` block has the `user_code`, `verification_uri`, `expires_in` and `interval`. Call this again with the same body for a new code.

### 4b. Hand off to the owner

Send the link and the code in one message:

> Open this link, sign in to Deco My Tree with owner@example.com, and type this 6-digit code: **123456**
> https://decomytree.link/agent/claim?attempt=…

The code goes into the page, not back to you. Only that email can claim you, and five wrong codes end the attempt.

### 4c. Poll for completion

```http
POST https://decomytree.link/oauth/token
Content-Type: application/x-www-form-urlencoded

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

- `authorization_pending`: the owner hasn't finished; wait `interval` seconds and poll again.
- `expired_token`: the code ran out (10 minutes); start a new attempt (4a).
- 200: `access_token` (scope `trees:read`, one hour) and a new `identity_assertion` that lasts 30 days. The claim token works once.

## Step 5 — Exchange the assertion

```http
POST https://decomytree.link/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=<identity_assertion>&resource=https://decomytree.link/
```

The answer: `access_token`, `token_type` Bearer, `expires_in` 3600 and `scope`. Use the same assertion for new access tokens until it expires; there is no refresh token in this flow.

## Step 6 — Use the access token

```http
POST https://decomytree.link/mcp/account
Authorization: Bearer <access_token>
Content-Type: application/json
Accept: application/json, text/event-stream

{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "my_trees", "arguments": {}}}
```

Initialize first as with any MCP server. `tools/list` shows `get_tree`, `list_gifts`, `leave_message`, `days_until` and `my_trees`.

## Errors

| Code | Where | What to do |
| --- | --- | --- |
| `issuer_not_enabled` | /agent/identity | ID-JAG isn't accepted; use service_auth or anonymous |
| `invalid_login_hint` | /agent/identity | login_hint must be an email address |
| `invalid_claim_token` | /agent/identity/claim | Unknown claim token; register again |
| `claim_expired` (410) | /agent/identity/claim | The registration's 24 hours ran out; register again |
| `claimed_or_in_flight` (409) | /agent/identity/claim | Already claimed; poll the token endpoint |
| `authorization_pending` | /oauth/token | Keep polling every `interval` seconds |
| `expired_token` | /oauth/token | Start a new claim attempt |
| `invalid_grant` | /oauth/token | The assertion or claim token is expired, used or revoked; register again |
| `rate_limited` (429) | any | Wait a minute |

## Revocation

- `POST https://decomytree.link/oauth/revoke` with `token=<access_token>` (form-encoded) ends that access token; your identity assertion still works.
- Access ends for good after 30 days, when the owner changes their password or when their account is deleted. Then `/oauth/token` answers `invalid_grant`: start again at Step 3.

More: https://decomytree.link/developers
