#!/bin/bash set -e echo "==================================================" echo "End-to-End Test - Separate Mode" echo "==================================================" echo "This script tests the complete OAuth flow and MCP features" echo "using separate auth server and MCP server." echo "" # Use environment variables if available, otherwise defaults AUTH_SERVER="${AUTH_SERVER_URL:-http://localhost:3001}" MCP_SERVER="${BASE_URI:-http://localhost:3232}" USER_ID="e2e-separate-$(date +%s)" echo "๐Ÿ”ง Configuration:" echo " Auth Server: $AUTH_SERVER" echo " MCP Server: $MCP_SERVER" echo " User ID: $USER_ID" echo " Auth Mode: ${AUTH_MODE:-separate} (from environment)" echo "" # Check prerequisites echo "๐Ÿ” Checking prerequisites..." # Check Redis if ! docker ps | grep -q redis; then echo "โŒ Redis not running" echo " Start Redis: docker compose up -d" exit 1 fi echo "โœ… Redis is running" # Check if wrong mode is set if [ "${AUTH_MODE}" = "integrated" ]; then echo "โš ๏ธ AUTH_MODE is set to 'integrated' but this script tests separate mode" echo " Either run: AUTH_MODE=separate $0" echo " Or use: ./scripts/test-integrated-e2e-fixed.sh" fi # Check auth server if ! curl -s -f "$AUTH_SERVER/health" > /dev/null; then echo "โŒ Auth server not running at $AUTH_SERVER" echo " Required setup:" echo " 1. Start Redis: docker compose up -d" echo " 2. Start both servers: npm run dev:with-separate-auth" echo " 3. Or start separately:" echo " Terminal 1: npm run dev:auth-server" echo " Terminal 2: AUTH_MODE=separate npm run dev" echo " 4. Or set up environment:" echo " cp .env.separate .env && npm run dev:with-separate-auth" exit 1 fi echo "โœ… Auth server is running" # Check MCP server if ! curl -s -f "$MCP_SERVER/" > /dev/null; then echo "โŒ MCP server not running at $MCP_SERVER" echo " See auth server setup instructions above" exit 1 fi echo "โœ… MCP server is running" echo "" echo "๐Ÿ” PHASE 1: OAuth Authentication (with Auth Server)" echo "=================================================" # Step 1: Register OAuth client with AUTH SERVER echo "๐Ÿ“ Step 1: Register OAuth client with auth server" CLIENT_RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" \ -d "{\"client_name\":\"e2e-separate-client\",\"redirect_uris\":[\"http://localhost:3000/callback\"]}" \ "$AUTH_SERVER/register") CLIENT_ID=$(echo "$CLIENT_RESPONSE" | jq -r .client_id) CLIENT_SECRET=$(echo "$CLIENT_RESPONSE" | jq -r .client_secret) echo " Client ID: $CLIENT_ID" # Step 2: Generate PKCE echo "" echo "๐Ÿ” Step 2: Generate PKCE challenge" CODE_VERIFIER=$(openssl rand -base64 32 | tr -d "=+/" | cut -c1-43) CODE_CHALLENGE=$(echo -n "$CODE_VERIFIER" | openssl dgst -binary -sha256 | base64 | tr "+/" "-_" | tr -d "=") echo " Code verifier generated" # Step 3: Get authorization code from AUTH SERVER echo "" echo "๐ŸŽซ Step 3: Get authorization code from auth server" AUTH_URL="$AUTH_SERVER/authorize?response_type=code&client_id=$CLIENT_ID&redirect_uri=http://localhost:3000/callback&code_challenge=$CODE_CHALLENGE&code_challenge_method=S256&state=separate-test" AUTH_PAGE=$(curl -s "$AUTH_URL") AUTH_CODE=$(echo "$AUTH_PAGE" | grep -o 'state=[^"&]*' | cut -d= -f2 | head -1) if [ -z "$AUTH_CODE" ]; then echo " โŒ Failed to extract authorization code from auth server" exit 1 fi echo " Auth Code: ${AUTH_CODE:0:20}..." # Step 4: Complete fake upstream auth with AUTH SERVER echo "" echo "๐Ÿ”„ Step 4: Complete fake upstream auth with auth server" CALLBACK_URL="$AUTH_SERVER/fakeupstreamauth/callback?state=$AUTH_CODE&code=fakecode&userId=$USER_ID" curl -s -L "$CALLBACK_URL" > /dev/null echo " Fake upstream auth completed" # Step 5: Exchange for tokens with AUTH SERVER echo "" echo "๐ŸŽŸ๏ธ Step 5: Exchange code for access token with auth server" TOKEN_RESPONSE=$(curl -s -X POST -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=authorization_code&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&code=$AUTH_CODE&redirect_uri=http://localhost:3000/callback&code_verifier=$CODE_VERIFIER" \ "$AUTH_SERVER/token") ACCESS_TOKEN=$(echo "$TOKEN_RESPONSE" | jq -r .access_token) if [ "$ACCESS_TOKEN" = "null" ] || [ -z "$ACCESS_TOKEN" ]; then echo " โŒ Token exchange failed" echo "Response: $TOKEN_RESPONSE" exit 1 fi echo " โœ… Access token from auth server: ${ACCESS_TOKEN:0:20}..." echo "" echo "๐Ÿงช PHASE 2: MCP Feature Testing (with MCP Server)" echo "==============================================" # Step 1: Initialize MCP session with MCP SERVER using auth server token echo "" echo "๐Ÿ“ฑ Step 1: Initialize MCP session with MCP server" INIT_RESPONSE=$(curl -i -s -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Accept: application/json, text/event-stream" \ -X POST -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":"init","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"e2e-separate","version":"1.0"}}}' \ "$MCP_SERVER/mcp") # Extract session ID from response header SESSION_ID=$(echo "$INIT_RESPONSE" | grep -i "mcp-session-id:" | cut -d' ' -f2 | tr -d '\r') if [ -n "$SESSION_ID" ]; then echo " โœ… MCP session initialized: $SESSION_ID" echo " โœ… Auth server token accepted by MCP server!" else echo " โŒ MCP session initialization failed" echo "$INIT_RESPONSE" exit 1 fi # Step 2: Test tools with MCP SERVER echo "" echo "๐Ÿ”ง Step 2: Test Tools with MCP server" TOOLS_RESPONSE=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Accept: application/json, text/event-stream" \ -H "Mcp-Session-Id: $SESSION_ID" \ -X POST -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":"tools","method":"tools/list"}' \ "$MCP_SERVER/mcp") if echo "$TOOLS_RESPONSE" | grep -q "event: message"; then TOOLS_JSON=$(echo "$TOOLS_RESPONSE" | grep "^data: " | sed 's/^data: //') TOOL_COUNT=$(echo "$TOOLS_JSON" | jq '.result.tools | length') echo " โœ… Tools: $TOOL_COUNT (README claims: 7)" # Test echo tool ECHO_RESPONSE=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Accept: application/json, text/event-stream" \ -H "Mcp-Session-Id: $SESSION_ID" \ -X POST -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":"echo","method":"tools/call","params":{"name":"echo","arguments":{"message":"Separate mode working!"}}}' \ "$MCP_SERVER/mcp") if echo "$ECHO_RESPONSE" | grep -q "event: message"; then ECHO_JSON=$(echo "$ECHO_RESPONSE" | grep "^data: " | sed 's/^data: //') ECHO_RESULT=$(echo "$ECHO_JSON" | jq -r '.result.content[0].text') echo " ๐Ÿ”Š Echo test: '$ECHO_RESULT'" fi else echo " โŒ Tools test failed: $TOOLS_RESPONSE" fi # Step 3: Test resources with MCP SERVER (with pagination) echo "" echo "๐Ÿ“š Step 3: Test Resources with MCP server (counting all pages)" TOTAL_RESOURCES=0 CURSOR="" PAGE=1 while true; do if [ -n "$CURSOR" ]; then PARAMS="{\"cursor\":\"$CURSOR\"}" else PARAMS="{}" fi RESOURCES_RESPONSE=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Accept: application/json, text/event-stream" \ -H "Mcp-Session-Id: $SESSION_ID" \ -X POST -H "Content-Type: application/json" \ -d "{\"jsonrpc\":\"2.0\",\"id\":\"resources$PAGE\",\"method\":\"resources/list\",\"params\":$PARAMS}" \ "$MCP_SERVER/mcp") if echo "$RESOURCES_RESPONSE" | grep -q "event: message"; then RESOURCES_JSON=$(echo "$RESOURCES_RESPONSE" | grep "^data: " | sed 's/^data: //') PAGE_COUNT=$(echo "$RESOURCES_JSON" | jq '.result.resources | length') NEXT_CURSOR=$(echo "$RESOURCES_JSON" | jq -r '.result.nextCursor // empty') TOTAL_RESOURCES=$((TOTAL_RESOURCES + PAGE_COUNT)) echo " ๐Ÿ“„ Page $PAGE: $PAGE_COUNT resources (total: $TOTAL_RESOURCES)" if [ -z "$NEXT_CURSOR" ]; then break fi CURSOR="$NEXT_CURSOR" PAGE=$((PAGE + 1)) else echo " โŒ Resources page $PAGE failed: $RESOURCES_RESPONSE" break fi done RESOURCE_COUNT=$TOTAL_RESOURCES echo " ๐Ÿ“Š Total Resources: $RESOURCE_COUNT (README claims: 100)" # Step 4: Test prompts with MCP SERVER echo "" echo "๐Ÿ’ญ Step 4: Test Prompts with MCP server" PROMPTS_RESPONSE=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Accept: application/json, text/event-stream" \ -H "Mcp-Session-Id: $SESSION_ID" \ -X POST -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":"prompts","method":"prompts/list"}' \ "$MCP_SERVER/mcp") if echo "$PROMPTS_RESPONSE" | grep -q "event: message"; then PROMPTS_JSON=$(echo "$PROMPTS_RESPONSE" | grep "^data: " | sed 's/^data: //') PROMPT_COUNT=$(echo "$PROMPTS_JSON" | jq '.result.prompts | length') echo " ๐Ÿ’ฌ Prompts: $PROMPT_COUNT" else echo " โŒ Prompts test failed: $PROMPTS_RESPONSE" fi echo "" echo "๐ŸŽ‰ SEPARATE MODE E2E TEST COMPLETE!" echo "===================================" echo "โœ… OAuth flow: Auth server โ†’ MCP server delegation working" echo "โœ… Token validation: MCP server accepts auth server tokens" echo "โœ… Session management: MCP server creates sessions for external tokens" echo "" echo "๐Ÿ“Š Verification Results:" echo " Tools: $TOOL_COUNT (README: 7) $([ "$TOOL_COUNT" = "7" ] && echo "โœ…" || echo "โŒ")" echo " Resources: $RESOURCE_COUNT (README: 100) $([ "$RESOURCE_COUNT" = "100" ] && echo "โœ…" || echo "โŒ")" echo " Prompts: $PROMPT_COUNT" echo "" echo "๐Ÿ—๏ธ Architecture Verified:" echo " โœ… Separate auth server provides OAuth endpoints" echo " โœ… MCP server validates tokens via introspection" echo " โœ… Session ownership works across server boundaries"