# auth.md — agent access to Dental Art Studio (vipstomatolog.ru)

You are an agent. Dental Art Studio is a dental clinic in Moscow (Lomonosovsky prospekt 14),
in practice since 2003. Its public information is available to agents over:

- **MCP** (Streamable HTTP): `https://vipstomatolog.ru/mcp` — tools `get_clinic_info`, `search_pages`, `get_page`.
  Card: `https://vipstomatolog.ru/.well-known/mcp/server-card.json`
- **REST API** (OpenAPI 3.1): `https://vipstomatolog.ru/openapi.json` — `/api/v1/clinic`, `/api/v1/pages?q=…`
- **Markdown** of any page: request the page URL with `Accept: text/markdown`.

Everything is read-only public data. **Authentication is optional**: unauthenticated calls are
accepted. Authenticate if your platform requires OAuth or you want your requests to carry an
agent identity. The only scope is `clinic:read`.

## Discover

```http
GET /.well-known/oauth-protected-resource
GET /.well-known/oauth-authorization-server
```

The authorization server metadata carries the `agent_auth` block. Only `anonymous`
identities are supported.

## Option 1 — Anonymous agent registration

```http
POST /agent/identity
Content-Type: application/json

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

Response (200): `registration_id`, `identity_assertion` (RS256 JWT, valid 1 hour),
`assertion_expires`, `pre_claim_scopes: ["clinic:read"]`.

Exchange the assertion for an access token:

```http
POST /oauth/token
Content-Type: application/x-www-form-urlencoded

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

**Claiming is not offered.** The site has no user accounts, so there is nothing a person could
attach an agent to. `POST /agent/identity/claim` answers `400 claim_not_supported`. Anonymous
agents already hold the only scope.

## Option 2 — Client credentials (RFC 7591 + RFC 6749)

```http
POST /oauth/register
Content-Type: application/json

{ "client_name": "Your Agent", "grant_types": ["client_credentials"] }
```

Response (201): `client_id`, `client_secret`. Then:

```http
POST /oauth/token
Authorization: Basic base64(client_id:client_secret)
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
```

## Option 3 — Authorization code with PKCE (for MCP clients)

1. Register with `redirect_uris` (https, or http://localhost for native apps):
   `POST /oauth/register {"client_name": "...", "redirect_uris": ["https://…/callback"]}`
   → public client, `token_endpoint_auth_method: none`.
2. Open in the user's browser:
   `GET /oauth/authorize?response_type=code&client_id=…&redirect_uri=…&code_challenge=…&code_challenge_method=S256&state=…`
   The user sees a one-click consent screen (read access to public clinic information). On
   approval the browser is redirected with `code`, `state` and `iss`; on refusal with
   `error=access_denied`. The code is valid 5 minutes.
3. `POST /oauth/token` with `grant_type=authorization_code&code=…&redirect_uri=…&client_id=…&code_verifier=…`

## Use the token

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

{ "jsonrpc": "2.0", "id": 1, "method": "tools/list" }
```

An invalid or expired token gets `401` with `WWW-Authenticate: Bearer … resource_metadata=…`;
retry without the header or get a new token.

## Tokens

- Access tokens are RS256 JWTs, valid 1 hour, verifiable against `https://vipstomatolog.ru/.well-known/jwks.json`.
- No refresh tokens and no revocation endpoint: tokens are short-lived and grant read access to
  public data only. Get a new token when one expires.

## Errors

| Code | Where | What to do |
| --- | --- | --- |
| `unsupported_identity_type` | `/agent/identity` | Register with `{"type":"anonymous"}`. |
| `claim_not_supported` | `/agent/identity/claim` | Use the identity assertion as is. |
| `invalid_client` | `/oauth/token`, `/oauth/authorize` | Register again at `/oauth/register`. |
| `invalid_grant` | `/oauth/token` | Code, assertion or PKCE verifier is wrong or expired. Start again. |
| `unsupported_grant_type` | `/oauth/token` | Use a grant listed in the authorization server metadata. |
| `invalid_token` | `/mcp`, `/api/v1/*` | Retry without a token or get a new one. |

## For people

Medical questions, prices and appointment times: call the clinic, +7 (495) 972-21-87, or see
https://vipstomatolog.ru/kontaktyi.
