{"slug": "mcp-oauth-for-remote-servers-explained-with-a-real-server-s-metadata", "title": "MCP OAuth for remote servers, explained with a real server's metadata", "summary": "A developer walkthrough of the MCP authorization specification (version 2025-11-25) traces how remote MCP servers handle OAuth, using Sandscale's published metadata as a worked example. The flow begins with a token-less request returning a 401 whose WWW-Authenticate header points to protected-resource metadata, then moves through authorization-server discovery, PKCE enforcement (clients must refuse to continue if code_challenge_methods_supported is missing), and resource binding via the canonical resource field. The writeup stresses that authorization servers must display the redirect URI's host on the consent page, giving teams a checkpoint to catch unexpected connectors.", "body_md": "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.\n\nThis 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.\n\nThe 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?ref=devto-mcp-oauth-for-remote-servers-explained).\n\nThe 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:\n\n```\nWWW-Authenticate: Bearer resource_metadata=\"https://mcp.sandscale.dev/.well-known/oauth-protected-resource/mcp\", scope=\"mcp\"\n```\n\nTwo 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.\n\nThe 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:\n\n```\n{\"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\"}\n```\n\nThe 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.\n\nThe 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`.\n\nThat PKCE field is not decoration. The specification says that if `code_challenge_methods_supported` is missing, the client must refuse to continue.\n\nAn 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:\n\nSandscale's authorization server advertises the second and third, so clients that do either can connect.\n\nFor 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.\n\nThe client opens the browser with an authorization code request. Two parameters matter:\n\n`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).\nThe person signs in and approves. The client exchanges the code for an access token, and, if it asked for `offline_access`, a refresh token.\n\nFrom here, each MCP request carries `Authorization: Bearer <token>`. The specification puts two duties on the server that are worth knowing as a buyer:\n\nLater, 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).\n\nThe 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:\n\nFor Sandscale's [remote MCP server](https://sandscale.dev/sandboxes/mcp?ref=devto-mcp-oauth-for-remote-servers-explained), 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.\n\nYou do not need a client to look at any of this. Two requests show what a remote MCP server expects:\n\n```\ncurl -si -X POST https://mcp.sandscale.dev/mcp -H 'Content-Type: application/json' -d '{}' | grep -i www-authenticate\ncurl -s https://mcp.sandscale.dev/.well-known/oauth-protected-resource\n```\n\nPoint 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.\n\n*Originally published on the [Sandscale blog](https://sandscale.dev/blog/mcp-oauth-for-remote-servers-explained?ref=devto-mcp-oauth-for-remote-servers-explained).*", "url": "https://wpnews.pro/news/mcp-oauth-for-remote-servers-explained-with-a-real-server-s-metadata", "canonical_source": "https://dev.to/sandscale/mcp-oauth-for-remote-servers-explained-with-a-real-servers-metadata-2686", "published_at": "2026-12-02 02:28:11+00:00", "updated_at": "2026-12-02 02:42:51.387666+00:00", "lang": "en", "topics": ["agent-protocols", "ai-agents", "ai-tools", "artificial-intelligence"], "entities": ["Sandscale", "Model Context Protocol", "Claude Code", "Codex", "Cursor", "Gemini CLI"], "also_reported_by": [], "takeaway": "Remote MCP servers over Streamable HTTP should return a 401 with a WWW-Authenticate header naming resource_metadata and scope, and clients must abort if the authorization server's metadata lacks code_challenge_methods_supported with S256.", "recommendation": {"advice": "When connecting a remote MCP server, verify its protected-resource metadata binds the canonical resource URL and that the consent page shows the redirect host before approving.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/mcp-oauth-for-remote-servers-explained-with-a-real-server-s-metadata", "markdown": "https://wpnews.pro/news/mcp-oauth-for-remote-servers-explained-with-a-real-server-s-metadata.md", "text": "https://wpnews.pro/news/mcp-oauth-for-remote-servers-explained-with-a-real-server-s-metadata.txt", "jsonld": "https://wpnews.pro/news/mcp-oauth-for-remote-servers-explained-with-a-real-server-s-metadata.jsonld"}}