Skip to content

Commit 2c94381

Browse files
authored
Merge pull request #3 from modelcontextprotocol/d-mcadams/oauth-client-credentials
SEP-1046 and SEP-1502: Support client credentials flow as an auth extension
2 parents e2f8571 + ce15435 commit 2c94381

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
title: OAuth Client Credentials Extension
3+
---
4+
5+
<div id="enable-section-numbers" />
6+
7+
<Info>**Protocol Revision**: draft</Info>
8+
9+
## Introduction
10+
11+
### Purpose and Scope
12+
13+
This extension defines OAuth 2.1 Client Credentials flow support for the Model
14+
Context Protocol, enabling machine-to-machine authentication without user
15+
interaction. This extension builds upon the baseline authorization requirements
16+
defined in the main [Authorization specification](../basic/authorization.mdx).
17+
18+
### Extension Requirements
19+
20+
This extension is **OPTIONAL** for MCP implementations. When adopted:
21+
22+
- Implementations **MUST** conform to all requirements specified in this
23+
extension
24+
- Implementations **MUST** also conform to the baseline authorization
25+
requirements
26+
- This extension is specifically designed for HTTP-based transports
27+
28+
### Standards Compliance
29+
30+
This extension is based on the following established specifications:
31+
32+
- OAuth 2.1 IETF DRAFT
33+
([draft-ietf-oauth-v2-1-13](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-13))
34+
- OAuth 2.0 Authorization Server Metadata
35+
([RFC8414](https://datatracker.ietf.org/doc/html/rfc8414))
36+
- OAuth 2.0 Protected Resource Metadata
37+
([RFC9728](https://datatracker.ietf.org/doc/html/rfc9728))
38+
- JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and
39+
Authorization Grants
40+
([RFC7523](https://datatracker.ietf.org/doc/html/rfc7523))
41+
42+
## Client Credentials Flow
43+
44+
### Overview
45+
46+
The Client Credentials flow enables machine-to-machine authentication without
47+
user interaction. This flow requires pre-registered client credentials, which
48+
are typically established out-of-band through administrative channels. Dynamic
49+
Client Registration is not used in this flow.
50+
51+
### Client Authentication Methods
52+
53+
Clients **MUST** authenticate using one of these methods:
54+
55+
- JWT Authentication (RECOMMENDED)
56+
- Clients use JWT Authentication as defined in
57+
[RFC 7523 Section 2.2](https://datatracker.ietf.org/doc/html/rfc7523#section-2.2).
58+
- Client Secret
59+
- Clients use a Client Secret transmitted in the request content as defined
60+
in
61+
[OAuth 2.1 Section 2.4.1](https://www.ietf.org/archive/id/draft-ietf-oauth-v2-1-13.html#name-client-secret)
62+
63+
### Server Metadata Requirements
64+
65+
When supporting the client credentials flow, Authorization Server metadata
66+
**MUST** include the following fields:
67+
68+
- `token_endpoint_auth_methods_supported`: **MUST** include at least one of:
69+
- `"private_key_jwt"`
70+
- `"client_secret_basic"`
71+
- `token_endpoint_auth_signing_alg_values_supported`: Required when supporting
72+
JWT authentication
73+
74+
### Flow Steps
75+
76+
The complete Client Credentials flow proceeds as follows:
77+
78+
```mermaid
79+
sequenceDiagram
80+
participant C as Client
81+
participant M as MCP Server (Resource Server)
82+
participant A as Authorization Server
83+
84+
C->>M: MCP request without token
85+
M->>C: HTTP 401 Unauthorized with WWW-Authenticate header
86+
Note over C: Extract resource_metadata URL from WWW-Authenticate
87+
88+
C->>M: Request Protected Resource Metadata
89+
M->>C: Return metadata
90+
91+
Note over C: Parse metadata and extract authorization server(s)<br/>Client determines AS to use
92+
93+
C->>A: GET Authorization server metadata endpoint
94+
Note over C,A: Try OAuth 2.0 and OpenID Connect<br/>discovery endpoints in priority order
95+
A-->>C: Authorization server metadata
96+
97+
Note over C: Prepare client authentication
98+
alt JWT Authentication (RECOMMENDED)
99+
Note over C: Generate signed JWT assertion
100+
C->>A: POST /token with client_assertion
101+
else Client Secret Authentication
102+
Note over C: Use client_id and client_secret
103+
C->>A: POST /token with client credentials
104+
end
105+
A->>C: Access token
106+
C->>M: MCP request with access token
107+
M-->>C: MCP response
108+
Note over C,M: MCP communication continues with valid token
109+
```
110+
111+
### Examples
112+
113+
The following examples illustrate both client authentication methods:
114+
115+
#### JWT Authentication Example
116+
117+
```
118+
POST /token HTTP/1.1
119+
Host: auth.example.com
120+
Content-Type: application/x-www-form-urlencoded
121+
122+
grant_type=client_credentials
123+
&client_assertion_type=urn%3Aietf%3Aparams%3Aoauth%3Aclient-assertion-type%3Ajwt-bearer
124+
&client_assertion=eyJhbGciOiJSUzI1NiIsImtpZCI6IjIyIn0.
125+
eyJpc3Mi[...omitted for brevity...].
126+
cC4hiUPo[...omitted for brevity...]
127+
&resource=https%3A%2F%2Fmcp.example.com
128+
&scope=mcp%3Aread
129+
```
130+
131+
> **Note:** The `client_id` parameter is omitted from the request body as
132+
> [RFC 7523 Section 3](https://datatracker.ietf.org/doc/html/rfc7523#section-3)
133+
> specifies that client identification is conveyed through the `sub` claim
134+
> within the JWT assertion.
135+
136+
#### Client Secret Authentication Example
137+
138+
```
139+
POST /token HTTP/1.1
140+
Host: auth.example.com
141+
Content-Type: application/x-www-form-urlencoded
142+
143+
grant_type=client_credentials
144+
&client_id=s6BhdRkqt3
145+
&client_secret=7Fjfp0ZBr1KtDRbnfVdmIw
146+
&resource=https%3A%2F%2Fmcp.example.com
147+
&scope=mcp%3Aread
148+
```
149+
150+
## Security Considerations
151+
152+
Implementations adopting this extension **MUST** follow OAuth 2.1 security best
153+
practices as laid out in
154+
[OAuth 2.1 Section 7. "Security Considerations"](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-13#name-security-considerations),
155+
with particular attention to:
156+
157+
- Client authentication security
158+
- Token storage and handling
159+
- Communication security requirements
160+
- Client credential protection
161+
162+
For detailed security guidance specific to client credentials flows, refer to
163+
[RFC 7523 Section 5 "Security Considerations"](https://datatracker.ietf.org/doc/html/rfc7523#section-5).

0 commit comments

Comments
 (0)