|
7 | 7 | * |
8 | 8 | * Command-line arguments: |
9 | 9 | * --actors - A comma-separated list of Actor full names to add to the server. |
| 10 | + * --help - Display help information |
10 | 11 | * |
11 | 12 | * Example: |
12 | 13 | * node stdio.js --actors=apify/google-search-scraper,apify/instagram-scraper |
13 | 14 | */ |
14 | 15 |
|
15 | 16 | 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'; |
17 | 22 |
|
18 | 23 | import log from '@apify/log'; |
19 | 24 |
|
20 | 25 | import { defaults } from './const.js'; |
21 | 26 | import { ActorsMcpServer } from './mcp/server.js'; |
22 | 27 | import { getActorsAsTools } from './tools/index.js'; |
23 | 28 |
|
| 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 | + |
24 | 40 | // Configure logging, set to ERROR |
25 | 41 | log.setLevel(log.LEVELS.ERROR); |
26 | 42 |
|
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 | + |
39 | 72 | const enableAddingActors = argv['enable-adding-actors'] || argv.enableActorAutoLoading || false; |
40 | | -const { actors = '' } = argv; |
| 73 | +const actors = argv.actors as string || ''; |
41 | 74 | const actorList = actors ? actors.split(',').map((a: string) => a.trim()) : []; |
42 | 75 |
|
43 | 76 | // Validate environment |
|
0 commit comments