-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmcp-client.js
More file actions
executable file
·90 lines (75 loc) · 1.89 KB
/
mcp-client.js
File metadata and controls
executable file
·90 lines (75 loc) · 1.89 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
#!/usr/bin/env node
const https = require("https");
const readline = require("readline");
const MCP_SERVER_URL = "https://www.sprintiq.ai/api/mcp/server";
// Create readline interface for JSON-RPC communication
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
// Handle incoming JSON-RPC requests from Claude
rl.on("line", async (line) => {
try {
const request = JSON.parse(line);
// Forward the request to our SprintiQ MCP server
const response = await makeHttpRequest(request);
// Send response back to Claude
console.log(JSON.stringify(response));
} catch (error) {
// Send error response back to Claude
console.log(
JSON.stringify({
jsonrpc: "2.0",
id: null,
error: {
code: -32603,
message: "Internal error",
data: error.message,
},
})
);
}
});
function makeHttpRequest(data) {
return new Promise((resolve, reject) => {
const postData = JSON.stringify(data);
const options = {
hostname: "sprintiq.ai",
port: 443,
path: "/api/mcp/server",
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(postData),
},
};
const req = https.request(options, (res) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
try {
const response = JSON.parse(body);
resolve(response);
} catch (error) {
reject(new Error(`Invalid JSON response: ${body}`));
}
});
});
req.on("error", (error) => {
reject(error);
});
req.write(postData);
req.end();
});
}
// Handle graceful shutdown
process.on("SIGINT", () => {
rl.close();
process.exit(0);
});
process.on("SIGTERM", () => {
rl.close();
process.exit(0);
});