# Signing In to a Remote MCP Server

> A remote MCP server has to know whose account a request is for. The spec's answer is OAuth. The server's 401 says where to sign in, the client discovers the sign-in server from two public JSON files, you approve in a browser, and the client sends the token it gets back on every request. Below is that chain, with its discovery steps captured from Homing in production.

Page: https://tryhoming.com/learn/mcp/sign-in
Section: Learn
Updated: 2026-11-25

Lesson 4 of 4 in How MCP Works · 5 min

## Why Remote Servers Ask Who You Are

A local server runs as you, on your machine, so it already knows who you are. The spec tells stdio servers to skip sign-in and "retrieve credentials from the environment" instead.

A remote server takes requests from the whole internet. Homing at `https://api.tryhoming.com/mcp` has to put a note in your inbox and nobody else's, so every request must carry proof of whose it is. For HTTP servers, the spec's authorization chapter describes one way to get that proof: OAuth.

## Follow the Chain

Your client starts with one thing, the server's URL, and discovers the rest. Step through it; the discovery responses are real.

_Steps 2, 4 and 6 are captured from Homing in production on 2026-11-24, trimmed. The rest follows the 2026-07-28 spec, with values cut._

**Step 1, Client to MCP server: Any request.** The client sends its first MCP request with no token, because it doesn't have one yet.

**Step 2, MCP server to Client: 401 + metadata URL.** Refused, with directions. `resource_metadata` is where to read about this server; `scope` is what to ask for.

```http
HTTP/2 401
www-authenticate: Bearer resource_metadata="https://api.tryhoming.com/.well-known/oauth-protected-resource/mcp", scope="profile email"
```

**Step 3, Client to MCP server: GET resource metadata.** If the 401 had no header, the spec says to try the well-known paths: `/.well-known/oauth-protected-resource/mcp` first, then the root.

```http
GET /.well-known/oauth-protected-resource/mcp HTTP/1.1
```

**Step 4, MCP server to Client: Protected Resource Metadata.** An RFC 9728 document. The line that matters is `authorization_servers`: the server isn't the one that signs you in. It names who does.

```json
{
  "resource": "https://api.tryhoming.com/mcp",
  "authorization_servers": ["https://clerk.tryhoming.com"],
  "bearer_methods_supported": ["header"],
  "scopes_supported": ["profile", "email"],
  "resource_name": "Homing"
}
```

**Step 5, Client to Sign-in server: GET server metadata.** The issuer has no path, so the client tries `/.well-known/oauth-authorization-server`, then OpenID's `/.well-known/openid-configuration`.

```http
GET https://clerk.tryhoming.com/.well-known/oauth-authorization-server
```

**Step 6, Sign-in server to Client: Server metadata.** The client checks three things. `issuer` must match the URL it asked, or it must not use the document. `code_challenge_methods_supported` must exist, or the client refuses to go on. And how to register: this server supports Client ID Metadata Documents and offers no `registration_endpoint`, which suits a spec that deprecated dynamic registration in 2026-07-28.

```json
{
  "issuer": "https://clerk.tryhoming.com",
  "authorization_endpoint": "https://clerk.tryhoming.com/oauth/authorize",
  "token_endpoint": "https://clerk.tryhoming.com/oauth/token",
  "code_challenge_methods_supported": ["S256"],
  "client_id_metadata_document_supported": true,
  "response_types_supported": ["code"],
  …
}
```

**Step 7, Client to You: Opens your browser.** The client sends you to the authorize page. Its `client_id` is a URL where the client publishes who it is. `code_challenge` is a hash of a secret the client keeps (PKCE). `resource` names the MCP server the token is for.

```http
GET https://clerk.tryhoming.com/oauth/authorize
  ?response_type=code
  &client_id=https://client.example/oauth/metadata.json
  &redirect_uri=http://localhost:…/callback
  &code_challenge=…&code_challenge_method=S256
  &scope=profile%20email
  &resource=https://api.tryhoming.com/mcp
```

**Step 8, You to Sign-in server: Sign in, approve.** You sign in to Homing and approve this client. This is the only step where a person is involved, and the client never sees your password.

**Step 9, Sign-in server to Client: Code.** The sign-in server redirects back to the client with a one-time code. On its own the code is useless: whoever redeems it must also hold the secret behind `code_challenge`.

**Step 10, Client to Sign-in server: POST /oauth/token.** The client trades the code for a token, proving it's the same client with `code_verifier`, and names the resource again.

```http
POST https://clerk.tryhoming.com/oauth/token

grant_type=authorization_code&code=…&code_verifier=…
&redirect_uri=http://localhost:…/callback
&resource=https://api.tryhoming.com/mcp
```

**Step 11, Sign-in server to Client: Access token.** A token issued for one audience: Homing's MCP server. A refresh token may come with it, so you don't have to sign in again each time the access token expires.

**Step 12, Client to MCP server: Retry, with token.** The first request again, now with the token in the `Authorization` header. The spec says it goes on every request, and never in a URL.

```http
POST /mcp HTTP/1.1
Authorization: Bearer …
```

## What Each Check Stops

**PKCE.** The client hashes a secret into `code_challenge` and reveals the secret only when it redeems the code. A code stolen from a redirect is worthless without it. The spec makes PKCE mandatory and S256 the method.

