File size: 4,232 Bytes
da2e594
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env ts-node
/**
 * Quick test script to validate the essentials implementation
 */

import { spawn } from 'child_process';
import { join } from 'path';

const colors = {
  reset: '\x1b[0m',
  bright: '\x1b[1m',
  green: '\x1b[32m',
  red: '\x1b[31m',
  yellow: '\x1b[33m',
  blue: '\x1b[34m',
  cyan: '\x1b[36m'
};

function log(message: string, color: string = colors.reset) {
  console.log(`${color}${message}${colors.reset}`);
}

async function runMCPCommand(toolName: string, args: any): Promise<any> {
  return new Promise((resolve, reject) => {
    const request = {
      jsonrpc: '2.0',
      method: 'tools/call',
      params: {
        name: toolName,
        arguments: args
      },
      id: 1
    };
    
    const mcp = spawn('npm', ['start'], {
      cwd: join(__dirname, '..'),
      stdio: ['pipe', 'pipe', 'pipe']
    });
    
    let output = '';
    let error = '';
    
    mcp.stdout.on('data', (data) => {
      output += data.toString();
    });
    
    mcp.stderr.on('data', (data) => {
      error += data.toString();
    });
    
    mcp.on('close', (code) => {
      if (code !== 0) {
        reject(new Error(`Process exited with code ${code}: ${error}`));
        return;
      }
      
      try {
        // Parse JSON-RPC response
        const lines = output.split('\n');
        for (const line of lines) {
          if (line.trim() && line.includes('"jsonrpc"')) {
            const response = JSON.parse(line);
            if (response.result) {
              resolve(JSON.parse(response.result.content[0].text));
              return;
            } else if (response.error) {
              reject(new Error(response.error.message));
              return;
            }
          }
        }
        reject(new Error('No valid response found'));
      } catch (err) {
        reject(err);
      }
    });
    
    // Send request
    mcp.stdin.write(JSON.stringify(request) + '\n');
    mcp.stdin.end();
  });
}

async function quickTest() {
  log('\n🚀 Quick Test - n8n MCP Essentials', colors.bright + colors.cyan);
  
  try {
    // Test 1: Get essentials for HTTP Request
    log('\n1️⃣  Testing get_node_essentials for HTTP Request...', colors.yellow);
    const essentials = await runMCPCommand('get_node_essentials', {
      nodeType: 'nodes-base.httpRequest'
    });
    
    log('✅ Success! Got essentials:', colors.green);
    log(`   Required properties: ${essentials.requiredProperties?.map((p: any) => p.name).join(', ') || 'None'}`);
    log(`   Common properties: ${essentials.commonProperties?.map((p: any) => p.name).join(', ') || 'None'}`);
    log(`   Examples: ${Object.keys(essentials.examples || {}).join(', ')}`);
    log(`   Response size: ${JSON.stringify(essentials).length} bytes`, colors.green);
    
    // Test 2: Search properties
    log('\n2️⃣  Testing search_node_properties...', colors.yellow);
    const searchResults = await runMCPCommand('search_node_properties', {
      nodeType: 'nodes-base.httpRequest',
      query: 'auth'
    });
    
    log('✅ Success! Found properties:', colors.green);
    log(`   Matches: ${searchResults.totalMatches}`);
    searchResults.matches?.slice(0, 3).forEach((match: any) => {
      log(`   - ${match.name}: ${match.description}`);
    });
    
    // Test 3: Compare sizes
    log('\n3️⃣  Comparing response sizes...', colors.yellow);
    const fullInfo = await runMCPCommand('get_node_info', {
      nodeType: 'nodes-base.httpRequest'
    });
    
    const fullSize = JSON.stringify(fullInfo).length;
    const essentialSize = JSON.stringify(essentials).length;
    const reduction = ((fullSize - essentialSize) / fullSize * 100).toFixed(1);
    
    log(`✅ Size comparison:`, colors.green);
    log(`   Full response: ${(fullSize / 1024).toFixed(1)} KB`);
    log(`   Essential response: ${(essentialSize / 1024).toFixed(1)} KB`);
    log(`   Size reduction: ${reduction}% 🎉`, colors.bright + colors.green);
    
    log('\n✨ All tests passed!', colors.bright + colors.green);
    
  } catch (error) {
    log(`\n❌ Test failed: ${error}`, colors.red);
    process.exit(1);
  }
}

// Run if called directly
if (require.main === module) {
  quickTest().catch(console.error);
}