-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmcp-proxy.js
More file actions
executable file
·51 lines (39 loc) · 1.14 KB
/
mcp-proxy.js
File metadata and controls
executable file
·51 lines (39 loc) · 1.14 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
#!/usr/bin/env node
const url = process.argv[2];
if (!url) {
console.error('Usage: node mcp-proxy.js <url>');
process.exit(1);
}
async function post(payload) {
try {
if (!payload || Object.keys(payload).length === 0) return;
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (!response.ok) return; // Silence HTTP errors
const data = await response.json();
// MAGIC FIX: Cursor hates responses with id: null.
// We filter them out because they are just noise (usually empty keep-alive pings).
if (data.id === null || data.id === undefined) return;
console.log(JSON.stringify(data));
} catch (error) {
// Silence network errors to keep connection alive
}
}
process.stdin.setEncoding('utf8');
let buffer = '';
process.stdin.on('data', (chunk) => {
buffer += chunk;
const lines = buffer.split('\n');
buffer = lines.pop();
for (const line of lines) {
if (line.trim()) {
try {
const request = JSON.parse(line);
post(request);
} catch (e) {}
}
}
});