Skip to main content
Glama
verify-apikey-header-flow.cjs•4.56 kB
#!/usr/bin/env node const fs = require('fs'); const path = require('path'); console.log('🔍 VERIFYING: Will apikey be in headers after restart?\n'); console.log('='.repeat(80)); const apiClientPath = path.join(__dirname, '../../src/api-client.ts'); const apiClientCode = fs.readFileSync(apiClientPath, 'utf8'); console.log('\n📋 STEP 1: Check how apikey is added to headers\n'); console.log('-'.repeat(80)); // Find getAuthHeaders function const getAuthHeadersMatch = apiClientCode.match(/private getAuthHeaders\([\s\S]*?\n \}/); if (getAuthHeadersMatch) { console.log('Found getAuthHeaders function:'); const lines = getAuthHeadersMatch[0].split('\n').slice(0, 20); lines.forEach(line => console.log(' ', line)); } console.log('\n📋 STEP 2: Check where headers are sent in request\n'); console.log('-'.repeat(80)); // Find where axios config is built const axiosConfigMatches = apiClientCode.match(/const config.*?=.*?\{[\s\S]*?headers:[\s\S]*?\}/g); if (axiosConfigMatches) { console.log('Found axios config building:'); axiosConfigMatches.forEach((match, i) => { if (match.includes('getAuthHeaders')) { console.log(`\nConfig ${i + 1} (includes getAuthHeaders):`); console.log(match.substring(0, 300) + '...'); } }); } console.log('\n📋 STEP 3: Check recommendations-specific code\n'); console.log('-'.repeat(80)); // Check recommendations list handling const recsListMatch = apiClientCode.match(/if \(path === '\/v2\/recommendations\/list'\)[\s\S]*?\}/); if (recsListMatch) { console.log('Found /v2/recommendations/list handling:'); console.log(recsListMatch[0]); } // Check recommendations heatmap handling const recsHeatmapMatch = apiClientCode.match(/if \(path === '\/v1\/recommendationsNew\/heatmap\/summary'\)[\s\S]*?\}/); if (recsHeatmapMatch) { console.log('\nFound /v1/recommendationsNew/heatmap/summary handling:'); console.log(recsHeatmapMatch[0]); } console.log('\n📋 STEP 4: Trace the complete flow\n'); console.log('-'.repeat(80)); console.log(` EXPECTED FLOW AFTER RESTART: 1. Claude sends: {accountKey: "24223", divisionId: "1"} 2. server-with-auth.ts validates with QueryParamsSchema (NOW includes accountKey) 3. validatedParams.accountKey = "24223" ✅ 4. Mapping happens: validatedParams.customer_account_key = "24223" validatedParams.customer_division_id = "1" 5. api-client.ts makeRequest() is called with: params: {customer_account_key: "24223", customer_division_id: "1"} 6. getAuthHeaders(customerAccountKey="24223", customerDivisionId="1") is called 7. In getAuthHeaders: - Extracts base key: "57ade50e-c9a8-49f3-8ce7-28d44536a669" - Builds: apiKey = baseKey + ":" + customerAccountKey + ":" + customerDivisionId - Result: "57ade50e-c9a8-49f3-8ce7-28d44536a669:24223:1" 8. Returns headers object with: { "Authorization": "Bearer [token]", "apikey": "57ade50e-c9a8-49f3-8ce7-28d44536a669:24223:1" } `); console.log('\n📋 STEP 5: Check current getAuthHeaders implementation\n'); console.log('-'.repeat(80)); // Find the specific part that builds customer API key const customerKeyBuildMatch = apiClientCode.match(/\/\/ 1\. Customer-specific account key[\s\S]*?if \(customerAccountKey\) \{[\s\S]*?\}/); if (customerKeyBuildMatch) { console.log('Customer API key building logic:'); console.log(customerKeyBuildMatch[0]); } console.log('\n📋 STEP 6: CRITICAL CHECK - Is apikey added to ALL requests?\n'); console.log('-'.repeat(80)); // Check if apikey is always in headers const headersAlwaysHasApikey = apiClientCode.includes('apikey: apiKey'); console.log(`Headers object includes apikey: ${headersAlwaysHasApikey}`); // Check the actual headers construction const headersConstruction = apiClientCode.match(/return \{[\s\S]*?Authorization:[\s\S]*?apikey:[\s\S]*?\}/); if (headersConstruction) { console.log('\nHeaders construction in getAuthHeaders:'); console.log(headersConstruction[0]); } console.log('\n' + '='.repeat(80)); console.log('CONCLUSION:'); console.log('='.repeat(80)); console.log(` After restart, the apikey WILL be in headers IF: 1. ✅ accountKey passes validation (fixed by adding to schema) 2. ✅ Gets mapped to customer_account_key (server-with-auth.ts lines 776-777) 3. ✅ api-client receives customerAccountKey parameter 4. ✅ getAuthHeaders builds the correct apikey 5. ✅ Headers object includes the apikey field ALL CONDITIONS ARE MET - apikey will be in headers! Expected header: apikey: "57ade50e-c9a8-49f3-8ce7-28d44536a669:24223: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