@apify/actors-mcp-server 0.1.22-beta.9 → 0.1.23

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 (115) 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/{tools/utils.js → actors.js} +241 -112
  5. package/dist/actors.js.map +1 -0
  6. package/dist/const.d.ts +18 -14
  7. package/dist/const.d.ts.map +1 -1
  8. package/dist/const.js +22 -22
  9. package/dist/const.js.map +1 -1
  10. package/dist/examples/clientSse.d.ts +1 -10
  11. package/dist/examples/clientSse.d.ts.map +1 -1
  12. package/dist/examples/clientSse.js +4 -7
  13. package/dist/examples/clientSse.js.map +1 -1
  14. package/dist/examples/clientStdio.js +2 -2
  15. package/dist/examples/clientStdio.js.map +1 -1
  16. package/dist/examples/clientStdioChat.js +1 -1
  17. package/dist/index.d.ts +14 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +51 -6
  20. package/dist/index.js.map +1 -1
  21. package/dist/input.d.ts +1 -1
  22. package/dist/input.d.ts.map +1 -1
  23. package/dist/input.js +8 -6
  24. package/dist/input.js.map +1 -1
  25. package/dist/logger.d.ts +3 -0
  26. package/dist/logger.d.ts.map +1 -0
  27. package/dist/logger.js +4 -0
  28. package/dist/logger.js.map +1 -0
  29. package/dist/main.d.ts +0 -4
  30. package/dist/main.d.ts.map +1 -1
  31. package/dist/main.js +126 -31
  32. package/dist/main.js.map +1 -1
  33. package/dist/server.d.ts +43 -0
  34. package/dist/server.d.ts.map +1 -0
  35. package/dist/server.js +178 -0
  36. package/dist/server.js.map +1 -0
  37. package/dist/tools.d.ts +46 -0
  38. package/dist/tools.d.ts.map +1 -0
  39. package/dist/tools.js +128 -0
  40. package/dist/tools.js.map +1 -0
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/dist/types.d.ts +10 -93
  43. package/dist/types.d.ts.map +1 -1
  44. package/package.json +16 -18
  45. package/dist/actor/const.d.ts +0 -10
  46. package/dist/actor/const.d.ts.map +0 -1
  47. package/dist/actor/const.js +0 -11
  48. package/dist/actor/const.js.map +0 -1
  49. package/dist/actor/server.d.ts +0 -4
  50. package/dist/actor/server.d.ts.map +0 -1
  51. package/dist/actor/server.js +0 -82
  52. package/dist/actor/server.js.map +0 -1
  53. package/dist/actor/types.d.ts +0 -23
  54. package/dist/actor/types.d.ts.map +0 -1
  55. package/dist/actor/types.js +0 -2
  56. package/dist/actor/types.js.map +0 -1
  57. package/dist/actor/utils.d.ts +0 -3
  58. package/dist/actor/utils.d.ts.map +0 -1
  59. package/dist/actor/utils.js +0 -26
  60. package/dist/actor/utils.js.map +0 -1
  61. package/dist/apify-client.d.ts +0 -6
  62. package/dist/apify-client.d.ts.map +0 -1
  63. package/dist/apify-client.js +0 -23
  64. package/dist/apify-client.js.map +0 -1
  65. package/dist/mcp/actors.d.ts +0 -3
  66. package/dist/mcp/actors.d.ts.map +0 -1
  67. package/dist/mcp/actors.js +0 -13
  68. package/dist/mcp/actors.js.map +0 -1
  69. package/dist/mcp/client.d.ts +0 -6
  70. package/dist/mcp/client.d.ts.map +0 -1
  71. package/dist/mcp/client.js +0 -33
  72. package/dist/mcp/client.js.map +0 -1
  73. package/dist/mcp/const.d.ts +0 -3
  74. package/dist/mcp/const.d.ts.map +0 -1
  75. package/dist/mcp/const.js +0 -3
  76. package/dist/mcp/const.js.map +0 -1
  77. package/dist/mcp/proxy.d.ts +0 -4
  78. package/dist/mcp/proxy.d.ts.map +0 -1
  79. package/dist/mcp/proxy.js +0 -29
  80. package/dist/mcp/proxy.js.map +0 -1
  81. package/dist/mcp/server.d.ts +0 -41
  82. package/dist/mcp/server.d.ts.map +0 -1
  83. package/dist/mcp/server.js +0 -177
  84. package/dist/mcp/server.js.map +0 -1
  85. package/dist/mcp/utils.d.ts +0 -34
  86. package/dist/mcp/utils.d.ts.map +0 -1
  87. package/dist/mcp/utils.js +0 -70
  88. package/dist/mcp/utils.js.map +0 -1
  89. package/dist/stdio.d.ts +0 -15
  90. package/dist/stdio.d.ts.map +0 -1
  91. package/dist/stdio.js +0 -46
  92. package/dist/stdio.js.map +0 -1
  93. package/dist/tools/actor.d.ts +0 -40
  94. package/dist/tools/actor.d.ts.map +0 -1
  95. package/dist/tools/actor.js +0 -136
  96. package/dist/tools/actor.js.map +0 -1
  97. package/dist/tools/build.d.ts +0 -12
  98. package/dist/tools/build.d.ts.map +0 -1
  99. package/dist/tools/build.js +0 -120
  100. package/dist/tools/build.js.map +0 -1
  101. package/dist/tools/helpers.d.ts +0 -19
  102. package/dist/tools/helpers.d.ts.map +0 -1
  103. package/dist/tools/helpers.js +0 -62
  104. package/dist/tools/helpers.js.map +0 -1
  105. package/dist/tools/index.d.ts +0 -6
  106. package/dist/tools/index.d.ts.map +0 -1
  107. package/dist/tools/index.js +0 -8
  108. package/dist/tools/index.js.map +0 -1
  109. package/dist/tools/store_collection.d.ts +0 -21
  110. package/dist/tools/store_collection.d.ts.map +0 -1
  111. package/dist/tools/store_collection.js +0 -80
  112. package/dist/tools/store_collection.js.map +0 -1
  113. package/dist/tools/utils.d.ts +0 -77
  114. package/dist/tools/utils.d.ts.map +0 -1
  115. package/dist/tools/utils.js.map +0 -1
