Skip to content

Commit 55e3360

Browse files
authored
refactor: cli as standalone (#30)
1 parent 088d564 commit 55e3360

File tree

6 files changed

+22
-24
lines changed

6 files changed

+22
-24
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The Model Context Protocol (MCP) is an open standard that enables AI assistants
1919
## Prerequisites
2020

2121
- Node.js 20.0.0 or higher
22-
- npm (or another Node package manager)
22+
- NPM (or another Node package manager)
2323

2424
## Installation
2525

@@ -63,7 +63,7 @@ These are the most relevant NPM scripts from package.json:
6363
- `build`: Build the TypeScript project (cleans dist, type-checks, bundles)
6464
- `build:clean`: Remove dist
6565
- `build:watch`: Build in watch mode
66-
- `start`: Run the built server (node dist/index.js)
66+
- `start`: Run the built server, CLI (node dist/cli.js)
6767
- `start:dev`: Run with tsx in watch mode (development)
6868
- `test`: Run linting, type-check, and unit tests in src/
6969
- `test:dev`: Jest watch mode for unit tests
@@ -182,7 +182,7 @@ Most MCP clients use a JSON configuration to specify how to start this server. T
182182
"mcpServers": {
183183
"patternfly-docs": {
184184
"command": "node",
185-
"args": ["dist/index.js"],
185+
"args": ["dist/cli.js"],
186186
"cwd": "/path/to/patternfly-mcp",
187187
"description": "PatternFly docs (local build)"
188188
}

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
".": "./dist/index.js"
99
},
1010
"bin": {
11-
"patternfly-mcp": "dist/index.js",
12-
"pf-mcp": "dist/index.js",
13-
"pfmcp": "dist/index.js"
11+
"patternfly-mcp": "dist/cli.js",
12+
"pf-mcp": "dist/cli.js",
13+
"pfmcp": "dist/cli.js"
1414
},
1515
"files": [
1616
"dist/**/*",
@@ -23,8 +23,8 @@
2323
"build:clean": "rm -rf dist",
2424
"build:watch": "npm run build -- --watch",
2525
"release": "changelog --non-cc --link-url https://github.com/patternfly/patternfly-mcp.git",
26-
"start": "node dist/index.js --verbose --log-stderr",
27-
"start:dev": "tsx watch src/index.ts",
26+
"start": "node dist/cli.js --log-stderr",
27+
"start:dev": "tsx watch src/cli.ts --verbose --log-stderr",
2828
"test": "npm run test:lint && npm run test:types && jest --roots=src/",
2929
"test:dev": "npm test -- --watchAll",
3030
"test:integration": "npm run build && jest --roots=tests/",

src/cli.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env node
2+
3+
import { main } from './index';
4+
5+
main().catch(error => {
6+
// Use console.error, log.error requires initialization
7+
console.error('Failed to start server:', error);
8+
process.exit(1);
9+
});

src/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env node
2-
31
import { parseCliOptions, type CliOptions, type DefaultOptions } from './options';
42
import { setOptions } from './options.context';
53
import { runServer, type ServerInstance } from './server';
@@ -26,13 +24,4 @@ const main = async (programmaticOptions?: Partial<DefaultOptions>): Promise<Serv
2624
}
2725
};
2826

29-
// Start the server
30-
if (process.env.NODE_ENV !== 'local') {
31-
main().catch(error => {
32-
// Use console.error, log.error requires initialization
33-
console.error('Failed to start server:', error);
34-
process.exit(1);
35-
});
36-
}
37-
3827
export { main, main as start, type CliOptions, type ServerInstance };

tests/utils/stdioTransportClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ export interface StdioTransportClient {
4141
*
4242
* @param options - Server configuration options
4343
* @param options.command - Node command to run (default: 'node')
44-
* @param options.serverPath - Path to built server (default: process.env.SERVER_PATH || 'dist/index.js')
44+
* @param options.serverPath - Path to built server (default: process.env.SERVER_PATH || 'dist/cli.js')
4545
* @param options.args - Additional args to pass to server, see app `CliOptions` for the full list (e.g., ['--docs-host'])
4646
* @param options.env - Environment variables for the child process
4747
*/
4848
export const startServer = async ({
4949
command = 'node',
50-
serverPath = process.env.SERVER_PATH || 'dist/index.js',
50+
serverPath = 'dist/cli.js',
5151
args = [],
5252
env = {}
5353
}: StartOptions = {}): Promise<StdioTransportClient> => {

0 commit comments

Comments
 (0)