Skip to content

Commit 0ef17c2

Browse files
committed
Create comprehensive docs/cognito.md guide and fix file references
- Add complete Amazon Cognito setup guide covering both user identity and agent identity authentication modes - Include step-by-step Cognito User Pool creation and App Client configuration - Document OAuth 2.0 PKCE flow setup and M2M authentication - Provide complete .env.user and .env.agent configuration examples - Add comprehensive testing and troubleshooting section - Fix file references throughout codebase: - Update agent_w_auth.py references to agent.py - Update auth_server/cli_auth.py references to agents/cli_user_auth.py - Address GitHub issue #16 requirements Resolves #16
1 parent b5d259b commit 0ef17c2

File tree

4 files changed

+628
-13
lines changed

4 files changed

+628
-13
lines changed

agents/agent.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
- AWS_REGION: AWS region for Cognito
2222
2323
Usage:
24-
python agent_w_auth.py --mcp-registry-url URL --model model_id --message "your question" \
24+
python agent.py --mcp-registry-url URL --model model_id --message "your question" \
2525
--client-id CLIENT_ID --client-secret CLIENT_SECRET --user-pool-id USER_POOL_ID --region REGION
2626
2727
Example with command line arguments:
28-
python agent_w_auth.py --mcp-registry-url http://localhost/mcpgw/sse \
28+
python agent.py --mcp-registry-url http://localhost/mcpgw/sse \
2929
--model anthropic.claude-3-haiku-20240307-v1:0 --message "current time in new delhi" \
3030
--client-id [REDACTED] --client-secret [REDACTED] \
3131
--user-pool-id [REDACTED] --region us-east-1
@@ -36,7 +36,7 @@
3636
COGNITO_USER_POOL_ID=your_user_pool_id
3737
AWS_REGION=us-east-1
3838
39-
python agent_w_auth.py --message "current time in new delhi"
39+
python agent.py --message "current time in new delhi"
4040
"""
4141

4242
import asyncio
@@ -248,7 +248,7 @@ def parse_arguments() -> argparse.Namespace:
248248
cookie_path = os.path.expanduser(args.session_cookie_file)
249249
if not os.path.exists(cookie_path):
250250
parser.error(f"Session cookie file not found: {cookie_path}\n"
251-
f"Run 'python auth_server/cli_auth.py' to authenticate first")
251+
f"Run 'python agents/cli_user_auth.py' to authenticate first")
252252
else:
253253
# For M2M auth, validate Cognito parameters
254254
missing_params = []

agents/cli_user_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def main():
408408
print("✓ Authentication successful!")
409409
print(f"✓ Session cookie saved to: {Path(args.cookie_file).expanduser()}")
410410
print("\nYou can now use this cookie with agents:")
411-
print(f" python agents/agent_w_auth.py --use-session-cookie")
411+
print(f" python agents/agent.py --use-session-cookie")
412412
print("="*50 + "\n")
413413
return 0
414414
else:

docs/auth.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ sequenceDiagram
144144
IdP->>Agent: Return JWT token + scopes
145145
else Session Cookie (On-behalf of User)
146146
participant CLIAuth as CLI Auth Tool
147-
User->>CLIAuth: Run cli_auth.py
147+
User->>CLIAuth: Run cli_user_auth.py
148148
CLIAuth->>IdP: OAuth PKCE flow
149149
IdP->>CLIAuth: Auth code + user info
150150
CLIAuth->>CLIAuth: Create session cookie
@@ -227,15 +227,15 @@ The auth server provides dual authentication support:
227227
- **Group Mapping**: Maps Cognito groups to MCP scopes via `scopes.yml` configuration
228228
- Both M2M and session cookie auth use the same scope definitions
229229

230-
#### 2. CLI Authentication Tool (`auth_server/cli_auth.py`)
230+
#### 2. CLI Authentication Tool (`agents/cli_user_auth.py`)
231231
A standalone tool for user-based authentication:
232232
- Implements OAuth 2.0 PKCE flow with Cognito hosted UI
233233
- Opens browser for user authentication
234234
- Runs local callback server on port 8080
235235
- Creates session cookie compatible with registry format
236236
- Saves to `~/.mcp/session_cookie` with secure permissions (0600)
237237

238-
#### 3. Agent (`agents/agent_w_auth.py`)
238+
#### 3. Agent (`agents/agent.py`)
239239
The agent supports both authentication methods:
240240
- `--use-session-cookie` flag for session-based auth
241241
- `--session-cookie-file` parameter (default: `~/.mcp/session_cookie`)
@@ -254,7 +254,7 @@ Cognito supports machine-to-machine authentication, enabling Agents to have thei
254254
#### Authentication Flow:
255255
Run the Agent with the following command:
256256
```{.bash}
257-
python agents/agent_w_auth.py
257+
python agents/agent.py
258258
```
259259
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. For detailed Cognito configuration steps, see [`docs/cognito.md`](cognito.md).
260260
1. Agent startup:
@@ -283,13 +283,13 @@ Session cookie authentication enables agents to act on behalf of users, using th
283283

284284
#### Implementation Components
285285

286-
##### a. CLI Authentication Tool (`auth_server/cli_auth.py`)
286+
##### a. CLI Authentication Tool (`agents/cli_user_auth.py`)
287287

288288
The CLI tool handles the OAuth flow with Cognito and saves the session cookie locally:
289289

290290
```bash
291291
# Run the CLI authentication tool
292-
python agents/cli_auth.py
292+
python agents/cli_user_auth.py
293293

294294
# This will:
295295
# 1. Open your browser to Cognito hosted UI
@@ -307,11 +307,11 @@ Required environment variables:
307307

308308
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. For detailed Cognito configuration steps, see [`docs/cognito.md`](cognito.md).
309309

310-
The agent (`agents/agent_w_auth.py`) supports session cookie authentication:
310+
The agent (`agents/agent.py`) supports session cookie authentication:
311311

312312
```bash
313313
# Use agent with session cookie
314-
python agent_w_auth.py \
314+
python agent.py \
315315
--use-session-cookie \
316316
--message "What time is it in Tokyo?" \
317317
--mcp-registry-url http://localhost/mcpgw/sse

0 commit comments

Comments
 (0)