@letoribo/mcpgql 1.0.2 → 1.1.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/core.ts +77 -44
- package/mcpgql.config.json +7 -0
- package/package.json +3 -2
package/core.ts
CHANGED
|
@@ -1,69 +1,102 @@
|
|
|
1
1
|
#!/usr/bin/env npx tsx
|
|
2
2
|
import { spawn } from 'child_process';
|
|
3
|
-
import * as readline from 'readline';
|
|
3
|
+
import * as readline from 'readline/promises';
|
|
4
|
+
import { stdin as input, stdout as output } from 'process';
|
|
4
5
|
import * as path from 'path';
|
|
5
6
|
import * as fs from 'fs';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
// --- Interfaces ---
|
|
9
|
+
interface Config {
|
|
10
|
+
activeEndpoints: string[];
|
|
11
|
+
endpoints: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// --- Initialization ---
|
|
15
|
+
const rl = readline.createInterface({ input, output });
|
|
16
|
+
|
|
17
|
+
const configPath = path.join(process.cwd(), 'mcpgql.config.json');
|
|
18
|
+
const config: Config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
19
|
+
const entries: [string, string][] = Object.entries(config.endpoints);
|
|
20
|
+
|
|
21
|
+
// Default: first endpoint is selected
|
|
22
|
+
const selected = new Set<string>();
|
|
23
|
+
if (entries.length > 0) selected.add(entries[0][0]);
|
|
11
24
|
|
|
12
25
|
function getDistPath(): string {
|
|
13
|
-
// 1. Try to find dist/index.js by traversing up from the current directory
|
|
14
26
|
let current = process.cwd();
|
|
15
|
-
|
|
16
27
|
while (true) {
|
|
17
28
|
const candidate = path.join(current, 'mcp-graphql-enhanced', 'dist', 'index.js');
|
|
18
|
-
if (fs.existsSync(candidate))
|
|
19
|
-
console.log(`[INFO] Found local project version: ${candidate}`);
|
|
20
|
-
return candidate;
|
|
21
|
-
}
|
|
29
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
22
30
|
const parent = path.dirname(current);
|
|
23
|
-
if (parent === current) break;
|
|
31
|
+
if (parent === current) break;
|
|
24
32
|
current = parent;
|
|
25
33
|
}
|
|
26
|
-
|
|
27
|
-
// 2. If not found locally, use the version installed in node_modules
|
|
28
|
-
console.log(`[INFO] Local build not found, using installed version.`);
|
|
29
34
|
return path.join(
|
|
30
35
|
path.dirname(require.resolve('@letoribo/mcp-graphql-enhanced/package.json')),
|
|
31
36
|
'dist/index.js'
|
|
32
37
|
);
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
// --- Core Logic ---
|
|
41
|
+
async function startSelection() {
|
|
42
|
+
while (true) {
|
|
43
|
+
console.clear();
|
|
44
|
+
console.log('\n--- Select Endpoints (Enter to confirm) ---');
|
|
45
|
+
entries.forEach(([key], i) => {
|
|
46
|
+
console.log(`${selected.has(key) ? ' [✓] ' : ' [ ] '} ${i + 1}. ${key}`);
|
|
47
|
+
});
|
|
38
48
|
|
|
39
|
-
rl.question('\
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
const choice = await rl.question('\nEnter number to toggle (or Enter to proceed): ');
|
|
50
|
+
|
|
51
|
+
if (choice.trim() === '') break;
|
|
52
|
+
|
|
53
|
+
const idx = parseInt(choice.trim()) - 1;
|
|
54
|
+
if (idx >= 0 && idx < entries.length) {
|
|
55
|
+
const key = entries[idx][0];
|
|
56
|
+
selected.has(key) ? selected.delete(key) : selected.add(key);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function main() {
|
|
62
|
+
await startSelection();
|
|
63
|
+
|
|
64
|
+
const selectedUrls = Array.from(selected).map(k => config.endpoints[k]);
|
|
65
|
+
if (selectedUrls.length === 0) {
|
|
66
|
+
console.log('[ERROR] No endpoints selected.');
|
|
67
|
+
rl.close();
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
console.log('\n1. Terminal (HTTP GraphQL Gateway)');
|
|
72
|
+
console.log('2. MCP Inspector (stdio)');
|
|
73
|
+
const mode = await rl.question('Select mode (1 or 2): ');
|
|
74
|
+
|
|
75
|
+
// Environment setup
|
|
76
|
+
const endpointString = selectedUrls.join(',');
|
|
77
|
+
const spawnEnv: Record<string, string> = {
|
|
78
|
+
...(process.env as Record<string, string>),
|
|
79
|
+
ENDPOINT: endpointString
|
|
80
|
+
};
|
|
45
81
|
|
|
46
|
-
const distPath = getDistPath();
|
|
47
|
-
|
|
48
|
-
if (!fs.existsSync(distPath)) {
|
|
49
|
-
console.error(`\n[ERROR] Build file not found at: ${distPath}`);
|
|
50
|
-
console.error('Please ensure the project is compiled (npm run build).');
|
|
51
82
|
rl.close();
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
83
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
84
|
+
const distPath = getDistPath();
|
|
85
|
+
if (mode === '1') {
|
|
86
|
+
spawnEnv['ENABLE_HTTP'] = 'true';
|
|
87
|
+
console.log(`[INFO] Launching with ENDPOINT=${endpointString}`);
|
|
88
|
+
spawn('node', [distPath], { stdio: 'inherit', cwd: process.cwd(), env: spawnEnv });
|
|
89
|
+
} else {
|
|
90
|
+
console.log('Launching in Inspector mode...');
|
|
91
|
+
spawn('npx', ['-y', '@modelcontextprotocol/inspector', 'node', distPath], {
|
|
92
|
+
stdio: 'inherit',
|
|
93
|
+
cwd: process.cwd(),
|
|
94
|
+
env: spawnEnv
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
67
98
|
|
|
68
|
-
|
|
99
|
+
main().catch(err => {
|
|
100
|
+
console.error(err);
|
|
101
|
+
process.exit(1);
|
|
69
102
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@letoribo/mcpgql",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "CLI tool for MCP GraphQL Enhanced",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"index.js",
|
|
11
|
-
"core.ts"
|
|
11
|
+
"core.ts",
|
|
12
|
+
"mcpgql.config.json"
|
|
12
13
|
],
|
|
13
14
|
"scripts": {
|
|
14
15
|
"test": "echo \"Error: no test specified\" && exit 1"
|