You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -6,9 +6,9 @@ This document describes different OAuth 2.0 architecture patterns for MCP server
6
6
7
7
Per the MCP specification, "the authorization server may be hosted with the resource server or as a separate entity." This leads to two primary patterns for implementing OAuth in MCP servers.
8
8
9
-
## Pattern 1: Separate Authorization Server (Implemented)
9
+
## Pattern 1: Separate Authorization Server (Recommended)
10
10
11
-
The current implementation uses this production-ready pattern with separate authorization and resource servers.
11
+
The current implementation demonstrates this pattern with separate authorization and resource servers. (Note: the authorization server is for demonstration purposes only.)
12
12
13
13
### Architecture
14
14
@@ -19,173 +19,51 @@ The current implementation uses this production-ready pattern with separate auth
5.**Migrate users**: Import existing users if needed
51
+
6.**Test integration**: Verify full OAuth flow
77
52
78
53
---
79
54
80
-
## Pattern 2: Embedded Authorization Server (Alternative)
81
-
82
-
An alternative pattern where the OAuth server is embedded within the MCP server. This demonstrates a self-hosted OAuth 2.1 authorization server running in the same process as the MCP server.
83
-
84
-
### Architecture
85
-
86
-
```
87
-
┌─────────────┐ ┌─────────────────────────┐
88
-
│ │ OAuth │ │
89
-
│ MCP Client │────────>│ MCP Server │
90
-
│ │ │ ┌──────────────────┐ │
91
-
│ │<────────│ │ OAuth Server │ │
92
-
│ │ token │ └──────────────────┘ │
93
-
│ │ │ ┌──────────────────┐ │
94
-
│ │────────>│ │ MCP Resources │ │
95
-
│ │ MCP │ └──────────────────┘ │
96
-
└─────────────┘ └─────────────────────────┘
97
-
```
98
-
99
-
### Upstream Delegation Pattern
100
-
101
-
Embedded OAuth often delegates user authentication to an upstream identity provider while maintaining control over token issuance:
│──4. Provide credentials────────────────────────────────────────>│
115
-
│<──redirect with userId─────────────────────────────────────────│
116
-
│ │ │
117
-
│──5. /callback with userId───────>│ │
118
-
│ │──(validate userId) │
119
-
│ │──(issue MCP tokens) │
120
-
│<──redirect with auth code──────│ │
121
-
│ │ │
122
-
│──6. /token (exchange code)─────>│ │
123
-
│<──MCP access token─────────────│ │
124
-
```
125
-
126
-
### Characteristics
127
-
128
-
-**Single Server**: OAuth and MCP in one process
129
-
-**Port**: Typically runs on single port (e.g., 3232)
130
-
-**Token Validation**: In-process, direct database access
131
-
-**Deployment**: Simpler, fewer moving parts
132
-
-**Upstream Delegation**: Can delegate authentication to corporate SSO while controlling token issuance
55
+
## Pattern 2: Embedded Authorization Server (Alternative/Legacy)
133
56
134
-
### Benefits
57
+
The MCP spec describes an alternative pattern where the OAuth server is embedded within the MCP server. However, this pattern is not recommended in the general case, and is not demonstrated in this codebase.
135
58
136
-
-**Simplicity**: Single server to deploy and manage
137
-
-**Performance**: No network hop for token validation
138
-
-**Self-Contained**: All functionality in one codebase
139
-
-**Control**: Full control over token issuance while leveraging existing identity infrastructure
140
-
141
-
### Drawbacks
142
-
143
-
-**Coupling**: Auth and MCP logic intertwined
144
-
-**Scalability**: Can't scale auth independently
145
-
-**Flexibility**: Harder to switch auth providers
146
-
-**Updates**: Auth changes require MCP server updates
147
-
148
-
### Use Cases
59
+
### Possible Use Cases
149
60
150
61
-**Enterprise Deployments**: Organizations needing control over OAuth token issuance while leveraging existing corporate identity infrastructure (LDAP, Active Directory, SAML)
151
62
-**Proof of Concepts**: Quick prototypes and demonstrations
152
63
-**Small Deployments**: Internal tools with simple auth needs
153
64
-**Isolated Systems**: Air-gapped environments without external connectivity
154
65
-**Custom Auth Requirements**: Specialized authentication needs not met by standard providers
155
66
156
-
### Typical Configuration
157
-
158
-
Environment variables for embedded pattern:
159
-
```bash
160
-
BASE_URI=http://localhost:3232 # Single server URL
- First run registers an OAuth client automatically
44
+
- Second run initializes an MCP session and returns a session ID
45
+
- Third run executes all the example MCP operations
46
+
42
47
### client.js
43
48
44
49
Node.js client showing programmatic interaction with the MCP server.
@@ -59,6 +64,20 @@ chmod +x client.js
59
64
./client.js
60
65
```
61
66
67
+
**Note:** When you complete the OAuth flow in your browser, you'll be redirected to `http://localhost:8080/callback` which will show "site can't be reached". This is expected! Simply copy the authorization code from the URL in your browser's address bar (the long string after `code=`). The script will exchange this for an access token and display it for use with other tools.
68
+
69
+
## Understanding OAuth Tokens
70
+
71
+
**Authorization Code** vs **Access Token**:
72
+
-**Authorization Code**: The temporary code you get from the browser redirect (e.g., `302a80e8...`)
73
+
- One-time use only
74
+
- Must be exchanged for an access token
75
+
- Expires quickly (usually within minutes)
76
+
-**Access Token**: The actual bearer token for API authentication (e.g., `mcp_at_...`)
0 commit comments