Skip to content

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.

View Markdown
On this page

Lesson 4 of 4 · 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.

You

Client

MCP server

Sign-in server

  1. 1 Any request

    The client sends its first MCP request with no token, because it doesn't have one yet.

  2. 2 401 + metadata URL

    Refused, with directions. resource_metadata is where to read about this server; scope is what to ask for.

    HTTP/2 401
    www-authenticate: Bearer resource_metadata="https://api.tryhoming.com/.well-known/oauth-protected-resource/mcp", scope="profile email"
  3. 3 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.

    GET /.well-known/oauth-protected-resource/mcp HTTP/1.1
  4. 4 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.

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

    The issuer has no path, so the client tries /.well-known/oauth-authorization-server, then OpenID's /.well-known/openid-configuration.

    GET https://clerk.tryhoming.com/.well-known/oauth-authorization-server
  6. 6 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.

    {
      "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"],
      …
    }
  7. 7 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.

    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
  8. 8 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.

  9. 9 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.

  10. 10 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.

    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
  11. 11 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.

  12. 12 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.

    POST /mcp HTTP/1.1
    Authorization: Bearer …

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.

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

1How does a client learn where to sign in?

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

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

4Where does an access token go?

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

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

2. The sign-in server's metadata

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

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 plain Markdown for language models, listed in /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

Sign in from Claude Code, ChatGPT and other clients, or connect with an API key.

Start with a note to yourself.

Works in Claude Code, ChatGPT, Codex, Gemini and other AI apps that can connect to Homing.

Connect an agent

Paste this into your agent.

Set me up with Homing in this session. Read https://tryhoming.com/setup-instructions.md and follow it. I'll sign in or set up a key when you ask.

Full Setup Guide

Step by step: Claude CodeCodexGeminiMore…