@@ -1,41 +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
- server: Server;
12
- tools: Map<string, ToolWrap>;
13
- constructor();
14
- /**
15
- * Loads missing default tools.
16
- */
17
- loadDefaultTools(apifyToken: string): Promise<void>;
18
- /**
19
- * Loads tools from URL params.
20
- *
21
- * This method also handles enabling of Actor auto loading via the processParamsGetTools.
22
- *
23
- * Used primarily for SSE.
24
- */
25
- loadToolsFromUrl(url: string, apifyToken: string): Promise<void>;
26
- /**
27
- * Upsert new tools.
28
- * @param tools - Array of tool wrappers.
29
- * @returns Array of tool wrappers.
30
- */
31
- updateTools(tools: ToolWrap[]): ToolWrap[];
32
- /**
33
- * Returns an array of tool names.
34
- * @returns {string[]} - An array of tool names.
35
- */
36
- getToolNames(): string[];
37
- private setupErrorHandling;
38
- private setupToolHandlers;
39
- connect(transport: Transport): Promise<void>;
40
- }
41
- //# sourceMappingURL=server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AACA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAa/E,OAAO,KAAK,EAAuC,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOjF;;GAEG;AACH,qBAAa,eAAe;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;;IAsBpC;;OAEG;IACU,gBAAgB,CAAC,UAAU,EAAE,MAAM;IAMhD;;;;;;OAMG;IACU,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAK7D;;;;OAIG;IACI,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE;IAQpC;;;OAGG;IACI,YAAY,IAAI,MAAM,EAAE;IAI/B,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;IAsGnB,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAGrD"}
@@ -1,177 +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 { ACTOR_OUTPUT_MAX_CHARS_PER_ITEM, ACTOR_OUTPUT_TRUNCATED_MESSAGE, SERVER_NAME, SERVER_VERSION, } from '../const.js';
8
- import { actorDefinitionTool, callActorGetDataset, getActorsAsTools, searchTool } from '../tools/index.js';
9
- import { defaults } from '../const.js';
10
- import { actorNameToToolName } from '../tools/utils.js';
11
- import { processParamsGetTools } from './utils.js';
12
- import { createMCPClient } from './client.js';
13
- /**
14
- * Create Apify MCP server
15
- */
16
- export class ActorsMcpServer {
17
- server;
18
- tools;
19
- constructor() {
20
- this.server = new Server({
21
- name: SERVER_NAME,
22
- version: SERVER_VERSION,
23
- }, {
24
- capabilities: {
25
- tools: { listChanged: true },
26
- },
27
- });
28
- this.tools = new Map();
29
- this.setupErrorHandling();
30
- this.setupToolHandlers();
31
- // Add default tools
32
- this.updateTools([searchTool, actorDefinitionTool]);
33
- }
34
- /**
35
- * Loads missing default tools.
36
- */
37
- async loadDefaultTools(apifyToken) {
38
- const missingDefaultTools = defaults.actors.filter(name => !this.tools.has(actorNameToToolName(name)));
39
- const tools = await getActorsAsTools(missingDefaultTools, apifyToken);
40
- if (tools.length > 0)
41
- this.updateTools(tools);
42
- }
43
- /**
44
- * Loads tools from URL params.
45
- *
46
- * This method also handles enabling of Actor auto loading via the processParamsGetTools.
47
- *
48
- * Used primarily for SSE.
49
- */
50
- async loadToolsFromUrl(url, apifyToken) {
51
- const tools = await processParamsGetTools(url, apifyToken);
52
- if (tools.length > 0)
53
- this.updateTools(tools);
54
- }
55
- /**
56
- * Upsert new tools.
57
- * @param tools - Array of tool wrappers.
58
- * @returns Array of tool wrappers.
59
- */
60
- updateTools(tools) {
61
- for (const wrap of tools) {
62
- this.tools.set(wrap.tool.name, wrap);
63
- log.info(`Added/updated tool: ${wrap.tool.name}`);
64
- }
65
- return tools;
66
- }
67
- /**
68
- * Returns an array of tool names.
69
- * @returns {string[]} - An array of tool names.
70
- */
71
- getToolNames() {
72
- return Array.from(this.tools.keys());
73
- }
74
- setupErrorHandling() {
75
- this.server.onerror = (error) => {
76
- console.error('[MCP Error]', error); // eslint-disable-line no-console
77
- };
78
- process.on('SIGINT', async () => {
79
- await this.server.close();
80
- process.exit(0);
81
- });
82
- }
83
- setupToolHandlers() {
84
- /**
85
- * Handles the request to list tools.
86
- * @param {object} request - The request object.
87
- * @returns {object} - The response object containing the tools.
88
- */
89
- this.server.setRequestHandler(ListToolsRequestSchema, async () => {
90
- // TODO if there is actor-mcp as a tool, also list the tools from that Actor
91
- const tools = Array.from(this.tools.values()).map((tool) => (tool.tool));
92
- return { tools };
93
- });
94
- /**
95
- * Handles the request to call a tool.
96
- * @param {object} request - The request object containing tool name and arguments.
97
- * @throws {Error} - Throws an error if the tool is unknown or arguments are invalid.
98
- */
99
- this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
100
- const { name, arguments: args } = request.params;
101
- const apifyToken = (request.params.apifyToken || process.env.APIFY_TOKEN);
102
- // Remove apifyToken from request.params just in case
103
- delete request.params.apifyToken;
104
- // Validate token
105
- if (!apifyToken) {
106
- throw new Error('APIFY_TOKEN is required but not set in the environment variables or passed as a parameter.');
107
- }
108
- // Find tool by name or actor full name
109
- const tool = Array.from(this.tools.values())
110
- .find((t) => t.tool.name === name || (t.type === 'actor' && t.tool.actorFullName === name));
111
- if (!tool) {
112
- // TODO: handle errors better, server.sendLoggingMessage ( )
113
- throw new Error(`Unknown tool: ${name}`);
114
- }
115
- if (!args) {
116
- throw new Error(`Missing arguments for tool: ${name}`);
117
- }
118
- log.info(`Validate arguments for tool: ${tool.tool.name} with arguments: ${JSON.stringify(args)}`);
119
- if (!tool.tool.ajvValidate(args)) {
120
- throw new Error(`Invalid arguments for tool ${tool.tool.name}: args: ${JSON.stringify(args)} error: ${JSON.stringify(tool?.tool.ajvValidate.errors)}`);
121
- }
122
- try {
123
- // Handle internal tool
124
- if (tool.type === 'internal') {
125
- const internalTool = tool.tool;
126
- const res = await internalTool.call({
127
- args,
128
- apifyMcpServer: this,
129
- mcpServer: this.server,
130
- apifyToken,
131
- });
132
- return { ...res };
133
- }
134
- if (tool.type === 'actor-mcp') {
135
- const serverTool = tool.tool;
136
- let client;
137
- try {
138
- client = await createMCPClient(serverTool.serverUrl, apifyToken);
139
- const res = await client.callTool({
140
- name: serverTool.originToolName,
141
- arguments: args,
142
- });
143
- return { ...res };
144
- }
145
- finally {
146
- if (client)
147
- await client.close();
148
- }
149
- }
150
- // Handle actor tool
151
- if (tool.type === 'actor') {
152
- const actorTool = tool.tool;
153
- const callOptions = {
154
- memory: actorTool.memoryMbytes,
155
- };
156
- const items = await callActorGetDataset(actorTool.actorFullName, args, apifyToken, callOptions);
157
- const content = items.map((item) => {
158
- const text = JSON.stringify(item).slice(0, ACTOR_OUTPUT_MAX_CHARS_PER_ITEM);
159
- return text.length === ACTOR_OUTPUT_MAX_CHARS_PER_ITEM
160
- ? { type: 'text', text: `${text} ... ${ACTOR_OUTPUT_TRUNCATED_MESSAGE}` }
161
- : { type: 'text', text };
162
- });
163
- return { content };
164
- }
165
- }
166
- catch (error) {
167
- log.error(`Error calling tool: ${error}`);
168
- throw new Error(`Error calling tool: ${error}`);
169
- }
170
- throw new Error(`Tool ${name} is not implemented`);
171
- });
172
- }
173
- async connect(transport) {
174
- await this.server.connect(transport);
175
- }
176
- }
177
- //# sourceMappingURL=server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AACA;;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,EACH,+BAA+B,EAC/B,8BAA8B,EAC9B,WAAW,EACX,cAAc,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,gBAAgB,EAA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types.js";
3
- /**
4
- * Generates a unique server ID based on the provided URL.
5
- *
6
- * URL is used instead of Actor ID becase one Actor may expose multiple servers - legacy SSE / streamable HTTP.
7
- *
8
- * @param url The URL to generate the server ID from.
9
- * @returns A unique server ID.
10
- */
11
- export declare function getMCPServerID(url: string): string;
12
- /**
13
- * Generates a unique tool name based on the provided URL and tool name.
14
- * @param url The URL to generate the tool name from.
15
- * @param toolName The tool name to generate the tool name from.
16
- * @returns A unique tool name.
17
- */
18
- export declare function getProxyMCPServerToolName(url: string, toolName: string): string;
19
- /**
20
- * Process input parameters and get tools
21
- * If URL contains query parameter `actors`, return tools from Actors otherwise return null.
22
- * @param url
23
- */
24
- export declare function processParamsGetTools(url: string, apifyToken: string): Promise<ToolWrap[]>;
25
- export declare function parseInputParamsFromUrl(url: string): Input;
26
- /**
27
- * Returns standby URL for given Actor ID.
28
- *
29
- * @param actorID
30
- * @param standbyBaseUrl
31
- * @returns
32
- */
33
- export declare function getActorStandbyURL(actorID: string, standbyBaseUrl?: string): string;
34
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/mcp/utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIlD;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAK/E;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,uBAY1E;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAI1D;AAED;;;;;;EAME;AACF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,SAAgB,GAAG,MAAM,CAW1F"}
package/dist/mcp/utils.js DELETED
@@ -1,70 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { MAX_TOOL_NAME_LENGTH, SERVER_ID_LENGTH } from "./const.js";
3
- import { parse } from 'node:querystring';
4
- import { processInput } from '../input.js';
5
- import { addTool, getActorsAsTools, removeTool } from '../tools/index.js';
6
- import { APIFY_USERNAME } from "../const.js";
7
- /**
8
- * Generates a unique server ID based on the provided URL.
9
- *
10
- * URL is used instead of Actor ID becase one Actor may expose multiple servers - legacy SSE / streamable HTTP.
11
- *
12
- * @param url The URL to generate the server ID from.
13
- * @returns A unique server ID.
14
- */
15
- export function getMCPServerID(url) {
16
- const serverHashDigest = createHash('sha256').update(url).digest('hex');
17
- return serverHashDigest.slice(0, SERVER_ID_LENGTH);
18
- }
19
- /**
20
- * Generates a unique tool name based on the provided URL and tool name.
21
- * @param url The URL to generate the tool name from.
22
- * @param toolName The tool name to generate the tool name from.
23
- * @returns A unique tool name.
24
- */
25
- export function getProxyMCPServerToolName(url, toolName) {
26
- const prefix = getMCPServerID(url);
27
- const fullName = `${prefix}-${toolName}`;
28
- return fullName.slice(0, MAX_TOOL_NAME_LENGTH);
29
- }
30
- /**
31
- * Process input parameters and get tools
32
- * If URL contains query parameter `actors`, return tools from Actors otherwise return null.
33
- * @param url
34
- */
35
- export async function processParamsGetTools(url, apifyToken) {
36
- const input = parseInputParamsFromUrl(url);
37
- let tools = [];
38
- if (input.actors) {
39
- const actors = input.actors;
40
- // Normal Actors as a tool
41
- tools = await getActorsAsTools(actors, apifyToken);
42
- }
43
- if (input.enableActorAutoLoading) {
44
- tools.push(addTool, removeTool);
45
- }
46
- return tools;
47
- }
48
- export function parseInputParamsFromUrl(url) {
49
- const query = url.split('?')[1] || '';
50
- const params = parse(query);
51
- return processInput(params);
52
- }
53
- /**
54
- * Returns standby URL for given Actor ID.
55
- *
56
- * @param actorID
57
- * @param standbyBaseUrl
58
- * @returns
59
- */
60
- export function getActorStandbyURL(actorID, standbyBaseUrl = 'apify.actor') {
61
- const actorOwner = actorID.split('/')[0];
62
- const actorName = actorID.split('/')[1];
63
- if (!actorOwner || !actorName) {
64
- throw new Error(`Invalid actor ID: ${actorID}`);
65
- }
66
- const actorOwnerDNSFriendly = actorOwner.replace('.', '-');
67
- const prefix = actorOwner === APIFY_USERNAME ? '' : `${actorOwnerDNSFriendly}--`;
68
- return `https://${prefix}${actorName}.${standbyBaseUrl}`;
69
- }
70
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/mcp/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACtC,MAAM,gBAAgB,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAExE,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,GAAW,EAAE,QAAgB;IACnE,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;IAEnC,MAAM,QAAQ,GAAG,GAAG,MAAM,IAAI,QAAQ,EAAE,CAAC;IACz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G,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,UAAU,KAAK,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,qBAAqB,IAAI,CAAC;IAEjF,OAAO,WAAW,MAAM,GAAG,SAAS,IAAI,cAAc,EAAE,CAAC;AAC7D,CAAC"}
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, removeTool, getActorsAsTools } 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, process.env.APIFY_TOKEN);
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,UAAU,EAAE,gBAAgB,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,EAAE,OAAO,CAAC,GAAG,CAAC,WAAqB,CAAC,CAAC;IACxH,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,40 +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
- * This function is used to fetch normal non-MCP server Actors as a tool.
20
- *
21
- * Fetches actor input schemas by Actor IDs or Actor full names and creates MCP tools.
22
- *
23
- * This function retrieves the input schemas for the specified actors and compiles them into MCP tools.
24
- * It uses the AJV library to validate the input schemas.
25
- *
26
- * Tool name can't contain /, so it is replaced with _
27
- *
28
- * The input schema processing workflow:
29
- * 1. Properties are marked as required using markInputPropertiesAsRequired() to add "REQUIRED" prefix to descriptions
30
- * 2. Nested properties are built by analyzing editor type (proxy, requestListSources) using buildNestedProperties()
31
- * 3. Properties are filtered using filterSchemaProperties()
32
- * 4. Properties are shortened using shortenProperties()
33
- * 5. Enums are added to descriptions with examples using addEnumsToDescriptionsWithExamples()
34
- *
35
- * @param {string[]} actors - An array of actor IDs or Actor full names.
36
- * @returns {Promise<Tool[]>} - A promise that resolves to an array of MCP tools.
37
- */
38
- export declare function getNormalActorsAsTools(actors: string[], apifyToken: string): Promise<ToolWrap[]>;
39
- export declare function getActorsAsTools(actors: string[], apifyToken: string): Promise<ToolWrap[]>;
40
- //# 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;AAIrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAkB5C;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,sBAAsB,CACxC,MAAM,EAAE,MAAM,EAAE,EAChB,UAAU,EAAE,MAAM,GACnB,OAAO,CAAC,QAAQ,EAAE,CAAC,CAoCrB;AAwBD,wBAAsB,gBAAgB,CAClC,MAAM,EAAE,MAAM,EAAE,EAChB,UAAU,EAAE,MAAM,GACnB,OAAO,CAAC,QAAQ,EAAE,CAAC,CAsBrB"}
@@ -1,136 +0,0 @@
1
- import { Ajv } from 'ajv';
2
- import log from '@apify/log';
3
- import { getActorDefinition } from './build.js';
4
- import { ACTOR_ADDITIONAL_INSTRUCTIONS, ACTOR_MAX_MEMORY_MBYTES } from '../const.js';
5
- import { ApifyClient } from '../apify-client.js';
6
- import { actorNameToToolName, addEnumsToDescriptionsWithExamples, buildNestedProperties, filterSchemaProperties, markInputPropertiesAsRequired, shortenProperties, } from './utils.js';
7
- import { getActorsMCPServerURL, isActorMCPServer } from '../mcp/actors.js';
8
- import { createMCPClient } from '../mcp/client.js';
9
- import { getMCPServerTools } from '../mcp/proxy.js';
10
- /**
11
- * Calls an Apify actor and retrieves the dataset items.
12
- *
13
- *
14
- * It requires the `APIFY_TOKEN` environment variable to be set.
15
- * If the `APIFY_IS_AT_HOME` the dataset items are pushed to the Apify dataset.
16
- *
17
- * @param {string} actorName - The name of the actor to call.
18
- * @param {ActorCallOptions} callOptions - The options to pass to the actor.
19
- * @param {unknown} input - The input to pass to the actor.
20
- * @param {string} apifyToken - The Apify token to use for authentication.
21
- * @returns {Promise<object[]>} - A promise that resolves to an array of dataset items.
22
- * @throws {Error} - Throws an error if the `APIFY_TOKEN` is not set
23
- */
24
- export async function callActorGetDataset(actorName, input, apifyToken, callOptions = undefined) {
25
- const name = actorName;
26
- try {
27
- log.info(`Calling Actor ${name} with input: ${JSON.stringify(input)}`);
28
- const client = new ApifyClient({ token: apifyToken });
29
- const actorClient = client.actor(name);
30
- const results = await actorClient.call(input, callOptions);
31
- const dataset = await client.dataset(results.defaultDatasetId).listItems();
32
- log.info(`Actor ${name} finished with ${dataset.items.length} items`);
33
- return dataset.items;
34
- }
35
- catch (error) {
36
- log.error(`Error calling actor: ${error}. Actor: ${name}, input: ${JSON.stringify(input)}`);
37
- throw new Error(`Error calling Actor: ${error}`);
38
- }
39
- }
40
- /**
41
- * This function is used to fetch normal non-MCP server Actors as a tool.
42
- *
43
- * Fetches actor input schemas by Actor IDs or Actor full names and creates MCP tools.
44
- *
45
- * This function retrieves the input schemas for the specified actors and compiles them into MCP tools.
46
- * It uses the AJV library to validate the input schemas.
47
- *
48
- * Tool name can't contain /, so it is replaced with _
49
- *
50
- * The input schema processing workflow:
51
- * 1. Properties are marked as required using markInputPropertiesAsRequired() to add "REQUIRED" prefix to descriptions
52
- * 2. Nested properties are built by analyzing editor type (proxy, requestListSources) using buildNestedProperties()
53
- * 3. Properties are filtered using filterSchemaProperties()
54
- * 4. Properties are shortened using shortenProperties()
55
- * 5. Enums are added to descriptions with examples using addEnumsToDescriptionsWithExamples()
56
- *
57
- * @param {string[]} actors - An array of actor IDs or Actor full names.
58
- * @returns {Promise<Tool[]>} - A promise that resolves to an array of MCP tools.
59
- */
60
- export async function getNormalActorsAsTools(actors, apifyToken) {
61
- const ajv = new Ajv({ coerceTypes: 'array', strict: false });
62
- const getActorDefinitionWithToken = async (actorId) => {
63
- const actor = await getActorDefinition(actorId, apifyToken);
64
- return actor;
65
- };
66
- const results = await Promise.all(actors.map(getActorDefinitionWithToken));
67
- const tools = [];
68
- for (const result of results) {
69
- if (result) {
70
- if (result.input && 'properties' in result.input && result.input) {
71
- result.input.properties = markInputPropertiesAsRequired(result.input);
72
- result.input.properties = buildNestedProperties(result.input.properties);
73
- result.input.properties = filterSchemaProperties(result.input.properties);
74
- result.input.properties = shortenProperties(result.input.properties);
75
- result.input.properties = addEnumsToDescriptionsWithExamples(result.input.properties);
76
- }
77
- try {
78
- const memoryMbytes = result.defaultRunOptions?.memoryMbytes || ACTOR_MAX_MEMORY_MBYTES;
79
- tools.push({
80
- type: 'actor',
81
- tool: {
82
- name: actorNameToToolName(result.actorFullName),
83
- actorFullName: result.actorFullName,
84
- description: `${result.description} Instructions: ${ACTOR_ADDITIONAL_INSTRUCTIONS}`,
85
- inputSchema: result.input || {},
86
- ajvValidate: ajv.compile(result.input || {}),
87
- memoryMbytes: memoryMbytes > ACTOR_MAX_MEMORY_MBYTES ? ACTOR_MAX_MEMORY_MBYTES : memoryMbytes,
88
- },
89
- });
90
- }
91
- catch (validationError) {
92
- log.error(`Failed to compile AJV schema for Actor: ${result.actorFullName}. Error: ${validationError}`);
93
- }
94
- }
95
- }
96
- return tools;
97
- }
98
- async function getMCPServersAsTools(actors, apifyToken) {
99
- const actorsMCPServerTools = [];
100
- for (const actorID of actors) {
101
- const serverUrl = await getActorsMCPServerURL(actorID, apifyToken);
102
- log.info(`ActorID: ${actorID} MCP server URL: ${serverUrl}`);
103
- let client;
104
- try {
105
- client = await createMCPClient(serverUrl, apifyToken);
106
- const serverTools = await getMCPServerTools(actorID, client, serverUrl);
107
- actorsMCPServerTools.push(...serverTools);
108
- }
109
- finally {
110
- if (client)
111
- await client.close();
112
- }
113
- }
114
- return actorsMCPServerTools;
115
- }
116
- export async function getActorsAsTools(actors, apifyToken) {
117
- console.log('Fetching actors as tools...');
118
- console.log(actors);
119
- // Actorized MCP servers
120
- const actorsMCPServers = [];
121
- for (const actorID of actors) {
122
- if (await isActorMCPServer(actorID, apifyToken)) {
123
- actorsMCPServers.push(actorID);
124
- }
125
- }
126
- // Normal Actors as a tool
127
- const toolActors = actors.filter((actorID) => !actorsMCPServers.includes(actorID));
128
- console.log('actorsMCPserver', actorsMCPServers);
129
- console.log('toolActors', toolActors);
130
- // Normal Actors as a tool
131
- const normalTools = await getNormalActorsAsTools(toolActors, apifyToken);
132
- // Tools from Actorized MCP servers
133
- const mcpServerTools = await getMCPServersAsTools(actorsMCPServers, apifyToken);
134
- return [...normalTools, ...mcpServerTools];
135
- }
136
- //# 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;AAG7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EACH,mBAAmB,EACnB,kCAAkC,EAClC,qBAAqB,EACrB,sBAAsB,EACtB,6BAA6B,EAC7B,iBAAiB,GACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAIpD;;;;;;;;;;;;;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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CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACnF,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IAEtC,0BAA0B;IAC1B,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEzE,mCAAmC;IACnC,MAAM,cAAc,GAAG,MAAM,oBAAoB,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;IAEhF,OAAO,CAAC,GAAG,WAAW,EAAE,GAAG,cAAc,CAAC,CAAC;AAC/C,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, apifyToken: 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,CACpC,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAClB,KAAK,GAAE,MAAgC,GACxC,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAsCvC;AA6CD,eAAO,MAAM,mBAAmB,EAAE,QAuBjC,CAAC"}