Skip to main content
Glama
test-mcp-tools-list.cjs9.62 kB
#!/usr/bin/env node const axios = require('axios'); const https = require('https'); const crypto = require('crypto'); const axiosInstance = axios.create({ httpsAgent: new https.Agent({ rejectUnauthorized: false }), timeout: 30000 }); const MCP_BASE = 'https://whether-pieces-spent-journey.trycloudflare.com'; async function testMcpToolsList() { console.log('\n════════════════════════════════════════════════════════════'); console.log(' TESTING MCP TOOLS LIST (WHAT CLAUDE SEES)'); console.log('════════════════════════════════════════════════════════════\n'); try { // Step 1: OAuth flow to get token console.log('1️⃣ Authenticating through OAuth...'); // Get metadata const metadataResponse = await axiosInstance.get(`${MCP_BASE}/.well-known/oauth-authorization-server`); console.log('✅ Got OAuth metadata\n'); // Register client const registerResponse = await axiosInstance.post(`${MCP_BASE}/register`, { client_name: "Claude Desktop Test", grant_types: ["authorization_code", "refresh_token"], response_types: ["code"], token_endpoint_auth_method: "client_secret_post", scope: "claudeai", redirect_uris: ["https://claude.ai/api/mcp/auth_callback"] }); const clientId = registerResponse.data.client_id; console.log(`✅ Registered client: ${clientId}\n`); // Login const loginResponse = await axiosInstance.post(`${MCP_BASE}/login`, 'username=david%2Ballcloud%40umbrellacost.com&password=Dsamsung1%21123&state=test&client_id=' + clientId, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, maxRedirects: 0, validateStatus: (status) => status === 302 } ); // Get session const cookies = loginResponse.headers['set-cookie']; const sidCookie = cookies?.find(c => c.startsWith('sid=')); const sid = sidCookie?.split(';')[0].split('=')[1]; // Get auth code const codeVerifier = crypto.randomBytes(32).toString('base64url'); const codeChallenge = crypto.createHash('sha256').update(codeVerifier).digest('base64url'); const authResponse = await axiosInstance.get(`${MCP_BASE}/authorize`, { params: { response_type: 'code', client_id: clientId, redirect_uri: 'https://claude.ai/api/mcp/auth_callback', state: 'test-state', code_challenge: codeChallenge, code_challenge_method: 'S256' }, headers: { 'Cookie': `sid=${sid}` } }); const codeMatch = authResponse.data.match(/code=([^&\"]+)/); const authCode = codeMatch ? codeMatch[1] : null; // Exchange for token const tokenResponse = await axiosInstance.post(`${MCP_BASE}/oauth/token`, new URLSearchParams({ grant_type: 'authorization_code', code: authCode, redirect_uri: 'https://claude.ai/api/mcp/auth_callback', client_id: clientId, code_verifier: codeVerifier }).toString(), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } } ); const accessToken = tokenResponse.data.access_token; console.log('✅ Authentication successful\n'); // Step 2: Initialize MCP console.log('2️⃣ Initializing MCP session...'); const initResponse = await axiosInstance.post(`${MCP_BASE}/mcp`, { method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "claude-desktop", version: "1.0.0" } }, jsonrpc: "2.0", id: 0 }, { headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json', 'Accept': 'application/json, text/event-stream' } }); console.log('✅ MCP session initialized'); // Parse SSE response if needed let initData; if (typeof initResponse.data === 'string' && initResponse.data.includes('event: message')) { const dataMatch = initResponse.data.match(/data: ({.*})/); if (dataMatch) { initData = JSON.parse(dataMatch[1]); } } else { initData = initResponse.data; } console.log('\n📋 Server capabilities:'); console.log(JSON.stringify(initData?.result?.serverInfo || {}, null, 2)); // Step 3: List available tools console.log('\n3️⃣ Listing available tools...'); const toolsRequest = { method: "tools/list", params: {}, jsonrpc: "2.0", id: 1 }; const toolsResponse = await axiosInstance.post(`${MCP_BASE}/mcp`, toolsRequest, { headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json', 'Accept': 'application/json, text/event-stream' } }); // Parse SSE response let toolsData; if (typeof toolsResponse.data === 'string' && toolsResponse.data.includes('event: message')) { const dataMatch = toolsResponse.data.match(/data: ({.*})/); if (dataMatch) { toolsData = JSON.parse(dataMatch[1]); } } else { toolsData = toolsResponse.data; } if (toolsData?.result?.tools) { const tools = toolsData.result.tools; console.log(`\n✅ Found ${tools.length} tools:\n`); console.log('════════════════════════════════════════════════════════════'); // List all tools tools.forEach((tool, index) => { console.log(`${index + 1}. ${tool.name}`); if (tool.description) { console.log(` ${tool.description.substring(0, 100)}...`); } }); console.log('════════════════════════════════════════════════════════════'); // Check for specific expected tools const expectedTools = ['authenticate', 'api__invoices_caui', 'api__recommendations_report']; console.log('\n🔍 Checking for expected tools:'); expectedTools.forEach(expectedTool => { const found = tools.some(t => t.name === expectedTool); console.log(` ${found ? '✅' : '❌'} ${expectedTool}`); }); // Show a sample tool schema const sampleTool = tools.find(t => t.name === 'api__invoices_caui'); if (sampleTool) { console.log('\n📊 Sample tool schema (api__invoices_caui):'); console.log(JSON.stringify(sampleTool, null, 2).substring(0, 500) + '...'); } } else { console.log('⚠️ No tools found in response'); console.log('Response:', JSON.stringify(toolsData, null, 2)); } // Step 4: Test if MCP is responsive console.log('\n4️⃣ Testing MCP responsiveness...'); const pingRequest = { method: "ping", params: {}, jsonrpc: "2.0", id: 2 }; try { const pingResponse = await axiosInstance.post(`${MCP_BASE}/mcp`, pingRequest, { headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json', 'Accept': 'application/json, text/event-stream' }, timeout: 5000 }); console.log('✅ MCP server is responsive'); } catch (pingError) { console.log('⚠️ MCP server ping failed or not supported'); } console.log('\n════════════════════════════════════════════════════════════'); console.log(' TEST COMPLETE'); console.log('════════════════════════════════════════════════════════════\n'); } catch (error) { console.error('\n❌ Error:', error.message); if (error.response) { console.error('Status:', error.response.status); console.error('Response:', JSON.stringify(error.response.data, null, 2)); } } } testMcpToolsList().catch(console.error);

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