-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-server.js
More file actions
150 lines (132 loc) · 3.18 KB
/
test-server.js
File metadata and controls
150 lines (132 loc) · 3.18 KB
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
140
141
142
143
144
145
146
147
148
149
150
/**
* Simple test script to verify the MCP server is working
* This simulates how an MCP client would interact with the server
*/
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
console.log('Starting MCP Server Test...\n');
const serverPath = join(__dirname, 'dist', 'index.js');
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe'],
});
let responseBuffer = '';
let requestId = 1;
server.stdout.on('data', (data) => {
responseBuffer += data.toString();
// Try to parse complete JSON-RPC messages
const lines = responseBuffer.split('\n');
responseBuffer = lines.pop() || ''; // Keep incomplete line in buffer
for (const line of lines) {
if (line.trim()) {
try {
const response = JSON.parse(line);
console.log('Response:', JSON.stringify(response, null, 2));
} catch (e) {
// Not JSON, might be stderr output
}
}
}
});
server.stderr.on('data', (data) => {
console.log('Server:', data.toString().trim());
});
server.on('error', (error) => {
console.error('Error:', error);
});
// Send initialization request
setTimeout(() => {
console.log('\n--- Test 1: Initialize ---');
sendRequest({
jsonrpc: '2.0',
id: requestId++,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0',
},
},
});
}, 100);
// List tools
setTimeout(() => {
console.log('\n--- Test 2: List Tools ---');
sendRequest({
jsonrpc: '2.0',
id: requestId++,
method: 'tools/list',
});
}, 500);
// Search for button component
setTimeout(() => {
console.log('\n--- Test 3: Search Components (button) ---');
sendRequest({
jsonrpc: '2.0',
id: requestId++,
method: 'tools/call',
params: {
name: 'search_components',
arguments: {
query: 'button',
},
},
});
}, 1000);
// Get button documentation
setTimeout(() => {
console.log('\n--- Test 4: Get Component Docs (button) ---');
sendRequest({
jsonrpc: '2.0',
id: requestId++,
method: 'tools/call',
params: {
name: 'get_component_docs',
arguments: {
component: 'button',
},
},
});
}, 1500);
// List all components
setTimeout(() => {
console.log('\n--- Test 5: List All Components ---');
sendRequest({
jsonrpc: '2.0',
id: requestId++,
method: 'tools/call',
params: {
name: 'list_all_components',
arguments: {},
},
});
}, 2000);
// Find by attribute
setTimeout(() => {
console.log('\n--- Test 6: Find by Attribute (disabled) ---');
sendRequest({
jsonrpc: '2.0',
id: requestId++,
method: 'tools/call',
params: {
name: 'find_by_attribute',
arguments: {
attribute: 'disabled',
},
},
});
}, 2500);
// Cleanup
setTimeout(() => {
console.log('\n--- All tests complete ---');
server.kill();
process.exit(0);
}, 3500);
function sendRequest(request) {
const message = JSON.stringify(request) + '\n';
server.stdin.write(message);
}