**The `resource` parameter.** The client names the MCP server in both the authorize and the token request, and the server "MUST validate that access tokens were issued specifically for them." A token for one server can't be replayed at another, and a server "MUST NOT pass through the token it received" to anything else.

**The issuer check.** Metadata whose `issuer` differs from the URL the client built must not be used, so a planted document can't redirect your sign-in.

**Header only.** "Access tokens MUST NOT be included in the URI query string," where they would end up in logs and browser history.

## Scopes, and Asking for More

The client asks for the scopes in the 401's `scope`, here `profile email`, and only falls back to `scopes_supported` when the challenge names none. If a later call needs more, the server answers 403 with `insufficient_scope` and the scope it wants. The client asks again for the union of what it had and what's missing, with a limit on retries.

## API Keys

The authorization chapter only describes OAuth. Plenty of servers also accept a key, for clients that can't open a browser, such as a script on a server or a CI job. Homing does: a key from the app goes in the same `Authorization: Bearer` header, read from an environment variable rather than pasted into a config file.

A key skips discovery entirely, so it suits machines. It also skips your approval in a browser, so treat it like a password, and revoke it when the job ends. When a key is wrong, Homing's 401 carries no sign-in pointer: signing in wouldn't fix a bad key.

## Check Yourself

### 1. How does a client learn where to sign in?

- It's configured by hand for each server: It can be, but the spec makes it discoverable: the client needs only the server's URL.
- From the 401's header, then the metadata it points to (correct): Right. `resource_metadata` leads to a document that names the authorization server, whose own metadata has the endpoints.
- The MCP server signs you in itself: Usually not. Homing's metadata names a separate sign-in server.

### 2. An attacker intercepts the authorization code on its way back to the client. What stops them using it?

- The code expires in a year: Codes are short-lived, but that's not what makes a stolen one useless.
- PKCE: redeeming it needs the client's secret verifier (correct): Right. The code is bound to `code_challenge`, and only the client knows the secret behind it.
- The `scope` parameter: Scope limits what a token can do, not who can redeem a code.

### 3. Why does the client send `resource=https://api.tryhoming.com/mcp`?

- So the token is issued for that server, and only that server accepts it (correct): Right. The server checks the token's audience, so a token for one server can't be replayed at another.
- So the sign-in server knows where to redirect: That's `redirect_uri`.
- It's optional decoration: The spec says clients MUST send it, whether or not the sign-in server supports it.

### 4. Where does an access token go?

- In the URL, as `?access_token=`: Forbidden, because URLs end up in logs and history.
- In the `Authorization: Bearer` header of every request (correct): Right. Every request, header only.
- Only in the first request of a session: There may be no session at all. The token rides on every request.

## Questions

### How does OAuth work with MCP?

The server answers an unauthenticated request with 401 and a resource_metadata URL. The client reads that metadata to find the authorization server, reads its metadata, sends you to sign in with PKCE, trades the code for a token, and sends the token in the Authorization header on every request.

### Does MCP support API keys?

The MCP authorization spec only describes OAuth for HTTP servers. Many servers, Homing included, also accept an API key as a bearer token, for clients that can't open a browser.

### Do local MCP servers need OAuth?

No. The spec says servers on the stdio transport should not use it and should read credentials from the environment instead.

## Try It

Walk the first half of the chain yourself. Both documents are public; no key needed.

1. The server's metadata:

```bash
curl -s https://api.tryhoming.com/.well-known/oauth-protected-resource/mcp | jq
```

2. The sign-in server's metadata:

```bash
curl -s https://clerk.tryhoming.com/.well-known/oauth-authorization-server | jq '{issuer, code_challenge_methods_supported, client_id_metadata_document_supported, registration_endpoint}'
```

What you should see:

- 1: `authorization_servers` naming `https://clerk.tryhoming.com`.
- 2: `["S256"]`, `true`, and `null` for `registration_endpoint`: PKCE with S256, client metadata documents, no dynamic registration.

## Sources

- [MCP 2026-07-28: Authorization](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization)
- [Authorization server discovery](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization/authorization-server-discovery)
- [Client registration](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization/client-registration)
- [Security considerations](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization/security-considerations)
- [RFC 9728: OAuth 2.0 Protected Resource Metadata](https://www.rfc-editor.org/rfc/rfc9728)
- [RFC 8414: OAuth 2.0 Authorization Server Metadata](https://www.rfc-editor.org/rfc/rfc8414)
- [RFC 8707: Resource Indicators for OAuth 2.0](https://www.rfc-editor.org/rfc/rfc8707)
- [RFC 7636: PKCE](https://www.rfc-editor.org/rfc/rfc7636)

_Checked against the MCP specification 2026-07-28 and Homing's MCP server on 2026-11-25._

## For Agents and Search Engines

This lesson is also a page at https://tryhoming.com/learn/mcp/sign-in, listed in https://tryhoming.com/llms.txt, and described in structured data as LearningResource, BreadcrumbList, FAQPage. Its sources are listed above. We last checked the lesson against them on 2026-11-25.

## Put It to Use

[Connect Your Agent](https://tryhoming.com/guides/connect.md): Sign in from Claude Code, ChatGPT and other clients, or connect with an API key.
