> ## Documentation Index
> Fetch the complete documentation index at: https://docs.artificialstudio.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> How OAuth works with the Artificial Studio MCP server.

The MCP server uses **OAuth 2.1 with PKCE** — the same flow Claude Code and Cursor use for all their MCP integrations. You don't need an API key.

## The flow (first use)

**1. Client requests a tool**

Your AI client (Claude Code, Cursor, etc.) calls an MCP tool — say, `generate`.

**2. Server returns 401**

Without a valid Bearer token, the server returns `401 Unauthorized` with a `WWW-Authenticate` header pointing to the OAuth metadata.

**3. Client opens browser**

The client starts an OAuth flow: opens `https://app.artificialstudio.ai/connect` in your default browser with a PKCE challenge.

**4. You sign in and approve**

You sign in to Artificial Studio (if not already) and click **Authorize**. The browser redirects back to your AI client's localhost callback with an auth code.

**5. Client exchanges for token**

The client exchanges the code for a Bearer token and stores it locally. From here on, every MCP request includes `Authorization: Bearer <token>`.

## OAuth endpoints

The server exposes standard OAuth discovery metadata:

| Endpoint | Purpose |
| - | - |
| `/.well-known/oauth-protected-resource` | Resource metadata referenced from 401 responses |
| `/.well-known/oauth-authorization-server` | Authorization server metadata (endpoints, supported grants) |
| `/oauth/authorize` | Authorization endpoint (browser) |
| `/oauth/token` | Token endpoint (exchange code, refresh) |
| `/oauth/register` | Dynamic client registration (DCR) |

Supported grants:

* `authorization_code` (with PKCE — required)
* `refresh_token`

## Scopes

Current scopes granted:

* Read your account (credits, plan, profile)
* Read your generations
* Run generations (charges your credits like the dashboard)

## Token storage

Tokens are stored **by the client**, not by Artificial Studio:

* **Claude Code**: OS keychain / `~/.claude`
* **Cursor**: OS keychain
* **Claude Desktop** (via `mcp-remote`): `~/.mcp-auth/` directory

Revoking a token from our side is possible via [app.artificialstudio.ai/account](https://app.artificialstudio.ai/account) under **Connected apps** (coming soon).

## Redirect URIs

For native clients, the server's redirect URI whitelist accepts:

* `http://localhost:<port>/*`
* `http://127.0.0.1:<port>/*`

This is per [RFC 8252](https://datatracker.ietf.org/doc/html/rfc8252) — AI clients run a tiny local HTTP server during the OAuth dance to receive the code.

## Troubleshooting

> [accordion] Browser doesn't open on first use
>
> Some clients (especially in SSH / headless sessions) can't launch a browser. Copy the authorize URL from the client logs and open it manually on a machine where you're logged in — then paste the callback URL back into the client when prompted.

> [accordion] 'invalid\_token' after working for a while
>
> Your access token expired and the refresh failed. Remove the stored token and re-authenticate:
>
> * **Claude Code**: `claude mcp remove artificial-studio && claude mcp add --transport http artificial-studio https://api.artificialstudio.ai/mcp`
> * **Cursor**: remove the entry from `mcp.json`, restart, re-add.
> * **Claude Desktop (mcp-remote)**: `rm -rf ~/.mcp-auth/` and restart.

> [accordion] 'redirect\_uri mismatch'
>
> The port your client chose for the OAuth callback isn't accepted. Make sure you're on the latest version of your MCP client — old versions sometimes pick non-localhost URIs. If it persists, open a support ticket with the exact redirect\_uri from the error.

> [accordion] Multiple accounts
>
> Each machine / profile stores one token. To switch accounts, remove the stored token (see above) and re-authenticate with the other account.

## Next steps

> [card] [Tool reference](https://docs.artificialstudio.ai/mcp/tools.md)
>
> All 6 tools, their args, and responses.

> [card] [Async & polling](https://docs.artificialstudio.ai/mcp/async-polling.md)
>
> How to handle long-running generations.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.