#!/usr/bin/env npx tsx import { spawn } from 'child_process'; /** * Test Reddit MCP server connection directly */ async function testRedditMCP() { console.log('šŸ” Testing Reddit MCP Server\n'); const possiblePackages = [ 'reddit-mcp', 'Reddit', '@reddit/mcp-server', 'mcp-server-reddit' ]; for (const packageName of possiblePackages) { console.log(`\nšŸ“¦ Testing: npx -y ${packageName}`); const result = await testPackage(packageName); if (result.success) { console.log(`āœ… Found working package: ${packageName}`); console.log(` Tools: ${result.tools.join(', ')}`); return; } } console.log('\nāŒ No working Reddit MCP package found'); console.log('Try searching on npm: https://www.npmjs.com/search?q=reddit%20mcp'); } function testPackage(packageName: string): Promise<{ success: boolean; tools: string[] }> { return new Promise((resolve) => { const child = spawn('npx', ['-y', packageName], { stdio: ['pipe', 'pipe', 'pipe'], env: { ...process.env }, timeout: 10000 }); let stdout = ''; let stderr = ''; const tools: string[] = []; let initialized = false; const initRequest = { jsonrpc: '2.0', method: 'initialize', params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'mcp-test', version: '1.0.0' } }, id: 1 }; const toolsRequest = { jsonrpc: '2.0', method: 'tools/list', params: {}, id: 2 }; child.stdout?.on('data', (data) => { stdout += data.toString(); const lines = data.toString().split('\n'); for (const line of lines) { if (line.trim()) { try { const parsed = JSON.parse(line); if (parsed.id === 1 && parsed.result) { initialized = true; console.log(` āœ“ Server initialized`); child.stdin?.write(JSON.stringify(toolsRequest) + '\n'); } else if (parsed.id === 2 && parsed.result?.tools) { console.log(` āœ“ Found ${parsed.result.tools.length} tools`); parsed.result.tools.forEach((tool: any) => { tools.push(tool.name); }); child.kill(); resolve({ success: true, tools }); } } catch { } } } }); child.stderr?.on('data', (data) => { stderr += data.toString(); }); child.on('error', (error) => { console.log(` āœ— Error: ${error.message}`); resolve({ success: false, tools: [] }); }); child.on('exit', (code) => { if (!initialized) { console.log(` āœ— Failed to initialize (exit code: ${code})`); if (stderr.includes('404') || stderr.includes('Not Found')) { console.log(` āœ— Package not found on npm`); } } resolve({ success: tools.length > 0, tools }); }); setTimeout(() => { child.stdin?.write(JSON.stringify(initRequest) + '\n'); }, 500); setTimeout(() => { child.kill(); resolve({ success: false, tools: [] }); }, 8000); }); } testRedditMCP().catch(console.error);