Skip to main content
Glama
debug-oauth-session-flow.cjs4.36 kB
#!/usr/bin/env node /** * Debug the OAuth session flow issue where sessions are created but not found */ const axios = require('axios'); const https = require('https'); const httpClient = axios.create({ httpsAgent: new https.Agent({ rejectUnauthorized: false }), timeout: 30000 }); async function debugOAuthSessionFlow() { console.log('\n🔍 Debugging OAuth Session Flow'); console.log('=' .repeat(70)); const baseUrl = 'https://127.0.0.1:8787'; const username = 'david+saola@umbrellacost.com'; const password = 'Dsamsung1!'; // Step 1: Complete OAuth flow to get token console.log('\n1️⃣ Getting OAuth token...'); const authParams = { response_type: 'code', client_id: 'claude-desktop', redirect_uri: 'https://127.0.0.1:8787/callback', state: 'test-state-123', code_challenge: 'test-challenge', code_challenge_method: 'S256' }; let authCode; try { // Submit login const loginData = { username, password, ...authParams }; const loginResponse = await httpClient.post( `${baseUrl}/login`, new URLSearchParams(loginData), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, maxRedirects: 0, validateStatus: (status) => status === 302 } ); if (loginResponse.status === 302 && loginResponse.headers.location) { const location = new URL(loginResponse.headers.location); authCode = location.searchParams.get('code'); console.log('✅ Got auth code:', authCode ? 'Yes' : 'No'); } } catch (error) { console.log('❌ Login failed:', error.message); return; } // Step 2: Exchange code for token console.log('\n2️⃣ Exchanging code for token...'); let accessToken; try { const tokenData = { grant_type: 'authorization_code', code: authCode, redirect_uri: authParams.redirect_uri, client_id: authParams.client_id, code_verifier: 'test-verifier' }; const tokenResponse = await httpClient.post( `${baseUrl}/oauth/token`, new URLSearchParams(tokenData), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } } ); if (tokenResponse.status === 200 && tokenResponse.data.access_token) { accessToken = tokenResponse.data.access_token; console.log('✅ Got access token'); } } catch (error) { console.log('❌ Token exchange failed:', error.message); return; } // Step 3: Test MCP connection with session_status console.log('\n3️⃣ Testing session_status through MCP...'); try { const mcpRequest = { jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'session_status', arguments: {} } }; const response = await httpClient.post( `${baseUrl}/mcp`, mcpRequest, { headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json' } } ); console.log('Session status response:', JSON.stringify(response.data, null, 2)); } catch (error) { console.log('❌ Session status failed:', error.message); if (error.response) { console.log('Response:', error.response.data); } } // Step 4: Test API call through MCP console.log('\n4️⃣ Testing API call through MCP...'); try { const mcpRequest = { jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: 'api___invoices_cost-summary', arguments: { month: '2024-10', vendor: 'aws' } } }; const response = await httpClient.post( `${baseUrl}/mcp`, mcpRequest, { headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json' } } ); console.log('API call response:', JSON.stringify(response.data, null, 2)); } catch (error) { console.log('❌ API call failed:', error.message); if (error.response) { console.log('Response:', error.response.data); } } console.log('\n' + '=' .repeat(70)); console.log('Debug complete - check server logs for session creation details'); } debugOAuthSessionFlow().catch(err => { console.error('Unexpected error:', err); process.exit(1); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/daviddraiumbrella/invoice-monitoring'

If you have feedback or need assistance with the MCP directory API, please join our Discord server