Skip to content

Commit 2fe5211

Browse files
MQ37Copilot
andauthored
fix: cli help (#125)
* replace minimist with yargs, support -h and --help for cli * Update src/stdio.ts Co-authored-by: Copilot <[email protected]> * workaround lint * comment * add how to connect help epilogue * fix lint --------- Co-authored-by: Copilot <[email protected]>
1 parent 9522625 commit 2fe5211

File tree

3 files changed

+197
-28
lines changed

3 files changed

+197
-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: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,70 @@
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+
// Had to ignore the eslint import extension error for the yargs package.
19+
// Using .js or /index.js didn't resolve it due to the @types package issues.
20+
// eslint-disable-next-line import/extensions
21+
import { hideBin } from 'yargs/helpers';
1722

1823
import log from '@apify/log';
1924

2025
import { defaults } from './const.js';
2126
import { ActorsMcpServer } from './mcp/server.js';
2227
import { getActorsAsTools } from './tools/index.js';
2328

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

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-
});
43+
// Parse command line arguments using yargs
44+
const argv = yargs(hideBin(process.argv))
45+
.usage('Usage: $0 [options]')
46+
.option('actors', {
47+
type: 'string',
48+
describe: 'Comma-separated list of Actor full names to add to the server',
49+
example: 'apify/google-search-scraper,apify/instagram-scraper',
50+
})
51+
.option('enable-adding-actors', {
52+
type: 'boolean',
53+
default: false,
54+
describe: 'Enable dynamically adding Actors as tools based on user requests',
55+
})
56+
.option('enableActorAutoLoading', {
57+
type: 'boolean',
58+
default: false,
59+
hidden: true,
60+
describe: 'Deprecated: use enable-adding-actors instead',
61+
})
62+
.help('help')
63+
.alias('h', 'help')
64+
.version(false)
65+
.epilogue(
66+
'To connect, set your MCP client server command to `npx @apify/actors-mcp-server`'
67+
+ ' and set the environment variable `APIFY_TOKEN` to your Apify API token.\n',
68+
)
69+
.epilogue('For more information, visit https://github.com/apify/actors-mcp-server')
70+
.parseSync() as CliArgs;
71+
3972
const enableAddingActors = argv['enable-adding-actors'] || argv.enableActorAutoLoading || false;
40-
const { actors = '' } = argv;
73+
const actors = argv.actors as string || '';
4174
const actorList = actors ? actors.split(',').map((a: string) => a.trim()) : [];
4275

4376
// Validate environment

0 commit comments

Comments
 (0)