@spuentesp/lain-mcp 0.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/README.md +54 -0
- package/bin/lain.js +29 -0
- package/bin/lain.test.js +147 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# lain-mcp
|
|
2
|
+
|
|
3
|
+
> Architectural code intelligence for AI coding agents.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g lain-mcp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or with npx (downloads binary on first run):
|
|
12
|
+
```bash
|
|
13
|
+
npx lain-mcp --workspace /path/to/project
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What this installs
|
|
17
|
+
|
|
18
|
+
- **Binary**: `~/.lain/bin/lain` — the Lain executable (downloaded from GitHub releases)
|
|
19
|
+
- **Config**: `~/.lain/tuning.toml` — default tuning parameters
|
|
20
|
+
- **Toolchains**: `~/.lain/toolchains/` — empty dir for user toolchain overrides
|
|
21
|
+
- **Models**: `~/.lain/models/` — empty dir for ONNX embedding models (optional)
|
|
22
|
+
|
|
23
|
+
## Configuration
|
|
24
|
+
|
|
25
|
+
Edit `~/.lain/tuning.toml` to customize Lain's behavior. All values are optional — omit a field to use the built-in default.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
After installation, add Lain to your MCP configuration:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"mcpServers": {
|
|
34
|
+
"lain": {
|
|
35
|
+
"command": "lain",
|
|
36
|
+
"args": ["--workspace", "/path/to/your/project"]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Or run directly:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
~/.lain/bin/lain --workspace /path/to/project --transport stdio
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Uninstall
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm uninstall -g lain-mcp
|
|
52
|
+
# Binary and config remain in ~/.lain/ — delete manually to fully remove
|
|
53
|
+
rm -rf ~/.lain
|
|
54
|
+
```
|
package/bin/lain.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Launcher stub — included in npm package.
|
|
3
|
+
// Real binary is downloaded by postinstall to ~/.lain/bin/
|
|
4
|
+
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { spawn } = require('child_process');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
|
|
9
|
+
const LAIN_DIR = path.join(process.env.HOME, '.lain');
|
|
10
|
+
const launcherName = process.platform === 'win32' ? 'lain-launcher.cmd' : 'lain-launcher';
|
|
11
|
+
const launcherPath = path.join(LAIN_DIR, 'bin', launcherName);
|
|
12
|
+
|
|
13
|
+
if (!fs.existsSync(launcherPath)) {
|
|
14
|
+
console.error(`Lain binary not found at ${launcherPath}`);
|
|
15
|
+
console.error("If you ran 'npx', the binary downloads on first install.");
|
|
16
|
+
console.error("Run: npm install -g lain-mcp (or npx lain-mcp to trigger download)");
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const child = spawn(launcherPath, process.argv.slice(2), {
|
|
21
|
+
stdio: 'inherit',
|
|
22
|
+
cwd: process.cwd(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
child.on('exit', (code) => process.exit(code ?? 0));
|
|
26
|
+
child.on('error', (err) => {
|
|
27
|
+
console.error('Failed to start lain:', err.message);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
package/bin/lain.test.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Tests for npm-shim bin/lain.js shim logic
|
|
3
|
+
|
|
4
|
+
const assert = require('assert');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
|
|
8
|
+
// ─────────────────────────────────────────────
|
|
9
|
+
// Helpers — mirror the logic in bin/lain.js
|
|
10
|
+
// ─────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
function getLauncherPath(home = os.homedir()) {
|
|
13
|
+
const LAIN_DIR = path.join(home, '.lain');
|
|
14
|
+
const isWin = process.platform === 'win32';
|
|
15
|
+
const launcherName = isWin ? 'lain-launcher.cmd' : 'lain-launcher';
|
|
16
|
+
return path.join(LAIN_DIR, 'bin', launcherName);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getLauncherContent(binaryPath, isWin = process.platform === 'win32') {
|
|
20
|
+
const launcherName = isWin ? 'lain-launcher.cmd' : 'lain-launcher';
|
|
21
|
+
return isWin
|
|
22
|
+
? `@echo off\n"${binaryPath}" %*`
|
|
23
|
+
: `#!/bin/sh\nexec "${binaryPath}" "$@"\n`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ─────────────────────────────────────────────
|
|
27
|
+
// Tests
|
|
28
|
+
// ─────────────────────────────────────────────
|
|
29
|
+
|
|
30
|
+
let passed = 0;
|
|
31
|
+
let failed = 0;
|
|
32
|
+
|
|
33
|
+
function test(name, fn) {
|
|
34
|
+
try {
|
|
35
|
+
fn();
|
|
36
|
+
console.log(` ✓ ${name}`);
|
|
37
|
+
passed++;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.log(` ✗ ${name}`);
|
|
40
|
+
console.log(` ${e.message}`);
|
|
41
|
+
failed++;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log('\n[ getLauncherPath ]');
|
|
46
|
+
|
|
47
|
+
test('launcher path for unix', () => {
|
|
48
|
+
const isWin = false;
|
|
49
|
+
const LAIN_DIR = path.join(os.homedir(), '.lain');
|
|
50
|
+
const launcherName = isWin ? 'lain-launcher.cmd' : 'lain-launcher';
|
|
51
|
+
const launcherPath = path.join(LAIN_DIR, 'bin', launcherName);
|
|
52
|
+
assert.strictEqual(launcherPath, path.join(os.homedir(), '.lain', 'bin', 'lain-launcher'));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('launcher path for windows', () => {
|
|
56
|
+
const isWin = true;
|
|
57
|
+
const LAIN_DIR = path.join(os.homedir(), '.lain');
|
|
58
|
+
const launcherName = isWin ? 'lain-launcher.cmd' : 'lain-launcher';
|
|
59
|
+
const launcherPath = path.join(LAIN_DIR, 'bin', launcherName);
|
|
60
|
+
assert.strictEqual(launcherPath, path.join(os.homedir(), '.lain', 'bin', 'lain-launcher.cmd'));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('getLauncherPath uses os.homedir()', () => {
|
|
64
|
+
const result = getLauncherPath();
|
|
65
|
+
assert.ok(result.endsWith('.lain/bin/lain-launcher'));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
console.log('\n[ launcher content ]');
|
|
69
|
+
|
|
70
|
+
test('unix launcher is valid sh script with shebang', () => {
|
|
71
|
+
const content = getLauncherContent('/home/user/.lain/bin/lain', false);
|
|
72
|
+
assert.ok(content.startsWith('#!/bin/sh'));
|
|
73
|
+
assert.ok(content.includes('exec "/home/user/.lain/bin/lain" "$@"'));
|
|
74
|
+
assert.ok(content.endsWith('\n'));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('windows launcher uses @echo off', () => {
|
|
78
|
+
const content = getLauncherContent('C:\\Users\\user\\.lain\\bin\\lain.exe', true);
|
|
79
|
+
assert.ok(content.startsWith('@echo off'));
|
|
80
|
+
assert.ok(content.includes('"C:\\Users\\user\\.lain\\bin\\lain.exe"'));
|
|
81
|
+
assert.ok(content.includes('%*'));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
console.log('\n[ shim path chain ]');
|
|
85
|
+
|
|
86
|
+
test('bin/lain.js spawns the launcher, not the binary directly', () => {
|
|
87
|
+
// Verify the launcher path exists as a distinct concept from the binary path
|
|
88
|
+
const isWin = false;
|
|
89
|
+
const LAIN_DIR = path.join(os.homedir(), '.lain');
|
|
90
|
+
const binaryName = isWin ? 'lain.exe' : 'lain';
|
|
91
|
+
const launcherName = isWin ? 'lain-launcher.cmd' : 'lain-launcher';
|
|
92
|
+
|
|
93
|
+
const binaryPath = path.join(LAIN_DIR, 'bin', binaryName); // ~/.lain/bin/lain
|
|
94
|
+
const launcherPath = path.join(LAIN_DIR, 'bin', launcherName); // ~/.lain/bin/lain-launcher
|
|
95
|
+
|
|
96
|
+
assert.notStrictEqual(binaryPath, launcherPath);
|
|
97
|
+
assert.ok(launcherPath.endsWith('lain-launcher'));
|
|
98
|
+
assert.ok(binaryPath.endsWith('lain'));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
console.log('\n[ error message correctness ]');
|
|
102
|
+
|
|
103
|
+
test('error message references launcher path, not binary', () => {
|
|
104
|
+
const isWin = false;
|
|
105
|
+
const LAIN_DIR = path.join(os.homedir(), '.lain');
|
|
106
|
+
const launcherName = isWin ? 'lain-launcher.cmd' : 'lain-launcher';
|
|
107
|
+
const launcherPath = path.join(LAIN_DIR, 'bin', launcherName);
|
|
108
|
+
|
|
109
|
+
const msg = `Lain binary not found at ${launcherPath}`;
|
|
110
|
+
// The message should mention the launcher, not the bare binary
|
|
111
|
+
assert.ok(msg.includes('lain-launcher'), 'error message should reference launcher');
|
|
112
|
+
assert.ok(!msg.includes('/lain"') || msg.includes('lain-launcher'),
|
|
113
|
+
'should not show bare binary path in error');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
console.log('\n[ spawn argument forwarding ]');
|
|
117
|
+
|
|
118
|
+
test('process.argv.slice(2) strips node and script name', () => {
|
|
119
|
+
// Simulate: node /path/to/lain.js --workspace /foo bar
|
|
120
|
+
const argv = ['node', '/path/to/lain.js', '--workspace', '/foo', 'bar'];
|
|
121
|
+
const forwarded = argv.slice(2);
|
|
122
|
+
assert.deepStrictEqual(forwarded, ['--workspace', '/foo', 'bar']);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('process.argv.slice(2) preserves all arguments', () => {
|
|
126
|
+
const argv = ['node', '/path/to/lain.js', '--transport', 'stdio', '--workspace', '/proj'];
|
|
127
|
+
const forwarded = argv.slice(2);
|
|
128
|
+
assert.deepStrictEqual(forwarded, ['--transport', 'stdio', '--workspace', '/proj']);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
console.log('\n[ exit code handling ]');
|
|
132
|
+
|
|
133
|
+
test('child exit code is passed through', () => {
|
|
134
|
+
// Simulate: code ?? 0
|
|
135
|
+
const cases = [[0, 0], [1, 1], [null, 0], [undefined, 0], [42, 42]];
|
|
136
|
+
for (const [code, expected] of cases) {
|
|
137
|
+
const result = code ?? 0;
|
|
138
|
+
assert.strictEqual(result, expected, `code=${code} should yield ${expected}`);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// ── Summary ────────────────────────────────
|
|
143
|
+
|
|
144
|
+
console.log(`\n${'─'.repeat(40)}`);
|
|
145
|
+
console.log(` Results: ${passed} passed, ${failed} failed`);
|
|
146
|
+
if (failed > 0) process.exit(1);
|
|
147
|
+
console.log(' All tests passed.\n');
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spuentesp/lain-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"mcpName": "io.github.spuentesp/lain",
|
|
5
|
+
"description": "Lain - Architectural code intelligence for AI coding agents",
|
|
6
|
+
"keywords": ["mcp", "code-intelligence", "architectural-analysis", "lain"],
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/spuentesp/lain",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/spuentesp/lain.git"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"lain": "./bin/lain.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"bin/"
|
|
18
|
+
],
|
|
19
|
+
"os": [
|
|
20
|
+
"darwin",
|
|
21
|
+
"linux",
|
|
22
|
+
"win32"
|
|
23
|
+
],
|
|
24
|
+
"cpu": [
|
|
25
|
+
"x64",
|
|
26
|
+
"arm64"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"postinstall": "node scripts/install.js"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18.0.0"
|
|
33
|
+
}
|
|
34
|
+
}
|