# MCP OAuth for remote servers, explained with a real server's metadata

> What happens between a coding agent and a remote MCP server before the first tool call: the 401, protected resource metadata, authorization server discovery, client registration, PKCE and the resource parameter. Walked through with the documents a live server publishes, and what a team should check before approving a connector.

What happens between a coding agent and a remote MCP server before the first tool call: the 401, protected resource metadata, authorization server discovery, client registration, PKCE and the resource parameter. Walked through with the documents a live server publishes, and what a team should check before approving a connector.

December 2, 2026 · 5 min read · The Sandscale team

When someone on your team adds a remote MCP server to Claude Code, Codex, Cursor or Gemini CLI, a browser opens, they sign in, and the tools appear. Several standards are doing work in those few seconds, and each one answers a question a team cares about: who is this client, what may it do, and which server is the token for.

This post walks through the flow in the [MCP authorization specification](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization) (version 2025-11-25), using the documents Sandscale’s remote MCP server publishes as the worked example. Anything quoted from that server below is what it returned when we requested it on 2 December 2026.

## First: this only applies to remote servers

The specification says HTTP-based transports should follow it, and stdio servers should not: a stdio server gets its credentials from the environment it was started in. So OAuth is the story for remote servers over Streamable HTTP. A local server started by the agent, such as `sandscale mcp`, signs in however its own CLI signs in. We compared the two transports in [MCP over stdio or Streamable HTTP](https://sandscale.dev/blog/mcp-stdio-vs-streamable-http).

## Step 1: the server says “not without a token”

The client sends its first request with no token. The server answers `401 Unauthorized` with a `WWW-Authenticate` header that points at its metadata. Sandscale’s server answers a token-less request to `https://mcp.sandscale.dev/mcp` with:

```text
WWW-Authenticate: Bearer resource_metadata="https://mcp.sandscale.dev/.well-known/oauth-protected-resource/mcp", scope="mcp"
```

Two things are in there. `resource_metadata` tells the client where to read about this server. `scope` tells it which scope to ask for. The specification says clients should use the challenged scope first, and fall back to the metadata’s `scopes_supported` only when the header has none.

## Step 2: protected resource metadata (RFC 9728)

The client reads that document. Every MCP server that does authorization must publish one, and it must list at least one authorization server. Sandscale’s says:

```json
{"resource":"https://mcp.sandscale.dev/mcp","authorization_servers":["https://auth.sandscale.dev"],"scopes_supported":["mcp","offline_access"],"bearer_methods_supported":["header"],"resource_name":"Sandscale","resource_documentation":"https://sandscale.dev/docs/reference/mcp"}
```

The important field for security is `resource`: it is the server’s canonical address, and it comes back in step 5. `bearer_methods_supported` says tokens go in the `Authorization` header, not in a query string.

## Step 3: find the authorization server’s endpoints

The client then reads the authorization server’s own metadata, from OAuth 2.0 Authorization Server Metadata (RFC 8414) or OpenID Connect Discovery. The specification requires clients to support both. For Sandscale, `https://auth.sandscale.dev/.well-known/oauth-authorization-server` lists the authorization, token and revocation endpoints, `code_challenge_methods_supported` with `S256`, `client_id_metadata_document_supported` set to `true`, and a `registration_endpoint`.

That PKCE field is not decoration. The specification says that if `code_challenge_methods_supported` is missing, the client must refuse to continue.

## Step 4: who is the client?

An authorization server has to know which app is asking. MCP has three ways to answer, and clients that support all of them should try them in this order:

1. **Pre-registration.** The client already has a client ID for this server.
2. **Client ID Metadata Documents.** The client’s ID is an HTTPS URL that serves a JSON document with its name and redirect URIs. The server fetches it and checks the redirect URI against it. This is the approach the specification recommends for the common case where client and server have never met.
3. **Dynamic Client Registration (RFC 7591).** The client registers itself at the server’s registration endpoint. The specification keeps this for backwards compatibility.

Sandscale’s authorization server advertises the second and third, so clients that do either can connect.

For a team, the useful consequence is on the consent page. The specification requires the authorization server to show the redirect URI’s host during authorization. Sandscale’s approval page names the app and says it is not made by Sandscale. Teach people to read that page: a connector they did not expect, or a redirect to a host they do not recognize, is a reason to cancel.

## Step 5: the authorization request, with PKCE and a resource

The client opens the browser with an authorization code request. Two parameters matter:

- **PKCE.** The client makes a random verifier, sends its `S256` hash as `code_challenge`, and later proves it holds the verifier when it exchanges the code. Someone who intercepts the code cannot use it.
- **`resource` (RFC 8707).** The client must name the server it wants a token for: the canonical address from step 2. The token that comes back is bound to that server.

The person signs in and approves. The client exchanges the code for an access token, and, if it asked for `offline_access`, a refresh token.

## Step 6: every call carries the token, and the server checks it

From here, each MCP request carries `Authorization: Bearer <token>`. The specification puts two duties on the server that are worth knowing as a buyer:

- It must accept only tokens issued for itself, checking the audience, and reject the rest.
- It must not pass the client’s token through to other APIs. If it calls an upstream service, it uses a separate token for that.

Later, a call that needs more than the token allows gets `403` with `error="insufficient_scope"`, and a client acting for a person should go back through authorization for the larger scope (the specification calls this step-up).

## What a team should check

The protocol gives you a person-bound, server-bound token. It does not decide your policy. Before you approve a remote MCP server for the team, ask:

- **Does each person sign in as themselves?** A shared account defeats the audit trail. With OAuth, the config file can be committed with no secret in it, and every client signs in separately.
- **What can the token do?** Look at the scopes the server asks for and what its tools change. Our post on [MCP tool annotations](https://sandscale.dev/blog/mcp-tool-annotations-explained) covers deciding what to auto-approve.
- **How is access removed?** When someone leaves, revoking their sign-in should end their connectors too. Ask whether a person can revoke one app without signing out of everything.
- **What is recorded?** The server, not the client, is where a durable record belongs.
- **Are there limits per app and per person?** A looping agent should hit a limit before it hits your bill.

For Sandscale’s [remote MCP server](https://sandscale.dev/sandboxes/mcp), the docs answer those: each call runs as the person who approved it, with a short-lived credential that never leaves the server; each app can make up to 120 calls a minute and each person up to 60; every call is in the organization’s audit log with the tool, the region, the outcome and the app, never the arguments; and a person can revoke one connector with `DELETE /api/v1/me/mcp-connectors/{id}`, which ends that app’s sessions at once.

## Reading a server’s metadata yourself

You do not need a client to look at any of this. Two requests show what a remote MCP server expects:

```sh
curl -si -X POST https://mcp.sandscale.dev/mcp -H 'Content-Type: application/json' -d '{}' | grep -i www-authenticate
curl -s https://mcp.sandscale.dev/.well-known/oauth-protected-resource
```

Point them at any remote server your team is considering. A server that has no protected resource document, or whose authorization server lists no `S256`, is one a conforming client should refuse to sign in to.

**On this page**

1. First: this only applies to remote servers
2. Step 1: the server says “not without a token”
3. Step 2: protected resource metadata (RFC 9728)
4. Step 3: find the authorization server’s endpoints
5. Step 4: who is the client?
6. Step 5: the authorization request, with PKCE and a resource
7. Step 6: every call carries the token, and the server checks it
8. What a team should check
9. Reading a server’s metadata yourself

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [December 2, 2026 · **Auditing the MCP tool calls your team's coding agents make** · When Claude Code, Codex, Cursor or Gemini CLI call MCP tools, the record of what happened can live in three places: the client, the MCP server, and the system behind it. What each layer can see, which one to trust as the record, whether to keep arguments, and how to read Sandscale's audit log for agent calls from the CLI.](https://sandscale.dev/blog/auditing-mcp-tool-calls)
- [December 2, 2026 · **Device flow login on headless machines: signing a coding agent's machine in as a person** · An agent's cloud machine has no browser, so a CLI there cannot open a sign-in page. The OAuth device authorization grant (RFC 8628) solves that: a short code you approve on your phone or laptop. How it works, the one phishing risk to teach your team, and how to use sandscale login --device on each agent's machine.](https://sandscale.dev/blog/device-flow-login-on-headless-machines)

---
Source: https://sandscale.dev/blog/mcp-oauth-for-remote-servers-explained
