@apify/actors-mcp-server 0.1.23 → 0.1.24-beta.0
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.
- package/README.md +58 -2
- package/dist/actor/const.d.ts +12 -0
- package/dist/actor/const.d.ts.map +1 -0
- package/dist/actor/const.js +18 -0
- package/dist/actor/const.js.map +1 -0
- package/dist/actor/server.d.ts +4 -0
- package/dist/actor/server.d.ts.map +1 -0
- package/dist/actor/server.js +158 -0
- package/dist/actor/server.js.map +1 -0
- package/dist/actor/types.d.ts +23 -0
- package/dist/actor/types.d.ts.map +1 -0
- package/dist/actor/types.js +2 -0
- package/dist/actor/types.js.map +1 -0
- package/dist/actor/utils.d.ts +3 -0
- package/dist/actor/utils.d.ts.map +1 -0
- package/dist/actor/utils.js +26 -0
- package/dist/actor/utils.js.map +1 -0
- package/dist/apify-client.d.ts +7 -0
- package/dist/apify-client.d.ts.map +1 -0
- package/dist/apify-client.js +30 -0
- package/dist/apify-client.js.map +1 -0
- package/dist/const.d.ts +15 -19
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +23 -23
- package/dist/const.js.map +1 -1
- package/dist/examples/clientSse.d.ts +11 -1
- package/dist/examples/clientSse.d.ts.map +1 -1
- package/dist/examples/clientSse.js +13 -10
- package/dist/examples/clientSse.js.map +1 -1
- package/dist/examples/clientStdio.js +6 -6
- package/dist/examples/clientStdio.js.map +1 -1
- package/dist/examples/clientStdioChat.js +31 -16
- package/dist/examples/clientStdioChat.js.map +1 -1
- package/dist/examples/clientStreamableHttp.d.ts +2 -0
- package/dist/examples/clientStreamableHttp.d.ts.map +1 -0
- package/dist/examples/clientStreamableHttp.js +93 -0
- package/dist/examples/clientStreamableHttp.js.map +1 -0
- package/dist/index.d.ts +2 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -51
- package/dist/index.js.map +1 -1
- package/dist/input.d.ts +1 -1
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +15 -7
- package/dist/input.js.map +1 -1
- package/dist/main.d.ts +4 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +22 -125
- package/dist/main.js.map +1 -1
- package/dist/mcp/actors.d.ts +22 -0
- package/dist/mcp/actors.d.ts.map +1 -0
- package/dist/mcp/actors.js +76 -0
- package/dist/mcp/actors.js.map +1 -0
- package/dist/mcp/client.d.ts +6 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +33 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/const.d.ts +3 -0
- package/dist/mcp/const.d.ts.map +1 -0
- package/dist/mcp/const.js +3 -0
- package/dist/mcp/const.js.map +1 -0
- package/dist/mcp/proxy.d.ts +4 -0
- package/dist/mcp/proxy.d.ts.map +1 -0
- package/dist/mcp/proxy.js +29 -0
- package/dist/mcp/proxy.js.map +1 -0
- package/dist/mcp/server.d.ts +41 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +187 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/utils.d.ts +26 -0
- package/dist/mcp/utils.d.ts.map +1 -0
- package/dist/mcp/utils.js +53 -0
- package/dist/mcp/utils.js.map +1 -0
- package/dist/stdio.d.ts +15 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +57 -0
- package/dist/stdio.js.map +1 -0
- package/dist/tools/actor.d.ts +40 -0
- package/dist/tools/actor.d.ts.map +1 -0
- package/dist/tools/actor.js +138 -0
- package/dist/tools/actor.js.map +1 -0
- package/dist/tools/build.d.ts +13 -0
- package/dist/tools/build.d.ts.map +1 -0
- package/dist/tools/build.js +122 -0
- package/dist/tools/build.js.map +1 -0
- package/dist/tools/helpers.d.ts +19 -0
- package/dist/tools/helpers.d.ts.map +1 -0
- package/dist/tools/helpers.js +62 -0
- package/dist/tools/helpers.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +8 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/store_collection.d.ts +21 -0
- package/dist/tools/store_collection.d.ts.map +1 -0
- package/dist/tools/store_collection.js +82 -0
- package/dist/tools/store_collection.js.map +1 -0
- package/dist/tools/utils.d.ts +77 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +202 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +97 -10
- package/dist/types.d.ts.map +1 -1
- package/package.json +17 -14
- package/dist/actors.d.ts +0 -74
- package/dist/actors.d.ts.map +0 -1
- package/dist/actors.js +0 -327
- package/dist/actors.js.map +0 -1
- package/dist/logger.d.ts +0 -3
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -4
- package/dist/logger.js.map +0 -1
- package/dist/server.d.ts +0 -43
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -178
- package/dist/server.js.map +0 -1
- package/dist/tools.d.ts +0 -46
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -128
- package/dist/tools.js.map +0 -1
package/dist/stdio.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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 parser = minimist;
|
|
24
|
+
const argv = parser(process.argv.slice(2), {
|
|
25
|
+
boolean: [
|
|
26
|
+
'enable-adding-actors',
|
|
27
|
+
'enableActorAutoLoading', // deprecated
|
|
28
|
+
],
|
|
29
|
+
string: ['actors'],
|
|
30
|
+
default: {
|
|
31
|
+
'enable-adding-actors': false,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
const { actors = '', enableActorAutoLoading = false } = argv;
|
|
35
|
+
const actorList = actors ? actors.split(',').map((a) => a.trim()) : [];
|
|
36
|
+
// Validate environment
|
|
37
|
+
if (!process.env.APIFY_TOKEN) {
|
|
38
|
+
log.error('APIFY_TOKEN is required but not set in the environment variables.');
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
async function main() {
|
|
42
|
+
const mcpServer = new ActorsMcpServer();
|
|
43
|
+
// Initialize tools
|
|
44
|
+
const tools = await getActorsAsTools(actorList.length ? actorList : defaults.actors, process.env.APIFY_TOKEN);
|
|
45
|
+
if (enableActorAutoLoading) {
|
|
46
|
+
tools.push(addTool, removeTool);
|
|
47
|
+
}
|
|
48
|
+
mcpServer.updateTools(tools);
|
|
49
|
+
// Start server
|
|
50
|
+
const transport = new StdioServerTransport();
|
|
51
|
+
await mcpServer.connect(transport);
|
|
52
|
+
}
|
|
53
|
+
main().catch((error) => {
|
|
54
|
+
log.error('Server error:', error);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=stdio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,oBAAoB,EAAE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B,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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../../src/tools/actor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AASrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAW5C;;;;;;;;;;;;;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,CAuBrB"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Ajv } from 'ajv';
|
|
2
|
+
import log from '@apify/log';
|
|
3
|
+
import { ApifyClient } from '../apify-client.js';
|
|
4
|
+
import { ACTOR_ADDITIONAL_INSTRUCTIONS, ACTOR_MAX_MEMORY_MBYTES } from '../const.js';
|
|
5
|
+
import { getActorsMCPServerURL, isActorMCPServer } from '../mcp/actors.js';
|
|
6
|
+
import { createMCPClient } from '../mcp/client.js';
|
|
7
|
+
import { getMCPServerTools } from '../mcp/proxy.js';
|
|
8
|
+
import { getActorDefinition } from './build.js';
|
|
9
|
+
import { actorNameToToolName, addEnumsToDescriptionsWithExamples, buildNestedProperties, filterSchemaProperties, markInputPropertiesAsRequired, shortenProperties, } from './utils.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
|
+
var _a;
|
|
62
|
+
const ajv = new Ajv({ coerceTypes: 'array', strict: false });
|
|
63
|
+
const getActorDefinitionWithToken = async (actorId) => {
|
|
64
|
+
const actor = await getActorDefinition(actorId, apifyToken);
|
|
65
|
+
return actor;
|
|
66
|
+
};
|
|
67
|
+
const results = await Promise.all(actors.map(getActorDefinitionWithToken));
|
|
68
|
+
const tools = [];
|
|
69
|
+
for (const result of results) {
|
|
70
|
+
if (result) {
|
|
71
|
+
if (result.input && 'properties' in result.input && result.input) {
|
|
72
|
+
result.input.properties = markInputPropertiesAsRequired(result.input);
|
|
73
|
+
result.input.properties = buildNestedProperties(result.input.properties);
|
|
74
|
+
result.input.properties = filterSchemaProperties(result.input.properties);
|
|
75
|
+
result.input.properties = shortenProperties(result.input.properties);
|
|
76
|
+
result.input.properties = addEnumsToDescriptionsWithExamples(result.input.properties);
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const memoryMbytes = ((_a = result.defaultRunOptions) === null || _a === void 0 ? void 0 : _a.memoryMbytes) || ACTOR_MAX_MEMORY_MBYTES;
|
|
80
|
+
tools.push({
|
|
81
|
+
type: 'actor',
|
|
82
|
+
tool: {
|
|
83
|
+
name: actorNameToToolName(result.actorFullName),
|
|
84
|
+
actorFullName: result.actorFullName,
|
|
85
|
+
description: `${result.description} Instructions: ${ACTOR_ADDITIONAL_INSTRUCTIONS}`,
|
|
86
|
+
inputSchema: result.input || {},
|
|
87
|
+
ajvValidate: ajv.compile(result.input || {}),
|
|
88
|
+
memoryMbytes: memoryMbytes > ACTOR_MAX_MEMORY_MBYTES ? ACTOR_MAX_MEMORY_MBYTES : memoryMbytes,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch (validationError) {
|
|
93
|
+
log.error(`Failed to compile AJV schema for Actor: ${result.actorFullName}. Error: ${validationError}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return tools;
|
|
98
|
+
}
|
|
99
|
+
async function getMCPServersAsTools(actors, apifyToken) {
|
|
100
|
+
const actorsMCPServerTools = [];
|
|
101
|
+
for (const actorID of actors) {
|
|
102
|
+
const serverUrl = await getActorsMCPServerURL(actorID, apifyToken);
|
|
103
|
+
log.info(`ActorID: ${actorID} MCP server URL: ${serverUrl}`);
|
|
104
|
+
let client;
|
|
105
|
+
try {
|
|
106
|
+
client = await createMCPClient(serverUrl, apifyToken);
|
|
107
|
+
const serverTools = await getMCPServerTools(actorID, client, serverUrl);
|
|
108
|
+
actorsMCPServerTools.push(...serverTools);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
if (client)
|
|
112
|
+
await client.close();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return actorsMCPServerTools;
|
|
116
|
+
}
|
|
117
|
+
export async function getActorsAsTools(actors, apifyToken) {
|
|
118
|
+
log.debug(`Fetching actors as tools...`);
|
|
119
|
+
log.debug(`Actors: ${actors}`);
|
|
120
|
+
// Actorized MCP servers
|
|
121
|
+
const actorsMCPServers = [];
|
|
122
|
+
for (const actorID of actors) {
|
|
123
|
+
// TODO: rework, we are fetching actor definition from API twice - in the getMCPServerTools
|
|
124
|
+
if (await isActorMCPServer(actorID, apifyToken)) {
|
|
125
|
+
actorsMCPServers.push(actorID);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Normal Actors as a tool
|
|
129
|
+
const toolActors = actors.filter((actorID) => !actorsMCPServers.includes(actorID));
|
|
130
|
+
log.debug(`actorsMCPserver: ${actorsMCPServers}`);
|
|
131
|
+
log.debug(`toolActors: ${toolActors}`);
|
|
132
|
+
// Normal Actors as a tool
|
|
133
|
+
const normalTools = await getNormalActorsAsTools(toolActors, apifyToken);
|
|
134
|
+
// Tools from Actorized MCP servers
|
|
135
|
+
const mcpServerTools = await getMCPServersAsTools(actorsMCPServers, apifyToken);
|
|
136
|
+
return [...normalTools, ...mcpServerTools];
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=actor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor.js","sourceRoot":"","sources":["../../src/tools/actor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG1B,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACrF,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;AAEpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,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,G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AI,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;IACL,CAAC;IACD,0BAA0B;IAC1B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACnF,GAAG,CAAC,KAAK,CAAC,oBAAoB,gBAAgB,EAAE,CAAC,CAAC;IAClD,GAAG,CAAC,KAAK,CAAC,eAAe,UAAU,EAAE,CAAC,CAAC;IAEvC,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
* @param {string} apifyToken
|
|
9
|
+
* @returns {Promise<ActorDefinitionWithDesc | null>} - The actor definition with description or null if not found.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getActorDefinition(actorIdOrName: string, apifyToken: string, limit?: number): Promise<ActorDefinitionPruned | null>;
|
|
12
|
+
export declare const actorDefinitionTool: ToolWrap;
|
|
13
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/tools/build.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACR,qBAAqB,EAIrB,QAAQ,EACX,MAAM,aAAa,CAAC;AAKrB;;;;;;;;GAQG;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"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Ajv } from 'ajv';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import zodToJsonSchema from 'zod-to-json-schema';
|
|
4
|
+
import log from '@apify/log';
|
|
5
|
+
import { ApifyClient } from '../apify-client.js';
|
|
6
|
+
import { ACTOR_README_MAX_LENGTH, HelperTools } from '../const.js';
|
|
7
|
+
import { filterSchemaProperties, shortenProperties } from './utils.js';
|
|
8
|
+
const ajv = new Ajv({ coerceTypes: 'array', strict: false });
|
|
9
|
+
/**
|
|
10
|
+
* Get Actor input schema by Actor name.
|
|
11
|
+
* First, fetch the Actor details to get the default build tag and buildId.
|
|
12
|
+
* Then, fetch the build details and return actorName, description, and input schema.
|
|
13
|
+
* @param {string} actorIdOrName - Actor ID or Actor full name.
|
|
14
|
+
* @param {number} limit - Truncate the README to this limit.
|
|
15
|
+
* @param {string} apifyToken
|
|
16
|
+
* @returns {Promise<ActorDefinitionWithDesc | null>} - The actor definition with description or null if not found.
|
|
17
|
+
*/
|
|
18
|
+
export async function getActorDefinition(actorIdOrName, apifyToken, limit = ACTOR_README_MAX_LENGTH) {
|
|
19
|
+
var _a, _b, _c;
|
|
20
|
+
const client = new ApifyClient({ token: apifyToken });
|
|
21
|
+
const actorClient = client.actor(actorIdOrName);
|
|
22
|
+
try {
|
|
23
|
+
// Fetch actor details
|
|
24
|
+
const actor = await actorClient.get();
|
|
25
|
+
if (!actor) {
|
|
26
|
+
log.error(`Failed to fetch input schema for Actor: ${actorIdOrName}. Actor not found.`);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
// fnesveda: The default build is not necessarily tagged, you can specify any build number as default build.
|
|
30
|
+
// There will be a new API endpoint to fetch a default build.
|
|
31
|
+
// For now, we'll use the tagged build, it will work for 90% of Actors. Later, we can update this.
|
|
32
|
+
const tag = ((_a = actor.defaultRunOptions) === null || _a === void 0 ? void 0 : _a.build) || '';
|
|
33
|
+
const buildId = ((_c = (_b = actor.taggedBuilds) === null || _b === void 0 ? void 0 : _b[tag]) === null || _c === void 0 ? void 0 : _c.buildId) || '';
|
|
34
|
+
if (!buildId) {
|
|
35
|
+
log.error(`Failed to fetch input schema for Actor: ${actorIdOrName}. Build ID not found.`);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
// Fetch build details and return the input schema
|
|
39
|
+
const buildDetails = await client.build(buildId).get();
|
|
40
|
+
if (buildDetails === null || buildDetails === void 0 ? void 0 : buildDetails.actorDefinition) {
|
|
41
|
+
const actorDefinitions = buildDetails === null || buildDetails === void 0 ? void 0 : buildDetails.actorDefinition;
|
|
42
|
+
actorDefinitions.id = actor.id;
|
|
43
|
+
actorDefinitions.readme = truncateActorReadme(actorDefinitions.readme || '', limit);
|
|
44
|
+
actorDefinitions.description = actor.description || '';
|
|
45
|
+
actorDefinitions.actorFullName = `${actor.username}/${actor.name}`;
|
|
46
|
+
actorDefinitions.defaultRunOptions = actor.defaultRunOptions;
|
|
47
|
+
return pruneActorDefinition(actorDefinitions);
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const errorMessage = `Failed to fetch input schema for Actor: ${actorIdOrName} with error ${error}.`;
|
|
53
|
+
log.error(errorMessage);
|
|
54
|
+
throw new Error(errorMessage);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function pruneActorDefinition(response) {
|
|
58
|
+
return {
|
|
59
|
+
id: response.id,
|
|
60
|
+
actorFullName: response.actorFullName || '',
|
|
61
|
+
buildTag: (response === null || response === void 0 ? void 0 : response.buildTag) || '',
|
|
62
|
+
readme: (response === null || response === void 0 ? void 0 : response.readme) || '',
|
|
63
|
+
input: (response === null || response === void 0 ? void 0 : response.input) && 'type' in response.input && 'properties' in response.input
|
|
64
|
+
? {
|
|
65
|
+
...response.input,
|
|
66
|
+
type: response.input.type,
|
|
67
|
+
properties: response.input.properties,
|
|
68
|
+
}
|
|
69
|
+
: undefined,
|
|
70
|
+
description: response.description,
|
|
71
|
+
defaultRunOptions: response.defaultRunOptions,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Prune Actor README if it is too long
|
|
75
|
+
* If the README is too long
|
|
76
|
+
* - We keep the README as it is up to the limit.
|
|
77
|
+
* - After the limit, we keep heading only
|
|
78
|
+
* - We add a note that the README was truncated because it was too long.
|
|
79
|
+
*/
|
|
80
|
+
function truncateActorReadme(readme, limit = ACTOR_README_MAX_LENGTH) {
|
|
81
|
+
if (readme.length <= limit) {
|
|
82
|
+
return readme;
|
|
83
|
+
}
|
|
84
|
+
const readmeFirst = readme.slice(0, limit);
|
|
85
|
+
const readmeRest = readme.slice(limit);
|
|
86
|
+
const lines = readmeRest.split('\n');
|
|
87
|
+
const prunedReadme = lines.filter((line) => line.startsWith('#'));
|
|
88
|
+
return `${readmeFirst}\n\nREADME was truncated because it was too long. Remaining headers:\n${prunedReadme.join(', ')}`;
|
|
89
|
+
}
|
|
90
|
+
const GetActorDefinitionArgsSchema = z.object({
|
|
91
|
+
actorName: z.string()
|
|
92
|
+
.describe('Retrieve input, readme, and other details for Actor ID or Actor full name. '
|
|
93
|
+
+ 'Actor name is always composed from `username/name`'),
|
|
94
|
+
limit: z.number()
|
|
95
|
+
.int()
|
|
96
|
+
.default(ACTOR_README_MAX_LENGTH)
|
|
97
|
+
.describe(`Truncate the README to this limit. Default value is ${ACTOR_README_MAX_LENGTH}.`),
|
|
98
|
+
});
|
|
99
|
+
export const actorDefinitionTool = {
|
|
100
|
+
type: 'internal',
|
|
101
|
+
tool: {
|
|
102
|
+
name: HelperTools.GET_TOOL_DETAILS,
|
|
103
|
+
actorFullName: HelperTools.GET_TOOL_DETAILS,
|
|
104
|
+
description: 'Get documentation, readme, input schema and other details about an Actor. '
|
|
105
|
+
+ 'For example, when user says, I need to know more about web crawler Actor.'
|
|
106
|
+
+ 'Get details for an Actor with with Actor ID or Actor full name, i.e. username/name.'
|
|
107
|
+
+ `Limit the length of the README if needed.`,
|
|
108
|
+
inputSchema: zodToJsonSchema(GetActorDefinitionArgsSchema),
|
|
109
|
+
ajvValidate: ajv.compile(zodToJsonSchema(GetActorDefinitionArgsSchema)),
|
|
110
|
+
call: async (toolArgs) => {
|
|
111
|
+
const { args, apifyToken } = toolArgs;
|
|
112
|
+
const parsed = GetActorDefinitionArgsSchema.parse(args);
|
|
113
|
+
const v = await getActorDefinition(parsed.actorName, apifyToken, parsed.limit);
|
|
114
|
+
if (v && v.input && 'properties' in v.input && v.input) {
|
|
115
|
+
const properties = filterSchemaProperties(v.input.properties);
|
|
116
|
+
v.input.properties = shortenProperties(properties);
|
|
117
|
+
}
|
|
118
|
+
return { content: [{ type: 'text', text: JSON.stringify(v) }] };
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/tools/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,eAAe,MAAM,oBAAoB,CAAC;AAEjD,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAQnE,OAAO,EAAE,sBAAsB,E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gB;QAClC,aAAa,EAAE,WAAW,CAAC,gBAAgB;QAC3C,WAAW,EAAE,4EAA4E;cACnF,2EAA2E;cAC3E,qFAAqF;cACrF,2CAA2C;QACjD,WAAW,EAAE,eAAe,CAAC,4BAA4B,CAAC;QAC1D,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,4BAA4B,CAAC,CAAC;QACvE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;YACrB,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC;YAEtC,MAAM,MAAM,GAAG,4BAA4B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACxD,MAAM,CAAC,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/E,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,YAAY,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;gBACrD,MAAM,UAAU,GAAG,sBAAsB,CAAC,CAAC,CAAC,KAAK,CAAC,UAAkD,CAAC,CAAC;gBACtG,CAAC,CAAC,KAAK,CAAC,UAAU,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;YACvD,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;QACpE,CAAC;KACY;CACpB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ToolWrap } from '../types';
|
|
3
|
+
export declare const AddToolArgsSchema: z.ZodObject<{
|
|
4
|
+
actorName: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
actorName: string;
|
|
7
|
+
}, {
|
|
8
|
+
actorName: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const addTool: ToolWrap;
|
|
11
|
+
export declare const RemoveToolArgsSchema: z.ZodObject<{
|
|
12
|
+
toolName: z.ZodEffects<z.ZodString, string, string>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
toolName: string;
|
|
15
|
+
}, {
|
|
16
|
+
toolName: string;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const removeTool: ToolWrap;
|
|
19
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/tools/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,KAAK,EAA2B,QAAQ,EAAE,MAAM,UAAU,CAAC;AAKlE,eAAO,MAAM,iBAAiB;;;;;;EAI5B,CAAC;AACH,eAAO,MAAM,OAAO,EAAE,QA0BrB,CAAC;AACF,eAAO,MAAM,oBAAoB;;;;;;EAI/B,CAAC;AACH,eAAO,MAAM,UAAU,EAAE,QAkBxB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Ajv } from 'ajv';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import zodToJsonSchema from 'zod-to-json-schema';
|
|
4
|
+
import { HelperTools } from '../const.js';
|
|
5
|
+
import { getActorsAsTools } from './actor.js';
|
|
6
|
+
import { actorNameToToolName } from './utils.js';
|
|
7
|
+
const ajv = new Ajv({ coerceTypes: 'array', strict: false });
|
|
8
|
+
export const AddToolArgsSchema = z.object({
|
|
9
|
+
actorName: z.string()
|
|
10
|
+
.describe('Add a tool, Actor or MCP-Server to available tools by Actor ID or tool full name.'
|
|
11
|
+
+ 'Tool name is always composed from `username/name`'),
|
|
12
|
+
});
|
|
13
|
+
export const addTool = {
|
|
14
|
+
type: 'internal',
|
|
15
|
+
tool: {
|
|
16
|
+
name: HelperTools.ADD_TOOL,
|
|
17
|
+
description: 'Add a tool, Actor or MCP-Server to available tools by Actor ID or Actor name. '
|
|
18
|
+
+ 'A tool is an Actor or MCP-Server that can be called by the user'
|
|
19
|
+
+ 'Do not execute the tool, only add it and list it in available tools. '
|
|
20
|
+
+ 'For example, add a tool with username/name when user wants to scrape data from a website.',
|
|
21
|
+
inputSchema: zodToJsonSchema(AddToolArgsSchema),
|
|
22
|
+
ajvValidate: ajv.compile(zodToJsonSchema(AddToolArgsSchema)),
|
|
23
|
+
// TODO: I don't like that we are passing apifyMcpServer and mcpServer to the tool
|
|
24
|
+
call: async (toolArgs) => {
|
|
25
|
+
const { apifyMcpServer, mcpServer, apifyToken, args } = toolArgs;
|
|
26
|
+
const parsed = AddToolArgsSchema.parse(args);
|
|
27
|
+
const tools = await getActorsAsTools([parsed.actorName], apifyToken);
|
|
28
|
+
const toolsAdded = apifyMcpServer.updateTools(tools);
|
|
29
|
+
await mcpServer.notification({ method: 'notifications/tools/list_changed' });
|
|
30
|
+
return {
|
|
31
|
+
content: [{
|
|
32
|
+
type: 'text',
|
|
33
|
+
text: `Actor added: ${toolsAdded.map((t) => `${t.tool.actorFullName} (tool name: ${t.tool.name})`).join(', ')}`,
|
|
34
|
+
}],
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export const RemoveToolArgsSchema = z.object({
|
|
40
|
+
toolName: z.string()
|
|
41
|
+
.describe('Tool name to remove from available tools.')
|
|
42
|
+
.transform((val) => actorNameToToolName(val)),
|
|
43
|
+
});
|
|
44
|
+
export const removeTool = {
|
|
45
|
+
type: 'internal',
|
|
46
|
+
tool: {
|
|
47
|
+
name: HelperTools.REMOVE_TOOL,
|
|
48
|
+
description: 'Remove a tool, an Actor or MCP-Server by name from available tools. '
|
|
49
|
+
+ 'For example, when user says, I do not need a tool username/name anymore',
|
|
50
|
+
inputSchema: zodToJsonSchema(RemoveToolArgsSchema),
|
|
51
|
+
ajvValidate: ajv.compile(zodToJsonSchema(RemoveToolArgsSchema)),
|
|
52
|
+
// TODO: I don't like that we are passing apifyMcpServer and mcpServer to the tool
|
|
53
|
+
call: async (toolArgs) => {
|
|
54
|
+
const { apifyMcpServer, mcpServer, args } = toolArgs;
|
|
55
|
+
const parsed = RemoveToolArgsSchema.parse(args);
|
|
56
|
+
apifyMcpServer.tools.delete(parsed.toolName);
|
|
57
|
+
await mcpServer.notification({ method: 'notifications/tools/list_changed' });
|
|
58
|
+
return { content: [{ type: 'text', text: `Tool ${parsed.toolName} was removed` }] };
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/tools/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,eAAe,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;SAChB,QAAQ,CAAC,mFAAmF;UACvF,mDAAmD,CAAC;CACjE,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,OAAO,GAAa;IAC7B,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE;QACF,IAAI,EAAE,WAAW,CAAC,QAAQ;QAC1B,WAAW,EAAE,gFAAgF;cACvF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UAAU;IAChB,IAAI,EAAE;QACF,IAAI,EAAE,WAAW,CAAC,WAAW;QAC7B,WAAW,EAAE,sEAAsE;cAC7E,yEAAyE;QAC/E,WAAW,EAAE,eAAe,CAAC,oBAAoB,CAAC;QAClD,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC;QAC/D,kFAAkF;QAClF,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;YACrB,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;YAErD,MAAM,MAAM,GAAG,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAChD,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7C,MAAM,SAAS,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,kCAAkC,EAAE,CAAC,CAAC;YAC7E,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,MAAM,CAAC,QAAQ,cAAc,EAAE,CAAC,EAAE,CAAC;QACxF,CAAC;KACY;CACpB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { callActorGetDataset, getActorsAsTools } from './actor.js';
|
|
2
|
+
import { actorDefinitionTool } from './build.js';
|
|
3
|
+
import { addTool, removeTool } from './helpers.js';
|
|
4
|
+
import { searchActorTool } from './store_collection.js';
|
|
5
|
+
export { addTool, removeTool, actorDefinitionTool, searchActorTool as searchTool, getActorsAsTools, callActorGetDataset };
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,IAAI,UAAU,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Import specific tools that are being used
|
|
2
|
+
import { callActorGetDataset, getActorsAsTools } from './actor.js';
|
|
3
|
+
import { actorDefinitionTool } from './build.js';
|
|
4
|
+
import { addTool, removeTool } from './helpers.js';
|
|
5
|
+
import { searchActorTool } from './store_collection.js';
|
|
6
|
+
// Export only the tools that are being used
|
|
7
|
+
export { addTool, removeTool, actorDefinitionTool, searchActorTool as searchTool, getActorsAsTools, callActorGetDataset };
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,4CAA4C;AAC5C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,IAAI,UAAU,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ActorStorePruned, ToolWrap } from '../types.js';
|
|
3
|
+
export declare function searchActorsByKeywords(search: string, apifyToken: string, limit?: number | undefined, offset?: number | undefined): Promise<ActorStorePruned[] | null>;
|
|
4
|
+
export declare const SearchToolArgsSchema: z.ZodObject<{
|
|
5
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
6
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
7
|
+
search: z.ZodDefault<z.ZodString>;
|
|
8
|
+
category: z.ZodDefault<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
limit: number;
|
|
11
|
+
search: string;
|
|
12
|
+
offset: number;
|
|
13
|
+
category: string;
|
|
14
|
+
}, {
|
|
15
|
+
limit?: number | undefined;
|
|
16
|
+
search?: string | undefined;
|
|
17
|
+
offset?: number | undefined;
|
|
18
|
+
category?: string | undefined;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const searchActorTool: ToolWrap;
|
|
21
|
+
//# sourceMappingURL=store_collection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store_collection.d.ts","sourceRoot":"","sources":["../../src/tools/store_collection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,KAAK,EAAE,gBAAgB,EAA2B,QAAQ,EAAE,MAAM,aAAa,CAAC;AA4BvF,wBAAsB,sBAAsB,CACxC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,KAAK,GAAE,MAAM,GAAG,SAAqB,EACrC,MAAM,GAAE,MAAM,GAAG,SAAqB,GACvC,OAAO,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAIpC;AAGD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;EAqB/B,CAAC;AACH,eAAO,MAAM,eAAe,EAAE,QA0B7B,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Ajv } from 'ajv';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import zodToJsonSchema from 'zod-to-json-schema';
|
|
4
|
+
import { ApifyClient } from '../apify-client.js';
|
|
5
|
+
import { HelperTools } from '../const.js';
|
|
6
|
+
function pruneActorStoreInfo(response) {
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
8
|
+
const stats = response.stats || {};
|
|
9
|
+
const pricingInfo = (response.currentPricingInfo || {});
|
|
10
|
+
return {
|
|
11
|
+
id: response.id,
|
|
12
|
+
name: ((_a = response.name) === null || _a === void 0 ? void 0 : _a.toString()) || '',
|
|
13
|
+
username: ((_b = response.username) === null || _b === void 0 ? void 0 : _b.toString()) || '',
|
|
14
|
+
actorFullName: `${response.username}/${response.name}`,
|
|
15
|
+
title: ((_c = response.title) === null || _c === void 0 ? void 0 : _c.toString()) || '',
|
|
16
|
+
description: ((_d = response.description) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
17
|
+
stats: {
|
|
18
|
+
totalRuns: stats.totalRuns,
|
|
19
|
+
totalUsers30Days: stats.totalUsers30Days,
|
|
20
|
+
publicActorRunStats30Days: 'publicActorRunStats30Days' in stats
|
|
21
|
+
? stats.publicActorRunStats30Days : {},
|
|
22
|
+
},
|
|
23
|
+
currentPricingInfo: {
|
|
24
|
+
pricingModel: ((_e = pricingInfo.pricingModel) === null || _e === void 0 ? void 0 : _e.toString()) || '',
|
|
25
|
+
pricePerUnitUsd: (_f = pricingInfo === null || pricingInfo === void 0 ? void 0 : pricingInfo.pricePerUnitUsd) !== null && _f !== void 0 ? _f : 0,
|
|
26
|
+
trialMinutes: (_g = pricingInfo === null || pricingInfo === void 0 ? void 0 : pricingInfo.trialMinutes) !== null && _g !== void 0 ? _g : 0,
|
|
27
|
+
},
|
|
28
|
+
url: ((_h = response.url) === null || _h === void 0 ? void 0 : _h.toString()) || '',
|
|
29
|
+
totalStars: 'totalStars' in response ? response.totalStars : null,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export async function searchActorsByKeywords(search, apifyToken, limit = undefined, offset = undefined) {
|
|
33
|
+
const client = new ApifyClient({ token: apifyToken });
|
|
34
|
+
const results = await client.store().list({ search, limit, offset });
|
|
35
|
+
return results.items.map((x) => pruneActorStoreInfo(x));
|
|
36
|
+
}
|
|
37
|
+
const ajv = new Ajv({ coerceTypes: 'array', strict: false });
|
|
38
|
+
export const SearchToolArgsSchema = z.object({
|
|
39
|
+
limit: z.number()
|
|
40
|
+
.int()
|
|
41
|
+
.min(1)
|
|
42
|
+
.max(100)
|
|
43
|
+
.default(10)
|
|
44
|
+
.describe('The maximum number of Actors to return. Default value is 10.'),
|
|
45
|
+
offset: z.number()
|
|
46
|
+
.int()
|
|
47
|
+
.min(0)
|
|
48
|
+
.default(0)
|
|
49
|
+
.describe('The number of elements that should be skipped at the start. Default value is 0.'),
|
|
50
|
+
search: z.string()
|
|
51
|
+
.default('')
|
|
52
|
+
.describe('String of key words to search Actors by. '
|
|
53
|
+
+ 'Searches the title, name, description, username, and readme of an Actor.'
|
|
54
|
+
+ 'Only key word search is supported, no advanced search.'
|
|
55
|
+
+ 'Always prefer simple keywords over complex queries.'),
|
|
56
|
+
category: z.string()
|
|
57
|
+
.default('')
|
|
58
|
+
.describe('Filters the results by the specified category.'),
|
|
59
|
+
});
|
|
60
|
+
export const searchActorTool = {
|
|
61
|
+
type: 'internal',
|
|
62
|
+
tool: {
|
|
63
|
+
name: HelperTools.SEARCH_ACTOR,
|
|
64
|
+
actorFullName: HelperTools.SEARCH_ACTOR,
|
|
65
|
+
description: `Discover available Actors or MCP-Servers in Apify Store using full text search using keywords.`
|
|
66
|
+
+ `Users try to discover Actors using free form query in this case search query must be converted to full text search. `
|
|
67
|
+
+ `Returns a list of Actors with name, description, run statistics, pricing, starts, and URL. `
|
|
68
|
+
+ `You perhaps need to use this tool several times to find the right Actor. `
|
|
69
|
+
+ `You should prefer simple keywords over complex queries. `
|
|
70
|
+
+ `Limit number of results returned but ensure that relevant results are returned. `
|
|
71
|
+
+ `This is not a general search tool, it is designed to search for Actors in Apify Store. `,
|
|
72
|
+
inputSchema: zodToJsonSchema(SearchToolArgsSchema),
|
|
73
|
+
ajvValidate: ajv.compile(zodToJsonSchema(SearchToolArgsSchema)),
|
|
74
|
+
call: async (toolArgs) => {
|
|
75
|
+
const { args, apifyToken } = toolArgs;
|
|
76
|
+
const parsed = SearchToolArgsSchema.parse(args);
|
|
77
|
+
const actors = await searchActorsByKeywords(parsed.search, apifyToken, parsed.limit, parsed.offset);
|
|
78
|
+
return { content: actors === null || actors === void 0 ? void 0 : actors.map((item) => ({ type: 'text', text: JSON.stringify(item) })) };
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=store_collection.js.map
|