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
Copy file name to clipboardExpand all lines: docs/auth.md
+22-17Lines changed: 22 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -168,16 +168,16 @@ The above implementation provides an OAuth compliant way to MCP security without
168
168
169
169
This section discusses the reference implementation using Amazon Cognito as the IdP, supporting both Machine-to-Machine (M2M) and Session Cookie authentication methods.
170
170
171
+
>This section will soon be updated with detailed steps for Cognito configuration.
172
+
171
173
### Key Components
172
174
173
175
#### 1. Auth Server (`auth_server/server.py`)
174
-
The enhanced auth server provides dual authentication support:
176
+
The auth server provides dual authentication support:
175
177
-**Primary Check**: Session cookie validation using `itsdangerous.URLSafeTimedSerializer`
176
178
-**Fallback**: JWT token validation with Cognito
177
179
-**Group Mapping**: Maps Cognito groups to MCP scopes via `scopes.yml` configuration
178
-
- Groups are mapped to scopes using the `group_mappings` section in `scopes.yml`
179
180
- Both M2M and session cookie auth use the same scope definitions
@@ -204,12 +204,17 @@ Cognito supports machine-to-machine authentication, enabling Agents to have thei
204
204
- MCP Server(s) function as resource servers
205
205
206
206
#### Authentication Flow:
207
+
Run the Agent with the following command:
208
+
```{.bash}
209
+
python agents/agent_w_auth.py
210
+
```
211
+
1. Copy `agents/.env.template` to `agents/.env.agent` and set the environment variables (`COGNITO_CLIENT_ID`, `COGNITO_CLIENT_SECRET`, `COGNITO_USER_POOL_ID`) as appropriate for your setup.
207
212
1. Agent startup:
208
-
- Configured with client ID, client secret, and a set of scopes
213
+
- Configured with client ID, client secret, and a set of scopes. _Each agent is an App Client in a Cognito user pool_.
209
214
- Requests scopes (e.g., MCP Registry with tool finder and basic MCP servers)
210
-
2. Cognito issues a JWT token
211
-
3. Agent includes the JWT token in MCP headers
212
-
4. Auth server on Nginx side:
215
+
1. Cognito issues a JWT token
216
+
1. Agent includes the JWT token in MCP headers
217
+
1. Auth server on Nginx side:
213
218
- Retrieves JWT token
214
219
- Calls Cognito to validate token and get allowed scopes
215
220
- Returns 200 or 403 based on:
@@ -219,10 +224,10 @@ Cognito supports machine-to-machine authentication, enabling Agents to have thei
219
224
220
225
#### Advantages
221
226
1. Leverages existing Cognito user identities and groups
222
-
2. No need to manage separate M2M credentials for user-initiated actions
223
-
3. Maintains user context throughout the session
224
-
4. Compatible with existing web-based authentication flow
225
-
5. Auth server handles both authentication methods transparently
227
+
1. No need to manage separate M2M credentials for user-initiated actions
228
+
1. Maintains user context throughout the session
229
+
1. Compatible with existing web-based authentication flow
230
+
1. Auth server handles both authentication methods transparently
226
231
227
232
### 2. Session Cookie Authentication
228
233
@@ -236,8 +241,7 @@ The CLI tool handles the OAuth flow with Cognito and saves the session cookie lo
236
241
237
242
```bash
238
243
# Run the CLI authentication tool
239
-
cd auth_server
240
-
python cli_auth.py
244
+
python agents/cli_auth.py
241
245
242
246
# This will:
243
247
# 1. Open your browser to Cognito hosted UI
@@ -247,13 +251,15 @@ python cli_auth.py
247
251
```
248
252
249
253
Required environment variables:
250
-
-`COGNITO_DOMAIN`: Your Cognito domain (e.g., 'mcp-gateway')
254
+
-`COGNITO_USER_POOL_ID`: Your Cognito user pool id
251
255
-`COGNITO_CLIENT_ID`: OAuth client ID configured for PKCE flow
252
256
-`SECRET_KEY`: Must match the registry's SECRET_KEY for cookie compatibility
253
257
254
258
##### b. Agent with Session Cookie Support
255
259
256
-
The enhanced agent (`agents/agent_w_auth.py`) now supports session cookie authentication:
260
+
Copy `agents/.env.template` to `agents/.env.user` and set the environment variables (`COGNITO_CLIENT_ID`, `COGNITO_CLIENT_SECRET`, `COGNITO_USER_POOL_ID`, `SECRET_KEY`) as appropriate for your setup.
261
+
262
+
The agent (`agents/agent_w_auth.py`) supports session cookie authentication:
257
263
258
264
```bash
259
265
# Use agent with session cookie
@@ -269,14 +275,13 @@ Key features:
269
275
- Automatically reads cookie and includes in request headers
270
276
- Falls back to M2M if session cookie flag not provided
271
277
272
-
##### c. Auth Server Enhancements
278
+
##### c. Auth Server
273
279
274
280
The auth server validates session cookies alongside JWT tokens:
275
281
- Checks for `mcp_gateway_session` cookie in request headers
276
282
- Validates cookie signature using `itsdangerous.URLSafeTimedSerializer`
277
283
- Maps Cognito groups to MCP scopes using `scopes.yml` configuration:
278
284
- Configuration-driven mapping ensures consistency with M2M authentication
279
-
- Group mappings defined in `group_mappings` section of `scopes.yml`
280
285
- Single source of truth for all permission definitions
281
286
- Falls back to JWT validation if no valid cookie found
0 commit comments