@apify/actors-mcp-server 0.1.22-beta.14 → 0.1.22-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/README.md +62 -64
  2. package/dist/actors.d.ts +74 -0
  3. package/dist/actors.d.ts.map +1 -0
  4. package/dist/actors.js +327 -0
  5. package/dist/actors.js.map +1 -0
  6. package/dist/const.d.ts +19 -14
  7. package/dist/const.d.ts.map +1 -1
  8. package/dist/const.js +23 -22
  9. package/dist/const.js.map +1 -1
  10. package/dist/examples/clientSse.d.ts +1 -11
  11. package/dist/examples/clientSse.d.ts.map +1 -1
  12. package/dist/examples/clientSse.js +10 -13
  13. package/dist/examples/clientSse.js.map +1 -1
  14. package/dist/examples/clientStdio.js +6 -6
  15. package/dist/examples/clientStdio.js.map +1 -1
  16. package/dist/examples/clientStdioChat.js +16 -31
  17. package/dist/examples/clientStdioChat.js.map +1 -1
  18. package/dist/index.d.ts +14 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +51 -6
  21. package/dist/index.js.map +1 -1
  22. package/dist/{actor/input.d.ts → input.d.ts} +1 -1
  23. package/dist/input.d.ts.map +1 -0
  24. package/dist/input.js +23 -0
  25. package/dist/input.js.map +1 -0
  26. package/dist/logger.d.ts +3 -0
  27. package/dist/logger.d.ts.map +1 -0
  28. package/dist/logger.js +4 -0
  29. package/dist/logger.js.map +1 -0
  30. package/dist/main.d.ts +0 -4
  31. package/dist/main.d.ts.map +1 -1
  32. package/dist/main.js +122 -23
  33. package/dist/main.js.map +1 -1
  34. package/dist/server.d.ts +43 -0
  35. package/dist/server.d.ts.map +1 -0
  36. package/dist/server.js +178 -0
  37. package/dist/server.js.map +1 -0
  38. package/dist/tools.d.ts +46 -0
  39. package/dist/tools.d.ts.map +1 -0
  40. package/dist/tools.js +128 -0
  41. package/dist/tools.js.map +1 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/dist/types.d.ts +10 -70
  44. package/dist/types.d.ts.map +1 -1
  45. package/package.json +15 -17
  46. package/dist/actor/const.d.ts +0 -12
  47. package/dist/actor/const.d.ts.map +0 -1
  48. package/dist/actor/const.js +0 -18
  49. package/dist/actor/const.js.map +0 -1
  50. package/dist/actor/input.d.ts.map +0 -1
  51. package/dist/actor/input.js +0 -21
  52. package/dist/actor/input.js.map +0 -1
  53. package/dist/actor/server.d.ts +0 -4
  54. package/dist/actor/server.d.ts.map +0 -1
  55. package/dist/actor/server.js +0 -154
  56. package/dist/actor/server.js.map +0 -1
  57. package/dist/actor/types.d.ts +0 -30
  58. package/dist/actor/types.d.ts.map +0 -1
  59. package/dist/actor/types.js +0 -2
  60. package/dist/actor/types.js.map +0 -1
  61. package/dist/actor/utils.d.ts +0 -11
  62. package/dist/actor/utils.d.ts.map +0 -1
  63. package/dist/actor/utils.js +0 -50
  64. package/dist/actor/utils.js.map +0 -1
  65. package/dist/examples/clientStreamableHttp.d.ts +0 -2
  66. package/dist/examples/clientStreamableHttp.d.ts.map +0 -1
  67. package/dist/examples/clientStreamableHttp.js +0 -93
  68. package/dist/examples/clientStreamableHttp.js.map +0 -1
  69. package/dist/mcp-server.d.ts +0 -39
  70. package/dist/mcp-server.d.ts.map +0 -1
  71. package/dist/mcp-server.js +0 -165
  72. package/dist/mcp-server.js.map +0 -1
  73. package/dist/stdio.d.ts +0 -15
  74. package/dist/stdio.d.ts.map +0 -1
  75. package/dist/stdio.js +0 -46
  76. package/dist/stdio.js.map +0 -1
  77. package/dist/tools/actor.d.ts +0 -37
  78. package/dist/tools/actor.d.ts.map +0 -1
  79. package/dist/tools/actor.js +0 -90
  80. package/dist/tools/actor.js.map +0 -1
  81. package/dist/tools/build.d.ts +0 -12
  82. package/dist/tools/build.d.ts.map +0 -1
  83. package/dist/tools/build.js +0 -121
  84. package/dist/tools/build.js.map +0 -1
  85. package/dist/tools/helpers.d.ts +0 -19
  86. package/dist/tools/helpers.d.ts.map +0 -1
  87. package/dist/tools/helpers.js +0 -62
  88. package/dist/tools/helpers.js.map +0 -1
  89. package/dist/tools/index.d.ts +0 -6
  90. package/dist/tools/index.d.ts.map +0 -1
  91. package/dist/tools/index.js +0 -8
  92. package/dist/tools/index.js.map +0 -1
  93. package/dist/tools/mcp-apify-client.d.ts +0 -6
  94. package/dist/tools/mcp-apify-client.d.ts.map +0 -1
  95. package/dist/tools/mcp-apify-client.js +0 -24
  96. package/dist/tools/mcp-apify-client.js.map +0 -1
  97. package/dist/tools/store_collection.d.ts +0 -21
  98. package/dist/tools/store_collection.d.ts.map +0 -1
  99. package/dist/tools/store_collection.js +0 -81
  100. package/dist/tools/store_collection.js.map +0 -1
  101. package/dist/tools/utils.d.ts +0 -77
  102. package/dist/tools/utils.d.ts.map +0 -1
  103. package/dist/tools/utils.js +0 -202
  104. package/dist/tools/utils.js.map +0 -1
