glpi-mcp-server 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +62 -0
- package/package.json +22 -0
package/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const readline = require('readline');
|
|
4
|
+
|
|
5
|
+
// Lê argumentos da linha de comando ou variáveis de ambiente
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
let url = process.env.GLPI_URL || '';
|
|
8
|
+
let token = process.env.GLPI_TOKEN || '';
|
|
9
|
+
|
|
10
|
+
for (let i = 0; i < args.length; i++) {
|
|
11
|
+
if (args[i] === '--url' && args[i + 1]) {
|
|
12
|
+
url = args[i + 1];
|
|
13
|
+
i++;
|
|
14
|
+
} else if (args[i] === '--token' && args[i + 1]) {
|
|
15
|
+
token = args[i + 1];
|
|
16
|
+
i++;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!url || !token) {
|
|
21
|
+
console.error("Uso: npx glpi-mcp-server --url <URL_DO_PLUGIN> --token <JWT_TOKEN>");
|
|
22
|
+
console.error("Ou use variáveis de ambiente GLPI_URL e GLPI_TOKEN.");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Inicia a leitura do stdio (onde a IA envia as mensagens JSON-RPC)
|
|
27
|
+
const rl = readline.createInterface({
|
|
28
|
+
input: process.stdin,
|
|
29
|
+
output: process.stdout,
|
|
30
|
+
terminal: false
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
rl.on('line', async (line) => {
|
|
34
|
+
if (!line.trim()) return;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch(url, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
'Authorization': `Bearer ${token}`
|
|
42
|
+
},
|
|
43
|
+
body: line
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const data = await response.text();
|
|
47
|
+
// Repassa a resposta de volta para a IA via stdout
|
|
48
|
+
process.stdout.write(data + "\n");
|
|
49
|
+
|
|
50
|
+
} catch (error) {
|
|
51
|
+
// Em caso de erro de rede, tenta enviar uma resposta de erro no formato JSON-RPC
|
|
52
|
+
const errorMsg = JSON.stringify({
|
|
53
|
+
jsonrpc: "2.0",
|
|
54
|
+
error: { code: -32000, message: `MCP Proxy Network Error: ${error.message}` },
|
|
55
|
+
id: null
|
|
56
|
+
});
|
|
57
|
+
process.stdout.write(errorMsg + "\n");
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Mantém o processo vivo esperando entradas
|
|
62
|
+
process.stdin.resume();
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "glpi-mcp-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Model Context Protocol (MCP) server proxy for GLPI 11 REST API",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"glpi-mcp-server": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node index.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"mcp",
|
|
14
|
+
"glpi",
|
|
15
|
+
"ai",
|
|
16
|
+
"claude",
|
|
17
|
+
"cursor",
|
|
18
|
+
"model-context-protocol"
|
|
19
|
+
],
|
|
20
|
+
"author": "Rodolpho Lopes",
|
|
21
|
+
"license": "MIT"
|
|
22
|
+
}
|