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
160 changes: 148 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"apify": "^3.4.0",
"apify-client": "^2.12.3",
"express": "^4.21.2",
"minimist": "^1.2.8",
"yargs": "^17.7.2",
"zod": "^3.24.1",
"zod-to-json-schema": "^3.24.1"
},
Expand All @@ -47,7 +47,7 @@
"@apify/eslint-config": "^1.0.0",
"@apify/tsconfig": "^0.1.0",
"@types/express": "^4.0.0",
"@types/minimist": "^1.2.5",
"@types/yargs": "^17.0.33",
"@types/yargs-parser": "^21.0.3",
"dotenv": "^16.4.7",
"eslint": "^9.19.0",
Expand Down
61 changes: 47 additions & 14 deletions src/stdio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,70 @@
*
* Command-line arguments:
* --actors - A comma-separated list of Actor full names to add to the server.
* --help - Display help information
*
* Example:
* node stdio.js --actors=apify/google-search-scraper,apify/instagram-scraper
*/

import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import minimist from 'minimist';
import yargs from 'yargs';
// Had to ignore the eslint import extension error for the yargs package.
// Using .js or /index.js didn't resolve it due to the @types package issues.
// eslint-disable-next-line import/extensions
import { hideBin } from 'yargs/helpers';

import log from '@apify/log';

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

// Keeping this interface here and not types.ts since
// it is only relevant to the CLI/STDIO transport in this file
/**
* Interface for command line arguments
*/
interface CliArgs {
actors?: string;
'enable-adding-actors'?: boolean;
enableActorAutoLoading?: boolean;
}

// Configure logging, set to ERROR
log.setLevel(log.LEVELS.ERROR);

// Parse command line arguments
const parser = minimist;
const argv = parser(process.argv.slice(2), {
boolean: [
'enable-adding-actors',
'enableActorAutoLoading', // deprecated
],
string: ['actors'],
default: {
'enable-adding-actors': false,
},
});
// Parse command line arguments using yargs
const argv = yargs(hideBin(process.argv))
.usage('Usage: $0 [options]')
.option('actors', {
type: 'string',
describe: 'Comma-separated list of Actor full names to add to the server',
example: 'apify/google-search-scraper,apify/instagram-scraper',
})
.option('enable-adding-actors', {
type: 'boolean',
default: false,
describe: 'Enable dynamically adding Actors as tools based on user requests',
})
.option('enableActorAutoLoading', {
type: 'boolean',
default: false,
hidden: true,
describe: 'Deprecated: use enable-adding-actors instead',
})
.help('help')
.alias('h', 'help')
.version(false)
.epilogue(
'To connect, set your MCP client server command to `npx @apify/actors-mcp-server`'
+ ' and set the environment variable `APIFY_TOKEN` to your Apify API token.\n',
)
.epilogue('For more information, visit https://github.com/apify/actors-mcp-server')
.parseSync() as CliArgs;

const enableAddingActors = argv['enable-adding-actors'] || argv.enableActorAutoLoading || false;
const { actors = '' } = argv;
const actors = argv.actors as string || '';
const actorList = actors ? actors.split(',').map((a: string) => a.trim()) : [];

// Validate environment
Expand Down