Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/zenstackhq/studio-mcp-remote"
},
"bin": {
"zenstack-mcp-remote": "./dist/index.js",
"studio-mcp-remote": "./dist/index.js"
"zenstack-mcp-remote": "./dist/cli.js",
"studio-mcp-remote": "./dist/cli.js"
},
"files": [
"dist"
],
"scripts": {
"build": "tsc && chmod +x dist/index.js",
"build": "tsc && chmod +x dist/cli.js dist/index.js",
"test": "vitest run",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
Expand Down
4 changes: 4 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node
import { main } from './index.js';

main();
21 changes: 12 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { runBridgeServer, type BridgeServerController } from './server.js';

Expand Down Expand Up @@ -36,7 +36,7 @@ export function parseArgs(argv: string[]) {
return { remote, proxy, authorization };
}

async function main() {
export async function main() {
const { remote, proxy, authorization } = parseArgs(process.argv.slice(2));

if (!remote || !proxy || !authorization) {
Expand Down Expand Up @@ -79,12 +79,15 @@ async function main() {
}

const currentFile = fileURLToPath(import.meta.url);
if (
process.argv[1] === currentFile ||
process.argv[1]?.endsWith('/index.js') ||
process.argv[1]?.endsWith('/index.ts') ||
process.argv[1]?.endsWith('/cli.js') ||
process.argv[1]?.endsWith('/cli.ts')
) {
function isDirectRun() {
if (!process.argv[1]) return false;
try {
return fs.realpathSync(process.argv[1]) === currentFile;
} catch {
return false;
}
}

if (isDirectRun()) {
main();
}
20 changes: 20 additions & 0 deletions tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,23 @@ describe('parseArgs', () => {
expect(result.authorization).toBeUndefined();
});
});

describe('CLI execution', () => {
it('exits with status 1 and shows usage when required options are missing', () => {
const { execSync } = require('node:child_process');
const path = require('node:path');
const cliPath = path.resolve(__dirname, '../dist/cli.js');

let output = '';
let status = 0;
try {
execSync(`node "${cliPath}"`, { encoding: 'utf-8', stdio: 'pipe' });
} catch (err: any) {
status = err.status;
output = err.stderr.toString();
}

expect(status).toBe(1);
expect(output).toContain('Usage: zenstack-mcp-remote');
});
});
Loading