resuml 1.9.1 → 1.10.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/package.json +1 -1
- package/scripts/mcp-call.mjs +99 -0
package/package.json
CHANGED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Simple MCP client — sends one tool/resource/prompt call and prints the result.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* node scripts/mcp-call.mjs tool <toolName> '<json args>'
|
|
7
|
+
* node scripts/mcp-call.mjs resource <uri>
|
|
8
|
+
* node scripts/mcp-call.mjs prompt <name> '<json args>'
|
|
9
|
+
* node scripts/mcp-call.mjs list-tools
|
|
10
|
+
* node scripts/mcp-call.mjs list-resources
|
|
11
|
+
* node scripts/mcp-call.mjs list-prompts
|
|
12
|
+
*/
|
|
13
|
+
import { spawn } from 'child_process';
|
|
14
|
+
import { resolve, dirname } from 'path';
|
|
15
|
+
import { fileURLToPath } from 'url';
|
|
16
|
+
import { existsSync } from 'fs';
|
|
17
|
+
|
|
18
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const ROOT = resolve(__dirname, '..');
|
|
20
|
+
const entry = existsSync(resolve(ROOT, 'dist/index.js'))
|
|
21
|
+
? './dist/index.js' : './dist/index.cjs';
|
|
22
|
+
|
|
23
|
+
const [,, cmd, arg1, arg2] = process.argv;
|
|
24
|
+
|
|
25
|
+
async function run() {
|
|
26
|
+
const proc = spawn('node', [entry, 'mcp'], { cwd: ROOT, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
27
|
+
let buf = '';
|
|
28
|
+
const pending = new Map();
|
|
29
|
+
let msgId = 0;
|
|
30
|
+
|
|
31
|
+
proc.stdout.on('data', (chunk) => {
|
|
32
|
+
buf += chunk.toString();
|
|
33
|
+
let idx;
|
|
34
|
+
while ((idx = buf.indexOf('\n')) !== -1) {
|
|
35
|
+
const line = buf.slice(0, idx).trim();
|
|
36
|
+
buf = buf.slice(idx + 1);
|
|
37
|
+
if (!line) continue;
|
|
38
|
+
try {
|
|
39
|
+
const msg = JSON.parse(line);
|
|
40
|
+
if (msg.id != null && pending.has(msg.id)) {
|
|
41
|
+
const { resolve } = pending.get(msg.id);
|
|
42
|
+
pending.delete(msg.id);
|
|
43
|
+
resolve(msg);
|
|
44
|
+
}
|
|
45
|
+
} catch {}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
function send(method, params) {
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
const id = ++msgId;
|
|
52
|
+
pending.set(id, { resolve });
|
|
53
|
+
proc.stdin.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Initialize
|
|
58
|
+
await send('initialize', {
|
|
59
|
+
protocolVersion: '2025-03-26',
|
|
60
|
+
capabilities: {},
|
|
61
|
+
clientInfo: { name: 'mcp-call', version: '1.0.0' },
|
|
62
|
+
});
|
|
63
|
+
proc.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized', params: {} }) + '\n');
|
|
64
|
+
|
|
65
|
+
let result;
|
|
66
|
+
switch (cmd) {
|
|
67
|
+
case 'tool': {
|
|
68
|
+
const args = arg2 ? JSON.parse(arg2) : {};
|
|
69
|
+
result = await send('tools/call', { name: arg1, arguments: args });
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case 'resource':
|
|
73
|
+
result = await send('resources/read', { uri: arg1 });
|
|
74
|
+
break;
|
|
75
|
+
case 'prompt': {
|
|
76
|
+
const args = arg2 ? JSON.parse(arg2) : {};
|
|
77
|
+
result = await send('prompts/get', { name: arg1, arguments: args });
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case 'list-tools':
|
|
81
|
+
result = await send('tools/list', {});
|
|
82
|
+
break;
|
|
83
|
+
case 'list-resources':
|
|
84
|
+
result = await send('resources/list', {});
|
|
85
|
+
break;
|
|
86
|
+
case 'list-prompts':
|
|
87
|
+
result = await send('prompts/list', {});
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
console.error('Usage: mcp-call.mjs tool|resource|prompt|list-tools|list-resources|list-prompts');
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.log(JSON.stringify(result.result ?? result.error, null, 2));
|
|
95
|
+
proc.stdin.end();
|
|
96
|
+
proc.kill();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
run().catch(e => { console.error(e); process.exit(1); });
|