C.W.K.
Stream
Lesson 01 of 05 · published

OAuth 2.1 — Authorization Framework

~26 min · oauth, resource-server, scopes, tokens

Level 0호기심 많은 독자
0 XP0/48 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

HTTP-transport MCP server 의 authorization 은 OAuth 2.1 사용. Spec 이 MCP server 를 OAuth 2.1 Resource Server 로 모델: access token 받아 검증, token scope 으로 각 tool call authorize. MCP client 는 외부 Authorization Server 에서 token 받는 OAuth client. 핵심: MCP server 는 auth 발급 사업 안 함 — token 소비; 발행 X.

전형적 session flow: host (MCP client 돌림) 가 user 를 authorization server OAuth flow 로 안내 → access token (+ refresh token) 받음 → 저장 → 모든 MCP request 에 Bearer header 로 access token 포함. MCP server 가 token 검증 (introspection 또는 JWT 검증), scope 읽고 request authorize. Token refresh 는 host 책임; MCP server 는 이미 발행된 Bearer token 만 봄.

알아둘 MCP-specific 디테일 둘:

  1. Authorization Server discovery. MCP server 가 — token 없이 (또는 invalid 한 거로) 호출되면 — authorization metadata 가리키는 WWW-Authenticate header publish. Client 가 metadata fetch, issuer · scope · PKCE 요구사항 학습 후 OAuth flow 돌림. MCP server 가 — OpenID Connect 가 일반 identity 에 그랬듯 — auth 에 self-describing.
  2. Client ID Metadata Document (CIMD) — 2025-11-25 revision 추가. 모든 MCP server 가 per-server client 등록 요구하는 대신, client 가 well-known URL 에 metadata 문서 publish; server 가 필요할 때 fetch. MCP 가 scale 에서 — adoption 죽이는 — '모든 service 에 client 등록' friction 피하는 방법.

Code

MCP server 에 Bearer-token request·text
POST /mcp HTTP/1.1
Authorization: Bearer eyJhbGciOiJSUzI1NiIs...
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{...}}
Token 빠진 거에 WWW-Authenticate discovery·text
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://api.example.com/.well-known/oauth-protected-resource"

# Client 가 URL 따라가서 issuer · scope · PKCE 요구사항 학습,
# OAuth 2.1 authorization-code flow 돌리고 retry.
Server 에서 token 검증 (FastMCP / FastAPI 스타일)·python
from fastapi import HTTPException, Depends
from authlib.integrations.starlette_client import OAuth

async def require_scope(scope: str, token: str = Depends(extract_bearer)):
    claims = verify_jwt(token, jwks=AUTH_SERVER_JWKS, audience="https://api.example.com")
    if scope not in claims.get("scope", "").split():
        raise HTTPException(403, "insufficient scope")
    return claims

External links

Exercise

MCP authorization spec 끝까지 읽어. 각 요구사항을 셋 중 하나로 mapping: 'client 가 해야 함', 'server 가 해야 함', 'auth server 가 해야 함'. Mapping 이 — 네가 실제 소유한 OAuth 부분과 기존 인프라에 위임 가능한 부분 — 을 드러내.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.