@@ -198,43 +198,59 @@ server.registerTool(
198198
199199## Authentication & Authorization
200200
201- This template provides ** optional** OAuth 2.1 authentication with two deployment patterns:
201+ This template provides ** optional** OAuth 2.1 authentication with three deployment modes. Gateway-based deployment is a common production pattern that separates authentication concerns.
202+
203+ ### 📋 Mode Overview
204+
205+ The three authentication modes serve different purposes:
206+
207+ - ** ` none ` ** - No authentication (public servers, or when gateway handles all OAuth/security)
208+ - ** ` full ` ** - Complete OAuth flow within MCP server (production-ready when you don't have a gateway)
209+ - ** ` resource_server ` ** - Only validates tokens (requires either ` full ` mode or external gateway to issue tokens)
210+
211+ ** Key insight** : ` resource_server ` mode only * validates* tokens - it doesn't * issue* them. So you need either:
212+ 1 . ** Gateway + resource_server** (common enterprise pattern)
213+ 2 . ** Full mode standalone** (self-contained OAuth solution)
202214
203215### 🔧 Authentication Modes
204216
205- #### Gateway Mode (Enterprise/Multi-Service)
206- - ** Resource Server Pattern** : MCP server only validates tokens from external OAuth providers
207- - ** External OAuth** : Authentication handled by reverse proxy/gateway (Pomerium, nginx, API Gateway)
208- - ** JWT + Introspection** : Supports both JWT validation and token introspection
217+ #### Resource Server Mode
218+ - ** Resource Server Pattern** : MCP server validates tokens issued by external OAuth providers
219+ - ** Token Validation** : Supports both JWT validation and token introspection
209220- ** Stateless** : No OAuth routes, sessions, or cookies in MCP server
210221- ** Scalable** : Easy to horizontally scale the MCP server
211- - ** Best for** : Organizations with existing OAuth infrastructure
212-
213- #### Built-in Mode (Standalone/Simple Deployment)
214- - ** OAuth 2.1 Authorization Server** : MCP server IS the complete OAuth authorization server
215- - ** PKCE Support** : Full PKCE implementation as required by MCP specification
216- - ** MCP Client Compatible** : Works seamlessly with VS Code and other MCP clients
217- - ** Self-contained** : No external OAuth provider needed
222+ - ** Gateway Compatible** : Commonly used with reverse proxies/gateways for enterprise deployments
223+ - ** Best for** : Deployments where authentication is handled externally
224+
225+ #### Full Mode (OAuth Proxy + Resource Server)
226+ - ** Dual Role** : MCP server acts as both OAuth client (proxy) AND resource server
227+ - ** External IdP Integration** : Delegates authentication to external providers (Auth0, Google, etc.)
228+ - ** OAuth Endpoints** : Provides its own OAuth endpoints for MCP clients
229+ - ** PKCE Support** : Full PKCE implementation for secure authorization flows
230+ - ** Self-Contained** : Provides complete OAuth flow without requiring external gateway infrastructure
218231- ** Discovery Endpoints** : Provides OAuth 2.1 discovery metadata for automatic client configuration
219- - ** Best for** : Solo developers, small teams, or simple deployments wanting OAuth security
232+ - ** Best for** : Production deployments without gateway infrastructure, provides complete OAuth flow for MCP clients
220233
221234#### No Auth Mode (Default)
222- - ** Completely Optional** : Authentication can be disabled entirely
235+ - ** No Authentication** : MCP server accepts all requests without authentication
236+ - ** Use Cases** : Public servers, or when gateway handles all OAuth/security layers
237+ - ** Security Note** : Consider enabling authentication even for local development to build secure habits
238+ - ** Gateway Compatible** : Can still benefit from gateway for rate limiting, SSL termination, etc.
223239- ** Simple Setup** : Just set ` ENABLE_AUTH=false ` or omit auth configuration
224- - ** Open Access** : MCP server accepts all requests without authentication
225240
226241### 🚀 Quick Setup
227242
228- #### 1. Gateway Mode (Enterprise)
243+ #### 1. Resource Server Mode
229244``` bash
230245# .env
231246ENABLE_AUTH=true
232- AUTH_MODE=gateway
247+ AUTH_MODE=resource_server
233248OAUTH_ISSUER=https://your-domain.auth0.com
234249OAUTH_AUDIENCE=your-api-identifier # optional
250+ # BASE_URL=https://mcp.yourdomain.com # optional, defaults to http://localhost:PORT
235251```
236252
237- ** Setup your gateway (e.g., Pomerium): **
253+ ** Common Pattern: With Gateway **
238254``` yaml
239255# pomerium-config.yaml
240256routes :
@@ -246,12 +262,24 @@ routes:
246262 - authenticated_user : true
247263` ` `
248264
249- #### 2. Built-in Mode (Standalone)
265+ **Alternative: Direct OAuth**
266+ ` ` ` bash
267+ # Note: MCP clients would need to implement OAuth flow themselves
268+ # Clients get tokens directly from Auth0, send to MCP server
269+ curl -H "Authorization : Bearer ${AUTH0_TOKEN}" http://localhost:3000/mcp
270+ ` ` `
271+
272+ #### 2. Full Mode (Self-Contained OAuth)
250273` ` ` bash
251274# .env
252275ENABLE_AUTH=true
253- AUTH_MODE=builtin
254- # No external OAuth configuration needed - server acts as OAuth provider
276+ AUTH_MODE=full
277+ OAUTH_CLIENT_ID=your-client-id
278+ OAUTH_CLIENT_SECRET=your-client-secret
279+ OAUTH_AUTH_ENDPOINT=https://your-domain.auth0.com/authorize
280+ OAUTH_TOKEN_ENDPOINT=https://your-domain.auth0.com/oauth/token
281+ # OAUTH_REDIRECT_URI=http://localhost:3000/callback # optional, defaults to BASE_URL/callback
282+ # BASE_URL=https://mcp.yourdomain.com # optional, defaults to http://localhost:PORT
255283```
256284
257285** OAuth 2.1 Endpoints (automatically available):**
@@ -267,7 +295,8 @@ AUTH_MODE=builtin
267295# .env (or just omit ENABLE_AUTH)
268296ENABLE_AUTH=false
269297```
270- Server accepts all requests without authentication.
298+
299+ ** ⚠️ Security Recommendation** : While convenient for getting started, consider enabling authentication even for local development to build secure practices and catch integration issues early.
271300
272301### 🔐 Token Validation
273302
@@ -282,11 +311,11 @@ curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
282311### 🏗️ Architecture
283312
284313```
285- ┌─────── Gateway Mode (Enterprise ) ─────── ┐ ┌────── Built-in Mode (Standalone ) ───┐ ┌── No Auth (Default) ──┐
314+ ┌─── Resource Server Mode (Production ) ───┐ ┌──── Full Mode (Proxy + Resource ) ───┐ ┌── No Auth (Default) ──┐
286315│ │ │ │ │ │
287- │ MCP Client → Gateway → MCP Server │ │ MCP Client → MCP Server │ │ MCP Client │
288- │ ↓ │ │ ↓ │ │ ↓ │
289- │ External OAuth (Auth0) │ │ Built-in OAuth Server │ │ MCP Server │
316+ │ MCP Client → [ Gateway] → MCP Server │ │ MCP Client → MCP Server │ │ MCP Client │
317+ │ ↓ ↓ │ │ ↓ ↓ │ │ ↓ │
318+ │ External OAuth → Token Validation │ │ OAuth Proxy → External IdP │ │ MCP Server │
290319│ │ │ │ │ (Open Access) │
291320│ ✅ Enterprise ready │ │ ✅ Production ready │ │ ✅ Simple setup │
292321│ ✅ Stateless & scalable │ │ ✅ OAuth 2.1 compliant │ │ ✅ No auth overhead │
@@ -300,13 +329,13 @@ curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
300329<details >
301330<summary ><strong >Auth0 Configuration</strong ></summary >
302331
303- ** Gateway Mode:**
332+ ** Resource Server Mode:**
304333``` bash
305334OAUTH_ISSUER=https://your-domain.auth0.com
306335OAUTH_AUDIENCE=your-api-identifier
307336```
308337
309- ** Built-in Mode:**
338+ ** Full Mode:**
310339``` bash
311340OAUTH_AUTH_ENDPOINT=https://your-domain.auth0.com/authorize
312341OAUTH_TOKEN_ENDPOINT=https://your-domain.auth0.com/oauth/token
@@ -318,13 +347,13 @@ OAUTH_CLIENT_SECRET=your-client-secret
318347<details >
319348<summary ><strong >Google OAuth Configuration</strong ></summary >
320349
321- ** Gateway Mode:**
350+ ** Resource Server Mode:**
322351``` bash
323352OAUTH_ISSUER=https://accounts.google.com
324353OAUTH_AUDIENCE=your-client-id.apps.googleusercontent.com
325354```
326355
327- ** Built-in Mode:**
356+ ** Full Mode:**
328357``` bash
329358OAUTH_AUTH_ENDPOINT=https://accounts.google.com/o/oauth2/v2/auth
330359OAUTH_TOKEN_ENDPOINT=https://oauth2.googleapis.com/token
0 commit comments