Skip to content

Commit 802a3eb

Browse files
committed
replace minimist with yargs, support -h and --help for cli
1 parent 7f60950 commit 802a3eb

File tree

3 files changed

+190
-28
lines changed

3 files changed

+190
-28
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"apify": "^3.4.0",
3838
"apify-client": "^2.12.3",
3939
"express": "^4.21.2",
40-
"minimist": "^1.2.8",
40+
"yargs": "^17.7.2",
4141
"zod": "^3.24.1",
4242
"zod-to-json-schema": "^3.24.1"
4343
},
@@ -47,7 +47,7 @@
4747
"@apify/eslint-config": "^1.0.0",
4848
"@apify/tsconfig": "^0.1.0",
4949
"@types/express": "^4.0.0",
50-
"@types/minimist": "^1.2.5",
50+
"@types/yargs": "^17.0.33",
5151
"@types/yargs-parser": "^21.0.3",
5252
"dotenv": "^16.4.7",
5353
"eslint": "^9.19.0",

src/stdio.ts

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,63 @@
77
*
88
* Command-line arguments:
99
* --actors - A comma-separated list of Actor full names to add to the server.
10+
* --help - Display help information
1011
*
1112
* Example:
1213
* node stdio.js --actors=apify/google-search-scraper,apify/instagram-scraper
1314
*/
1415

1516
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
16-
import minimist from 'minimist';
17+
import yargs from 'yargs';
18+
import { hideBin } from 'yargs/helpers';
1719

1820
import log from '@apify/log';
1921

2022
import { defaults } from './const.js';
2123
import { ActorsMcpServer } from './mcp/server.js';
2224
import { getActorsAsTools } from './tools/index.js';
2325

26+
// Keeping this interfafce here and not types.ts since
27+
// it is only relevant to the CLI/STDIO transport in this file
28+
/**
29+
* Interface for command line arguments
30+
*/
31+
interface CliArgs {
32+
actors?: string;
33+
'enable-adding-actors'?: boolean;
34+
enableActorAutoLoading?: boolean;
35+
}
36+
2437
// Configure logging, set to ERROR
2538
log.setLevel(log.LEVELS.ERROR);
2639

27-
// Parse command line arguments
28-
const parser = minimist;
29-
const argv = parser(process.argv.slice(2), {
30-
boolean: [
31-
'enable-adding-actors',
32-
'enableActorAutoLoading', // deprecated
33-
],
34-
string: ['actors'],
35-
default: {
36-
'enable-adding-actors': false,
37-
},
38-
});
40+
// Parse command line arguments using yargs
41+
const argv = yargs(hideBin(process.argv))
42+
.usage('Usage: $0 [options]')
43+
.option('actors', {
44+
type: 'string',
45+
describe: 'Comma-separated list of Actor full names to add to the server',
46+
example: 'apify/google-search-scraper,apify/instagram-scraper',
47+
})
48+
.option('enable-adding-actors', {
49+
type: 'boolean',
50+
default: false,
51+
describe: 'Enable dynamically adding Actors as tools based on user requests',
52+
})
53+
.option('enableActorAutoLoading', {
54+
type: 'boolean',
55+
default: false,
56+
hidden: true,
57+
describe: 'Deprecated: use enable-adding-actors instead',
58+
})
59+
.help('help')
60+
.alias('h', 'help')
61+
.version(false)
62+
.epilogue('For more information, visit https://github.com/apify/actors-mcp-server')
63+
.parseSync() as CliArgs;
64+
3965
const enableAddingActors = argv['enable-adding-actors'] || argv.enableActorAutoLoading || false;
40-
const { actors = '' } = argv;
66+
const actors = argv.actors as string || '';
4167
const actorList = actors ? actors.split(',').map((a: string) => a.trim()) : [];
4268

4369
// Validate environment

0 commit comments

Comments
 (0)