Skip to main content
Glama
debug-mcp-response.cjs5.6 kB
#!/usr/bin/env node /** * Debug MCP response to understand what's actually being returned */ const axios = require('axios'); const https = require('https'); const httpsAgent = new https.Agent({ rejectUnauthorized: false }); const TUNNEL_URL = 'https://partition-bras-write-robust.trycloudflare.com'; const credentials = { username: 'david+saola@umbrellacost.com', password: 'Dsamsung1!' }; async function debugMcpResponse() { console.log('🔍 DEBUG: Investigating MCP Response Details\n'); try { // OAuth authentication flow const loginData = new URLSearchParams({ username: credentials.username, password: credentials.password, client_id: 'test-client', redirect_uri: 'https://claude.ai/api/mcp/auth_callback', scope: 'openid profile email', response_type: 'code', code_challenge: 'test-challenge', code_challenge_method: 'plain' }); const loginResponse = await axios.post( `${TUNNEL_URL}/login`, loginData.toString(), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, httpsAgent, maxRedirects: 0, validateStatus: status => status === 302 || status === 303 || status === 200 } ).catch(err => err.response); const cookies = loginResponse.headers['set-cookie']; const sessionCookie = cookies?.find(c => c.startsWith('sid=')); const authParams = new URLSearchParams({ response_type: 'code', client_id: 'test-client', redirect_uri: 'https://claude.ai/api/mcp/auth_callback', scope: 'openid profile email', state: 'test-state', code_challenge: 'test-challenge', code_challenge_method: 'plain' }); const authorizeHeaders = { 'User-Agent': 'Mozilla/5.0' }; if (sessionCookie) authorizeHeaders['Cookie'] = sessionCookie; const authorizeResponse = await axios.get( `${TUNNEL_URL}/authorize?${authParams.toString()}`, { headers: authorizeHeaders, httpsAgent, maxRedirects: 0, validateStatus: status => status === 200 || status === 302 } ).catch(err => err.response); let authCode; if (authorizeResponse.status === 302) { const location = authorizeResponse.headers.location; const codeMatch = location?.match(/code=([^&]+)/); authCode = codeMatch?.[1]; } else { const codeMatch = authorizeResponse.data.match(/code=([^&'"]+)/); authCode = codeMatch?.[1]; } const tokenResponse = await axios.post( `${TUNNEL_URL}/oauth/token`, { grant_type: 'authorization_code', code: authCode, code_verifier: 'test-challenge', redirect_uri: 'https://claude.ai/api/mcp/auth_callback', client_id: 'test-client' }, { httpsAgent } ); const bearerToken = tokenResponse.data.access_token; console.log('✅ Authentication successful\n'); // Test MCP tools/call method const mcpRequest = { jsonrpc: '2.0', method: 'tools/call', params: { name: 'api__invoices_caui', arguments: { startDate: '2025-03-01', endDate: '2025-07-31', periodGranLevel: 'month', groupBy: 'none', costType: '["cost", "discount"]', isUnblended: 'true' } }, id: 1 }; console.log('📊 Making MCP request...'); console.log('Request:', JSON.stringify(mcpRequest, null, 2)); const mcpResponse = await axios.post( `${TUNNEL_URL}/mcp`, mcpRequest, { headers: { 'Authorization': `Bearer ${bearerToken}`, 'Content-Type': 'application/json' }, httpsAgent } ); console.log('\n📄 FULL MCP RESPONSE:'); console.log('Status:', mcpResponse.status); console.log('Headers:', JSON.stringify(mcpResponse.headers, null, 2)); console.log('Data:', JSON.stringify(mcpResponse.data, null, 2)); // Check for error in response if (mcpResponse.data.error) { console.log('\n❌ ERROR FOUND IN RESPONSE:'); console.log('Error Code:', mcpResponse.data.error.code); console.log('Error Message:', mcpResponse.data.error.message); console.log('Error Data:', JSON.stringify(mcpResponse.data.error.data, null, 2)); } // Check for result in response if (mcpResponse.data.result) { console.log('\n✅ RESULT FOUND IN RESPONSE:'); console.log('Result Type:', typeof mcpResponse.data.result); console.log('Result Keys:', Object.keys(mcpResponse.data.result || {})); if (mcpResponse.data.result.content) { console.log('Content Length:', mcpResponse.data.result.content.length); console.log('First Content Item:', JSON.stringify(mcpResponse.data.result.content[0], null, 2)); } } // Try tools/list method to see if it works console.log('\n🔍 Testing tools/list method...'); const listRequest = { jsonrpc: '2.0', method: 'tools/list', params: {}, id: 2 }; const listResponse = await axios.post( `${TUNNEL_URL}/mcp`, listRequest, { headers: { 'Authorization': `Bearer ${bearerToken}`, 'Content-Type': 'application/json' }, httpsAgent } ); console.log('\n📋 TOOLS/LIST RESPONSE:'); console.log('Status:', listResponse.status); console.log('Data:', JSON.stringify(listResponse.data, null, 2)); } catch (error) { console.error('❌ Error:', error.response?.data || error.message); } } debugMcpResponse();

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