Skip to content

Commit ec1de9c

Browse files
committed
docs: update authentication modes in README and .env.example for clarity
1 parent d92cefb commit ec1de9c

File tree

2 files changed

+87
-47
lines changed

2 files changed

+87
-47
lines changed

.env.example

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@ SERVER_NAME=mcp-typescript-template
55
SERVER_VERSION=1.0.0
66
LOG_LEVEL=info
77

8+
# Base URL for the server (used for OAuth redirects and discovery endpoints)
9+
# Defaults to http://localhost:PORT if not set (where PORT is the configured port)
10+
# BASE_URL=http://localhost:3000
11+
812
# Authentication Configuration (Optional)
913
# Set ENABLE_AUTH=true to enable authentication
1014
ENABLE_AUTH=false
1115

12-
# Authentication mode: "gateway" (recommended) or "builtin" (testing/demos)
13-
AUTH_MODE=gateway
16+
# Authentication mode: "resource_server", "full", or "none" (default)
17+
AUTH_MODE=resource_server
1418

1519
# ============================================================================
16-
# Gateway Mode Configuration (Recommended for Production)
20+
# Resource Server Mode Configuration
1721
# ============================================================================
18-
# Use when authentication is handled by a reverse proxy/gateway (Pomerium, etc.)
19-
# The MCP server acts as a resource server and only validates tokens
22+
# MCP server acts as a resource server and validates tokens from external OAuth providers
23+
# Commonly used with gateways that handle OAuth flows for enterprise deployments
24+
# Can also work with direct OAuth flows where clients get tokens themselves
2025

21-
# OAuth issuer URL for token validation (required for gateway mode)
26+
# OAuth issuer URL for token validation (required for resource_server mode)
2227
# Examples:
2328
# Auth0: https://your-domain.auth0.com
2429
# Okta: https://your-domain.okta.com
@@ -30,39 +35,45 @@ OAUTH_ISSUER=https://your-domain.auth0.com
3035
OAUTH_AUDIENCE=your-api-identifier
3136

3237
# ============================================================================
33-
# Built-in Mode Configuration (Testing/Demos Only)
38+
# Full Mode Configuration (OAuth Proxy + Resource Server)
3439
# ============================================================================
35-
# Use when you want the MCP server to handle the OAuth flow directly
36-
# Not recommended for production - use gateway mode instead
40+
# MCP server acts as both OAuth client (proxy to external IdP) AND resource server
41+
# Provides OAuth endpoints while delegating authentication to external providers
42+
# Production-ready but consider using resource_server mode with a gateway for enterprise deployments
3743

38-
# OAuth client credentials (required for built-in mode)
44+
# OAuth client credentials (required for full mode)
3945
OAUTH_CLIENT_ID=your-client-id
4046
OAUTH_CLIENT_SECRET=your-client-secret
4147

42-
# OAuth provider endpoints (required for built-in mode)
48+
# OAuth provider endpoints (required for full mode)
4349
OAUTH_AUTH_ENDPOINT=https://your-domain.auth0.com/authorize
4450
OAUTH_TOKEN_ENDPOINT=https://your-domain.auth0.com/oauth/token
4551

4652
# OAuth configuration
4753
OAUTH_SCOPE=read
48-
OAUTH_REDIRECT_URI=http://localhost:3000/callback
54+
# OAUTH_REDIRECT_URI=http://localhost:3000/callback # Optional, defaults to BASE_URL/callback
4955

5056
# ============================================================================
5157
# Example Configurations
5258
# ============================================================================
5359

54-
# Example: Auth0 Gateway Mode
60+
# Example: Auth0 Resource Server Mode
5561
# ENABLE_AUTH=true
56-
# AUTH_MODE=gateway
62+
# AUTH_MODE=resource_server
5763
# OAUTH_ISSUER=https://your-domain.auth0.com
5864
# OAUTH_AUDIENCE=your-api-identifier
5965

60-
# Example: Auth0 Built-in Mode
66+
# Example: Auth0 Full Mode
6167
# ENABLE_AUTH=true
62-
# AUTH_MODE=builtin
68+
# AUTH_MODE=full
6369
# OAUTH_CLIENT_ID=your-auth0-client-id
6470
# OAUTH_CLIENT_SECRET=your-auth0-client-secret
6571
# OAUTH_AUTH_ENDPOINT=https://your-domain.auth0.com/authorize
6672
# OAUTH_TOKEN_ENDPOINT=https://your-domain.auth0.com/oauth/token
6773
# OAUTH_SCOPE=read
68-
# OAUTH_REDIRECT_URI=http://localhost:3000/callback
74+
# OAUTH_REDIRECT_URI=http://localhost:3000/callback # Optional, defaults to BASE_URL/callback
75+
76+
# Example: No Authentication Mode (Default)
77+
# Note: Consider enabling auth even for local development for security best practices
78+
# ENABLE_AUTH=false
79+
# AUTH_MODE=none

README.md

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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
231246
ENABLE_AUTH=true
232-
AUTH_MODE=gateway
247+
AUTH_MODE=resource_server
233248
OAUTH_ISSUER=https://your-domain.auth0.com
234249
OAUTH_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
240256
routes:
@@ -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
252275
ENABLE_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)
268296
ENABLE_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
305334
OAUTH_ISSUER=https://your-domain.auth0.com
306335
OAUTH_AUDIENCE=your-api-identifier
307336
```
308337

309-
**Built-in Mode:**
338+
**Full Mode:**
310339
```bash
311340
OAUTH_AUTH_ENDPOINT=https://your-domain.auth0.com/authorize
312341
OAUTH_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
323352
OAUTH_ISSUER=https://accounts.google.com
324353
OAUTH_AUDIENCE=your-client-id.apps.googleusercontent.com
325354
```
326355

327-
**Built-in Mode:**
356+
**Full Mode:**
328357
```bash
329358
OAUTH_AUTH_ENDPOINT=https://accounts.google.com/o/oauth2/v2/auth
330359
OAUTH_TOKEN_ENDPOINT=https://oauth2.googleapis.com/token

0 commit comments

Comments
 (0)