-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-react-component.js
More file actions
76 lines (69 loc) · 2.21 KB
/
Copy pathtest-react-component.js
File metadata and controls
76 lines (69 loc) · 2.21 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
const axios = require('axios');
const fs = require('fs');
async function testReactComponentGeneration() {
try {
const initResponse = await axios.post('http://localhost:9451/', {
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: {
name: "test-client",
version: "1.0.0"
}
}
}, {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json, text/event-stream',
'MCP-Protocol-Version': '2024-11-05'
}
});
await axios.post('http://localhost:9451/', {
jsonrpc: "2.0",
method: "notifications/initialized"
}, {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json, text/event-stream',
'MCP-Protocol-Version': '2024-11-05'
}
});
console.log('Testing React component generation mode...');
const imageBuffer = fs.readFileSync('/Users/alex/node/fly-eye/visara/6d2649b2-7b30-4150-a668-0da27477b021.png');
const base64Image = imageBuffer.toString('base64');
const analyzeResponse = await axios.post('http://localhost:9451/', {
jsonrpc: "2.0",
id: 2,
method: "tools/call",
params: {
name: "analyze_image",
arguments: {
image: base64Image,
prompt: "react_component_generation"
}
}
}, {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json, text/event-stream',
'MCP-Protocol-Version': '2024-11-05'
}
});
const responseText = analyzeResponse.data;
const lines = responseText.split('\n');
const dataLine = lines.find(line => line.startsWith('data:'));
if (dataLine) {
const jsonData = JSON.parse(dataLine.substring(5));
console.log('✅ React component generation successful!');
console.log('📝 Result preview:', jsonData.result.content[0].text.substring(0, 300) + '...');
} else {
console.log('❌ Could not parse response');
}
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
}
testReactComponentGeneration();