@@ -1,93 +0,0 @@
1
- import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
- import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
3
- import { CallToolResultSchema, ListToolsResultSchema, LoggingMessageNotificationSchema, } from '@modelcontextprotocol/sdk/types.js';
4
- import log from '@apify/log';
5
- log.setLevel(log.LEVELS.DEBUG);
6
- async function main() {
7
- // Create a new client with streamable HTTP transport
8
- const client = new Client({
9
- name: 'example-client',
10
- version: '1.0.0',
11
- });
12
- const transport = new StreamableHTTPClientTransport(new URL('http://localhost:3000/mcp'));
13
- // Connect the client using the transport and initialize the server
14
- await client.connect(transport);
15
- log.debug('Connected to MCP server');
16
- // Set up notification handlers for server-initiated messages
17
- client.setNotificationHandler(LoggingMessageNotificationSchema, (notification) => {
18
- log.debug(`Notification received: ${notification.params.level} - ${notification.params.data}`);
19
- });
20
- // List and call tools
21
- await listTools(client);
22
- await callSearchTool(client);
23
- await callActor(client);
24
- // Keep the connection open to receive notifications
25
- log.debug('\nKeeping connection open to receive notifications. Press Ctrl+C to exit.');
26
- }
27
- async function listTools(client) {
28
- try {
29
- const toolsRequest = {
30
- method: 'tools/list',
31
- params: {},
32
- };
33
- const toolsResult = await client.request(toolsRequest, ListToolsResultSchema);
34
- log.debug(`Tools available, count: ${toolsResult.tools.length}`);
35
- for (const tool of toolsResult.tools) {
36
- log.debug(`Tool: ${tool.name}, Description: ${tool.description}`);
37
- }
38
- if (toolsResult.tools.length === 0) {
39
- log.debug('No tools available from the server');
40
- }
41
- }
42
- catch (error) {
43
- log.error(`Tools not supported by this server (${error})`);
44
- }
45
- }
46
- async function callSearchTool(client) {
47
- try {
48
- const searchRequest = {
49
- method: 'tools/call',
50
- params: {
51
- name: 'search',
52
- arguments: { search: 'rag web browser', limit: 1 },
53
- },
54
- };
55
- const searchResult = await client.request(searchRequest, CallToolResultSchema);
56
- log.debug('Search result:');
57
- searchResult.content.forEach((item) => {
58
- if (item.type === 'text') {
59
- log.debug(`\t${item.text}`);
60
- }
61
- });
62
- }
63
- catch (error) {
64
- log.error(`Error calling greet tool: ${error}`);
65
- }
66
- }
67
- async function callActor(client) {
68
- try {
69
- log.debug('\nCalling Actor...');
70
- const actorRequest = {
71
- method: 'tools/call',
72
- params: {
73
- name: 'apify/rag-web-browser',
74
- arguments: { query: 'apify mcp server' },
75
- },
76
- };
77
- const actorResult = await client.request(actorRequest, CallToolResultSchema);
78
- log.debug('Actor results:');
79
- actorResult.content.forEach((item) => {
80
- if (item.type === 'text') {
81
- log.debug(`- ${item.text}`);
82
- }
83
- });
84
- }
85
- catch (error) {
86
- log.error(`Error calling Actor: ${error}`);
87
- }
88
- }
89
- main().catch((error) => {
90
- log.error('Error running MCP client:', error);
91
- process.exit(1);
92
- });
93
- //# sourceMappingURL=clientStreamableHttp.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"clientStreamableHttp.js","sourceRoot":"","sources":["../../src/examples/clientStreamableHttp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,MAA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;IACpD,CAAC;AACL,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,MAAc;IACnC,IAAI,CAAC;QACD,GAAG,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAChC,MAAM,YAAY,GAAoB;YAClC,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE;gBACJ,IAAI,EAAE,uBAAuB;gBAC7B,SAAS,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE;aAC3C;SACJ,CAAC;QACF,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;QAC7E,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC5B,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACjC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBACvB,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAChC,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,GAAG,CAAC,KAAK,CAAC,wBAAwB,KAAK,EAAE,CAAC,CAAC;IAC/C,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC5B,GAAG,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAc,CAAC,CAAC;IACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
@@ -1,39 +0,0 @@
1
- /**
2
- * Model Context Protocol (MCP) server for Apify Actors
3
- */
4
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
5
- import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
6
- import type { ToolWrap } from './types.js';
7
- /**
8
- * Create Apify MCP server
9
- */
10
- export declare class ActorsMcpServer {
11
- readonly server: Server;
12
- readonly tools: Map<string, ToolWrap>;
13
- constructor();
14
- /**
15
- * Loads missing default tools.
16
- */
17
- loadDefaultTools(): Promise<void>;
18
- /**
19
- * Loads tools from URL params.
20
- *
21
- * Used primarily for SSE.
22
- */
23
- loadToolsFromUrl(url: string): Promise<void>;
24
- /**
25
- * Upsert new tools.
26
- * @param tools - Array of tool wrappers.
27
- * @returns Array of tool wrappers.
28
- */
29
- updateTools(tools: ToolWrap[]): ToolWrap[];
30
- /**
31
- * Returns an array of tool names.
32
- * @returns {string[]} - An array of tool names.
33
- */
34
- getToolNames(): string[];
35
- private setupErrorHandling;
36
- private setupToolHandlers;
37
- connect(transport: Transport): Promise<void>;
38
- }
39
- //# sourceMappingURL=mcp-server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAa/E,OAAO,KAAK,EAAyB,QAAQ,EAAE,MAAM,YAAY,CAAC;AAElE;;GAEG;AACH,qBAAa,eAAe;IACxB,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;;IAuB7C;;OAEG;IACU,gBAAgB;IAM7B;;;;OAIG;IACU,gBAAgB,CAAC,GAAG,EAAE,MAAM;IAKzC;;;;OAIG;IACI,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE;IAQpC;;;OAGG;IACI,YAAY,IAAI,MAAM,EAAE;IAI/B,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;IAiFnB,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAGrD"}
@@ -1,165 +0,0 @@
1
- /**
2
- * Model Context Protocol (MCP) server for Apify Actors
3
- */
4
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
5
- import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
6
- import log from '@apify/log';
7
- import { processParamsGetTools } from './actor/utils.js';
8
- import { ACTOR_OUTPUT_MAX_CHARS_PER_ITEM, ACTOR_OUTPUT_TRUNCATED_MESSAGE, defaults, SERVER_NAME, SERVER_VERSION } from './const.js';
9
- import { actorDefinitionTool, callActorGetDataset, getActorsAsTools, searchTool } from './tools/index.js';
10
- import { actorNameToToolName } from './tools/utils.js';
11
- /**
12
- * Create Apify MCP server
13
- */
14
- export class ActorsMcpServer {
15
- constructor() {
16
- Object.defineProperty(this, "server", {
17
- enumerable: true,
18
- configurable: true,
19
- writable: true,
20
- value: void 0
21
- });
22
- Object.defineProperty(this, "tools", {
23
- enumerable: true,
24
- configurable: true,
25
- writable: true,
26
- value: void 0
27
- });
28
- this.server = new Server({
29
- name: SERVER_NAME,
30
- version: SERVER_VERSION,
31
- }, {
32
- capabilities: {
33
- tools: { listChanged: true },
34
- logging: {},
35
- },
36
- });
37
- this.tools = new Map();
38
- this.setupErrorHandling();
39
- this.setupToolHandlers();
40
- // Add default tools
41
- this.updateTools([searchTool, actorDefinitionTool]);
42
- }
43
- /**
44
- * Loads missing default tools.
45
- */
46
- async loadDefaultTools() {
47
- const missingDefaultTools = defaults.actors.filter((name) => !this.tools.has(actorNameToToolName(name)));
48
- const tools = await getActorsAsTools(missingDefaultTools);
49
- if (tools.length > 0)
50
- this.updateTools(tools);
51
- }
52
- /**
53
- * Loads tools from URL params.
54
- *
55
- * Used primarily for SSE.
56
- */
57
- async loadToolsFromUrl(url) {
58
- const tools = await processParamsGetTools(url);
59
- if (tools.length > 0)
60
- this.updateTools(tools);
61
- }
62
- /**
63
- * Upsert new tools.
64
- * @param tools - Array of tool wrappers.
65
- * @returns Array of tool wrappers.
66
- */
67
- updateTools(tools) {
68
- for (const wrap of tools) {
69
- this.tools.set(wrap.tool.name, wrap);
70
- log.info(`Added/updated tool: ${wrap.tool.name}`);
71
- }
72
- return tools;
73
- }
74
- /**
75
- * Returns an array of tool names.
76
- * @returns {string[]} - An array of tool names.
77
- */
78
- getToolNames() {
79
- return Array.from(this.tools.keys());
80
- }
81
- setupErrorHandling() {
82
- this.server.onerror = (error) => {
83
- console.error('[MCP Error]', error); // eslint-disable-line no-console
84
- };
85
- process.on('SIGINT', async () => {
86
- await this.server.close();
87
- process.exit(0);
88
- });
89
- }
90
- setupToolHandlers() {
91
- /**
92
- * Handles the request to list tools.
93
- * @param {object} request - The request object.
94
- * @returns {object} - The response object containing the tools.
95
- */
96
- this.server.setRequestHandler(ListToolsRequestSchema, async () => {
97
- // TODO if there is actor-mcp as a tool, also list the tools from that Actor
98
- const tools = Array.from(this.tools.values()).map((tool) => (tool.tool));
99
- return { tools };
100
- });
101
- /**
102
- * Handles the request to call a tool.
103
- * @param {object} request - The request object containing tool name and arguments.
104
- * @throws {Error} - Throws an error if the tool is unknown or arguments are invalid.
105
- */
106
- this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
107
- const { name, arguments: args } = request.params;
108
- const apifyToken = request.params.apifyToken || process.env.APIFY_TOKEN;
109
- // Validate token
110
- if (!apifyToken) {
111
- throw new Error('APIFY_TOKEN is required but not set in the environment variables or passed as a parameter.');
112
- }
113
- // Find tool by name or actor full name
114
- const tool = Array.from(this.tools.values())
115
- .find((t) => t.tool.name === name || (t.type === 'actor' && t.tool.actorFullName === name));
116
- if (!tool) {
117
- // TODO: handle errors better, server.sendLoggingMessage ( )
118
- throw new Error(`Unknown tool: ${name}`);
119
- }
120
- if (!args) {
121
- throw new Error(`Missing arguments for tool: ${name}`);
122
- }
123
- log.info(`Validate arguments for tool: ${tool.tool.name} with arguments: ${JSON.stringify(args)}`);
124
- if (!tool.tool.ajvValidate(args)) {
125
- throw new Error(`Invalid arguments for tool ${tool.tool.name}: args: ${JSON.stringify(args)} error: ${JSON.stringify(tool === null || tool === void 0 ? void 0 : tool.tool.ajvValidate.errors)}`);
126
- }
127
- try {
128
- // Handle internal tool
129
- if (tool.type === 'internal') {
130
- const internalTool = tool.tool;
131
- const res = await internalTool.call({
132
- args,
133
- apifyMcpServer: this,
134
- mcpServer: this.server,
135
- });
136
- return { ...res };
137
- }
138
- // Handle actor tool
139
- if (tool.type === 'actor') {
140
- const actorTool = tool.tool;
141
- const callOptions = {
142
- memory: actorTool.memoryMbytes,
143
- };
144
- const items = await callActorGetDataset(actorTool.actorFullName, args, apifyToken, callOptions);
145
- const content = items.map((item) => {
146
- const text = JSON.stringify(item).slice(0, ACTOR_OUTPUT_MAX_CHARS_PER_ITEM);
147
- return text.length === ACTOR_OUTPUT_MAX_CHARS_PER_ITEM
148
- ? { type: 'text', text: `${text} ... ${ACTOR_OUTPUT_TRUNCATED_MESSAGE}` }
149
- : { type: 'text', text };
150
- });
151
- return { content };
152
- }
153
- }
154
- catch (error) {
155
- log.error(`Error calling tool: ${error}`);
156
- throw new Error(`Error calling tool: ${error}`);
157
- }
158
- throw new Error(`Tool ${name} is not implemented`);
159
- });
160
- }
161
- async connect(transport) {
162
- await this.server.connect(transport);
163
- }
164
- }
165
- //# sourceMappingURL=mcp-server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAEnE,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAGnG,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,+BAA+B,EACpC,8BAA8B,EAC9B,QAAQ,EAAE,WAAW,EACrB,cAAc,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,UAAU,EAAE,M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CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,GAAG,CAAC,KAAK,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC;gBAC1C,MAAM,IAAI,KAAK,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC;YACpD,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,qBAAqB,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,SAAoB;QAC9B,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;CACJ"}
package/dist/stdio.d.ts DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * This script initializes and starts the Apify MCP server using the Stdio transport.
4
- *
5
- * Usage:
6
- * node <script_name> --actors=<actor1,actor2,...>
7
- *
8
- * Command-line arguments:
9
- * --actors - A comma-separated list of Actor full names to add to the server.
10
- *
11
- * Example:
12
- * node stdio.js --actors=apify/google-search-scraper,apify/instagram-scraper
13
- */
14
- export {};
15
- //# sourceMappingURL=stdio.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;GAWG"}
package/dist/stdio.js DELETED
@@ -1,46 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * This script initializes and starts the Apify MCP server using the Stdio transport.
4
- *
5
- * Usage:
6
- * node <script_name> --actors=<actor1,actor2,...>
7
- *
8
- * Command-line arguments:
9
- * --actors - A comma-separated list of Actor full names to add to the server.
10
- *
11
- * Example:
12
- * node stdio.js --actors=apify/google-search-scraper,apify/instagram-scraper
13
- */
14
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
15
- import minimist from 'minimist';
16
- import log from '@apify/log';
17
- import { defaults } from './const.js';
18
- import { ActorsMcpServer } from './mcp-server.js';
19
- import { addTool, getActorsAsTools, removeTool } from './tools/index.js';
20
- // Configure logging, set to ERROR
21
- log.setLevel(log.LEVELS.ERROR);
22
- // Parse command line arguments
23
- const { actors = '', enableActorAutoLoading = false } = minimist(process.argv.slice(2));
24
- const actorList = actors ? actors.split(',').map((a) => a.trim()) : [];
25
- // Validate environment
26
- if (!process.env.APIFY_TOKEN) {
27
- log.error('APIFY_TOKEN is required but not set in the environment variables.');
28
- process.exit(1);
29
- }
30
- async function main() {
31
- const mcpServer = new ActorsMcpServer();
32
- // Initialize tools
33
- const tools = await getActorsAsTools(actorList.length ? actorList : defaults.actors);
34
- if (enableActorAutoLoading) {
35
- tools.push(addTool, removeTool);
36
- }
37
- mcpServer.updateTools(tools);
38
- // Start server
39
- const transport = new StdioServerTransport();
40
- await mcpServer.connect(transport);
41
- }
42
- main().catch((error) => {
43
- log.error('Server error:', error);
44
- process.exit(1);
45
- });
46
- //# sourceMappingURL=stdio.js.map
package/dist/stdio.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"stdio.js","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEzE,kCAAkC;AAClC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAE/B,+BAA+B;AAC/B,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,sBAAsB,GAAG,KAAK,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACxF,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAE/E,uBAAuB;AACvB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;IAC3B,GAAG,CAAC,KAAK,CAAC,mEAAmE,CAAC,CAAC;IAC/E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC;AAED,KAAK,UAAU,IAAI;IACf,MAAM,SAAS,GAAG,IAAI,eAAe,EAAE,CAAC;IACxC,mBAAmB;IACnB,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACrF,IAAI,sBAAsB,EAAE,CAAC;QACzB,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACpC,CAAC;IACD,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAE7B,eAAe;IACf,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACnB,GAAG,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IAClC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
@@ -1,37 +0,0 @@
1
- import type { ActorCallOptions } from 'apify-client';
2
- import type { ToolWrap } from '../types.js';
3
- /**
4
- * Calls an Apify actor and retrieves the dataset items.
5
- *
6
- *
7
- * It requires the `APIFY_TOKEN` environment variable to be set.
8
- * If the `APIFY_IS_AT_HOME` the dataset items are pushed to the Apify dataset.
9
- *
10
- * @param {string} actorName - The name of the actor to call.
11
- * @param {ActorCallOptions} callOptions - The options to pass to the actor.
12
- * @param {unknown} input - The input to pass to the actor.
13
- * @param {string} apifyToken - The Apify token to use for authentication.
14
- * @returns {Promise<object[]>} - A promise that resolves to an array of dataset items.
15
- * @throws {Error} - Throws an error if the `APIFY_TOKEN` is not set
16
- */
17
- export declare function callActorGetDataset(actorName: string, input: unknown, apifyToken: string, callOptions?: ActorCallOptions | undefined): Promise<object[]>;
18
- /**
19
- * Fetches actor input schemas by Actor IDs or Actor full names and creates MCP tools.
20
- *
21
- * This function retrieves the input schemas for the specified actors and compiles them into MCP tools.
22
- * It uses the AJV library to validate the input schemas.
23
- *
24
- * Tool name can't contain /, so it is replaced with _
25
- *
26
- * The input schema processing workflow:
27
- * 1. Properties are marked as required using markInputPropertiesAsRequired() to add "REQUIRED" prefix to descriptions
28
- * 2. Nested properties are built by analyzing editor type (proxy, requestListSources) using buildNestedProperties()
29
- * 3. Properties are filtered using filterSchemaProperties()
30
- * 4. Properties are shortened using shortenProperties()
31
- * 5. Enums are added to descriptions with examples using addEnumsToDescriptionsWithExamples()
32
- *
33
- * @param {string[]} actors - An array of actor IDs or Actor full names.
34
- * @returns {Promise<Tool[]>} - A promise that resolves to an array of MCP tools.
35
- */
36
- export declare function getActorsAsTools(actors: string[]): Promise<ToolWrap[]>;
37
- //# sourceMappingURL=actor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../../src/tools/actor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAY5C;;;;;;;;;;;;;GAaG;AACH,wBAAsB,mBAAmB,CACrC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,OAAO,EACd,UAAU,EAAE,MAAM,EAClB,WAAW,GAAE,gBAAgB,GAAG,SAAqB,GACtD,OAAO,CAAC,MAAM,EAAE,CAAC,CAiBnB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAgC5E"}
@@ -1,90 +0,0 @@
1
- import { Ajv } from 'ajv';
2
- import log from '@apify/log';
3
- import { ACTOR_ADDITIONAL_INSTRUCTIONS, ACTOR_MAX_MEMORY_MBYTES } from '../const.js';
4
- import { getActorDefinition } from './build.js';
5
- import { ApifyClient } from './mcp-apify-client.js';
6
- import { actorNameToToolName, addEnumsToDescriptionsWithExamples, buildNestedProperties, filterSchemaProperties, markInputPropertiesAsRequired, shortenProperties, } from './utils.js';
7
- /**
8
- * Calls an Apify actor and retrieves the dataset items.
9
- *
10
- *
11
- * It requires the `APIFY_TOKEN` environment variable to be set.
12
- * If the `APIFY_IS_AT_HOME` the dataset items are pushed to the Apify dataset.
13
- *
14
- * @param {string} actorName - The name of the actor to call.
15
- * @param {ActorCallOptions} callOptions - The options to pass to the actor.
16
- * @param {unknown} input - The input to pass to the actor.
17
- * @param {string} apifyToken - The Apify token to use for authentication.
18
- * @returns {Promise<object[]>} - A promise that resolves to an array of dataset items.
19
- * @throws {Error} - Throws an error if the `APIFY_TOKEN` is not set
20
- */
21
- export async function callActorGetDataset(actorName, input, apifyToken, callOptions = undefined) {
22
- const name = actorName;
23
- try {
24
- log.info(`Calling Actor ${name} with input: ${JSON.stringify(input)}`);
25
- const client = new ApifyClient({ token: apifyToken });
26
- const actorClient = client.actor(name);
27
- const results = await actorClient.call(input, callOptions);
28
- const dataset = await client.dataset(results.defaultDatasetId).listItems();
29
- log.info(`Actor ${name} finished with ${dataset.items.length} items`);
30
- return dataset.items;
31
- }
32
- catch (error) {
33
- log.error(`Error calling actor: ${error}. Actor: ${name}, input: ${JSON.stringify(input)}`);
34
- throw new Error(`Error calling Actor: ${error}`);
35
- }
36
- }
37
- /**
38
- * Fetches actor input schemas by Actor IDs or Actor full names and creates MCP tools.
39
- *
40
- * This function retrieves the input schemas for the specified actors and compiles them into MCP tools.
41
- * It uses the AJV library to validate the input schemas.
42
- *
43
- * Tool name can't contain /, so it is replaced with _
44
- *
45
- * The input schema processing workflow:
46
- * 1. Properties are marked as required using markInputPropertiesAsRequired() to add "REQUIRED" prefix to descriptions
47
- * 2. Nested properties are built by analyzing editor type (proxy, requestListSources) using buildNestedProperties()
48
- * 3. Properties are filtered using filterSchemaProperties()
49
- * 4. Properties are shortened using shortenProperties()
50
- * 5. Enums are added to descriptions with examples using addEnumsToDescriptionsWithExamples()
51
- *
52
- * @param {string[]} actors - An array of actor IDs or Actor full names.
53
- * @returns {Promise<Tool[]>} - A promise that resolves to an array of MCP tools.
54
- */
55
- export async function getActorsAsTools(actors) {
56
- var _a;
57
- const ajv = new Ajv({ coerceTypes: 'array', strict: false });
58
- const results = await Promise.all(actors.map(getActorDefinition));
59
- const tools = [];
60
- for (const result of results) {
61
- if (result) {
62
- if (result.input && 'properties' in result.input && result.input) {
63
- result.input.properties = markInputPropertiesAsRequired(result.input);
64
- result.input.properties = buildNestedProperties(result.input.properties);
65
- result.input.properties = filterSchemaProperties(result.input.properties);
66
- result.input.properties = shortenProperties(result.input.properties);
67
- result.input.properties = addEnumsToDescriptionsWithExamples(result.input.properties);
68
- }
69
- try {
70
- const memoryMbytes = ((_a = result.defaultRunOptions) === null || _a === void 0 ? void 0 : _a.memoryMbytes) || ACTOR_MAX_MEMORY_MBYTES;
71
- tools.push({
72
- type: 'actor',
73
- tool: {
74
- name: actorNameToToolName(result.actorFullName),
75
- actorFullName: result.actorFullName,
76
- description: `${result.description} Instructions: ${ACTOR_ADDITIONAL_INSTRUCTIONS}`,
77
- inputSchema: result.input || {},
78
- ajvValidate: ajv.compile(result.input || {}),
79
- memoryMbytes: memoryMbytes > ACTOR_MAX_MEMORY_MBYTES ? ACTOR_MAX_MEMORY_MBYTES : memoryMbytes,
80
- },
81
- });
82
- }
83
- catch (validationError) {
84
- log.error(`Failed to compile AJV schema for Actor: ${result.actorFullName}. Error: ${validationError}`);
85
- }
86
- }
87
- }
88
- return tools;
89
- }
90
- //# sourceMappingURL=actor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actor.js","sourceRoot":"","sources":["../../src/tools/actor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG1B,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAErF,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACH,mBAAmB,EACnB,kCAAkC,EAClC,qBAAqB,EACrB,sBAAsB,EACtB,6BAA6B,EAC7B,iBAAiB,GACpB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACrC,SAAiB,EACjB,KAAc,EACd,UAAkB,EAClB,cAA4C,SAAS;IAErD,MAAM,IAAI,GAAG,SAAS,CAAC;IACvB,IAAI,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,iBAAiB,IAAI,gBAAgB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAEvE,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;QACtD,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEvC,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAC3D,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,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AAC,CAAC;gBAC1E,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBACrE,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,kCAAkC,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC1F,CAAC;YACD,IAAI,CAAC;gBACD,MAAM,YAAY,GAAG,CAAA,MAAA,MAAM,CAAC,iBAAiB,0CAAE,YAAY,KAAI,uBAAuB,CAAC;gBACvF,KAAK,CAAC,IAAI,CAAC;oBACP,IAAI,EAAE,OAAO;oBACb,IAAI,EAAE;wBACF,IAAI,EAAE,mBAAmB,CAAC,MAAM,CAAC,aAAa,CAAC;wBAC/C,aAAa,EAAE,MAAM,CAAC,aAAa;wBACnC,WAAW,EAAE,GAAG,MAAM,CAAC,WAAW,kBAAkB,6BAA6B,EAAE;wBACnF,WAAW,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE;wBAC/B,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;wBAC5C,YAAY,EAAE,YAAY,GAAG,uBAAuB,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,YAAY;qBAChG;iBACJ,CAAC,CAAC;YACP,CAAC;YAAC,OAAO,eAAe,EAAE,CAAC;gBACvB,GAAG,CAAC,KAAK,CAAC,2CAA2C,MAAM,CAAC,aAAa,YAAY,eAAe,EAAE,CAAC,CAAC;YAC5G,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
@@ -1,12 +0,0 @@
1
- import type { ActorDefinitionPruned, ToolWrap } from '../types.js';
2
- /**
3
- * Get Actor input schema by Actor name.
4
- * First, fetch the Actor details to get the default build tag and buildId.
5
- * Then, fetch the build details and return actorName, description, and input schema.
6
- * @param {string} actorIdOrName - Actor ID or Actor full name.
7
- * @param {number} limit - Truncate the README to this limit.
8
- * @returns {Promise<ActorDefinitionWithDesc | null>} - The actor definition with description or null if not found.
9
- */
10
- export declare function getActorDefinition(actorIdOrName: string, limit?: number): Promise<ActorDefinitionPruned | null>;
11
- export declare const actorDefinitionTool: ToolWrap;
12
- //# sourceMappingURL=build.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/tools/build.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,qBAAqB,EAA4D,QAAQ,EAAE,MAAM,aAAa,CAAC;AAK7H;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,GAAE,MAAgC,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAsC9I;AA6CD,eAAO,MAAM,mBAAmB,EAAE,QAuBjC,CAAC"}