-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-with-base64.js
More file actions
70 lines (61 loc) · 1.82 KB
/
Copy pathtest-with-base64.js
File metadata and controls
70 lines (61 loc) · 1.82 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
const axios = require('axios');
const fs = require('fs');
async function testMCPWithBase64() {
try {
const imageBuffer = fs.readFileSync('/Users/alex/node/fly-eye/visara/6d2649b2-7b30-4150-a668-0da27477b021.png');
const base64Image = imageBuffer.toString('base64');
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'
}
});
console.log('Initialize response received');
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('Sent initialized notification');
const analyzeResponse = await axios.post('http://localhost:9451/', {
jsonrpc: "2.0",
id: 2,
method: "tools/call",
params: {
name: "analyze_image",
arguments: {
imageBase64: base64Image,
mimeType: "image/png"
}
}
}, {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json, text/event-stream',
'MCP-Protocol-Version': '2024-11-05'
}
});
console.log('Analyze response:', analyzeResponse.data);
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
}
testMCPWithBase64();