# auth.md

Metals-API authenticates AI agents and API clients with **OAuth 2.1** (MCP) or an **API key**.

## Audience

Agents connecting to:

- REST API: `https://metals-api.com/api/*`
- MCP: `https://mcp.metals-api.com/mcp`

## MCP with OAuth (ChatGPT, claude.ai, Claude Desktop)

Add the MCP URL as a connector with no key. The server answers `401` with `WWW-Authenticate`, the client opens the Metals-API login, and the user approves access. The token uses the same plan and quota as the account's API key.

- Authorization: `https://metals-api.com/oauth/authorize`
- Token: `https://metals-api.com/oauth/token`
- Scope: `metals.api`
- Registration: `https://metals-api.com/oauth/register` (dynamic client registration, RFC 7591). Clients register themselves; there is no Client ID to copy.
- Public clients only, authorization code with PKCE (S256).

## API key

1. Create an account: [https://metals-api.com/register](https://metals-api.com/register)
2. Copy your access key from the dashboard
3. REST: pass `?access_key=YOUR_ACCESS_KEY` or send `Authorization: Bearer YOUR_API_KEY`. MCP: send `Authorization: Bearer YOUR_API_KEY`. Do not put the key in the MCP URL (`?api_key=` or `?apikey=`): Claude Desktop and claude.ai reject tokens in the query string.

## Methods

| Method | How |
|--------|-----|
| MCP OAuth | Connector URL `https://mcp.metals-api.com/mcp`, no key, sign in when prompted |
| MCP header | `Authorization: Bearer <key>` on `https://mcp.metals-api.com/mcp` (no key in the URL; do not use `npx` or `mcp-remote`) |
| REST query | `https://metals-api.com/api/latest?access_key=<key>` |
| REST header | `Authorization: Bearer <key or OAuth token>` on `https://metals-api.com/api/*` |

## Discovery

- OAuth Protected Resource: `/.well-known/oauth-protected-resource`
- Authorization Server metadata: `/.well-known/oauth-authorization-server`
- MCP Server Card: `/.well-known/mcp/server-card.json`
- Docs: [https://metals-api.com/mcp](https://metals-api.com/mcp)
