@apify/actors-mcp-server 0.1.21 → 0.1.22-beta.1
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 +1 -1
- package/dist/actor/const.d.ts +10 -0
- package/dist/actor/const.d.ts.map +1 -0
- package/dist/actor/const.js +11 -0
- package/dist/actor/const.js.map +1 -0
- package/dist/{input.d.ts → actor/input.d.ts} +1 -1
- package/dist/actor/input.d.ts.map +1 -0
- package/dist/{input.js → actor/input.js} +5 -1
- package/dist/actor/input.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 +81 -0
- package/dist/actor/server.js.map +1 -0
- package/dist/actor/types.d.ts +30 -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 +11 -0
- package/dist/actor/utils.d.ts.map +1 -0
- package/dist/actor/utils.js +50 -0
- package/dist/actor/utils.js.map +1 -0
- package/dist/const.d.ts +13 -18
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +21 -22
- package/dist/const.js.map +1 -1
- package/dist/examples/clientSse.d.ts +10 -1
- package/dist/examples/clientSse.d.ts.map +1 -1
- package/dist/examples/clientSse.js +7 -4
- package/dist/examples/clientSse.js.map +1 -1
- package/dist/examples/clientStdio.js +2 -2
- package/dist/examples/clientStdio.js.map +1 -1
- package/dist/examples/clientStdioChat.js +1 -1
- package/dist/index.d.ts +2 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -42
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +4 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +21 -118
- package/dist/main.js.map +1 -1
- package/dist/mcp-server.d.ts +39 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +155 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/stdio.d.ts +15 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +46 -0
- package/dist/stdio.js.map +1 -0
- package/dist/tools/actor.d.ts +37 -0
- package/dist/tools/actor.d.ts.map +1 -0
- package/dist/tools/actor.js +89 -0
- package/dist/tools/actor.js.map +1 -0
- package/dist/tools/build.d.ts +12 -0
- package/dist/tools/build.d.ts.map +1 -0
- package/dist/tools/build.js +120 -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/mcp-apify-client.d.ts +6 -0
- package/dist/tools/mcp-apify-client.d.ts.map +1 -0
- package/dist/tools/mcp-apify-client.js +22 -0
- package/dist/tools/mcp-apify-client.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 +80 -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/{actors.js → tools/utils.js} +112 -241
- package/dist/tools/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +70 -9
- 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.map +0 -1
- package/dist/input.d.ts.map +0 -1
- package/dist/input.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
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Ajv } from 'ajv';
|
|
2
|
+
import { ApifyClient } from 'apify-client';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import zodToJsonSchema from 'zod-to-json-schema';
|
|
5
|
+
import log from '@apify/log';
|
|
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
|
+
* @returns {Promise<ActorDefinitionWithDesc | null>} - The actor definition with description or null if not found.
|
|
16
|
+
*/
|
|
17
|
+
export async function getActorDefinition(actorIdOrName, limit = ACTOR_README_MAX_LENGTH) {
|
|
18
|
+
const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
|
|
19
|
+
const actorClient = client.actor(actorIdOrName);
|
|
20
|
+
try {
|
|
21
|
+
// Fetch actor details
|
|
22
|
+
const actor = await actorClient.get();
|
|
23
|
+
if (!actor) {
|
|
24
|
+
log.error(`Failed to fetch input schema for Actor: ${actorIdOrName}. Actor not found.`);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
// fnesveda: The default build is not necessarily tagged, you can specify any build number as default build.
|
|
28
|
+
// There will be a new API endpoint to fetch a default build.
|
|
29
|
+
// For now, we'll use the tagged build, it will work for 90% of Actors. Later, we can update this.
|
|
30
|
+
const tag = actor.defaultRunOptions?.build || '';
|
|
31
|
+
const buildId = actor.taggedBuilds?.[tag]?.buildId || '';
|
|
32
|
+
if (!buildId) {
|
|
33
|
+
log.error(`Failed to fetch input schema for Actor: ${actorIdOrName}. Build ID not found.`);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
// Fetch build details and return the input schema
|
|
37
|
+
const buildDetails = await client.build(buildId).get();
|
|
38
|
+
if (buildDetails?.actorDefinition) {
|
|
39
|
+
const actorDefinitions = buildDetails?.actorDefinition;
|
|
40
|
+
actorDefinitions.id = actor.id;
|
|
41
|
+
actorDefinitions.readme = truncateActorReadme(actorDefinitions.readme || '', limit);
|
|
42
|
+
actorDefinitions.description = actor.description || '';
|
|
43
|
+
actorDefinitions.actorFullName = `${actor.username}/${actor.name}`;
|
|
44
|
+
actorDefinitions.defaultRunOptions = actor.defaultRunOptions;
|
|
45
|
+
return pruneActorDefinition(actorDefinitions);
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
const errorMessage = `Failed to fetch input schema for Actor: ${actorIdOrName} with error ${error}.`;
|
|
51
|
+
log.error(errorMessage);
|
|
52
|
+
throw new Error(errorMessage);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function pruneActorDefinition(response) {
|
|
56
|
+
return {
|
|
57
|
+
id: response.id,
|
|
58
|
+
actorFullName: response.actorFullName || '',
|
|
59
|
+
buildTag: response?.buildTag || '',
|
|
60
|
+
readme: response?.readme || '',
|
|
61
|
+
input: response?.input && 'type' in response.input && 'properties' in response.input
|
|
62
|
+
? {
|
|
63
|
+
...response.input,
|
|
64
|
+
type: response.input.type,
|
|
65
|
+
properties: response.input.properties,
|
|
66
|
+
}
|
|
67
|
+
: undefined,
|
|
68
|
+
description: response.description,
|
|
69
|
+
defaultRunOptions: response.defaultRunOptions,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Prune Actor README if it is too long
|
|
73
|
+
* If the README is too long
|
|
74
|
+
* - We keep the README as it is up to the limit.
|
|
75
|
+
* - After the limit, we keep heading only
|
|
76
|
+
* - We add a note that the README was truncated because it was too long.
|
|
77
|
+
*/
|
|
78
|
+
function truncateActorReadme(readme, limit = ACTOR_README_MAX_LENGTH) {
|
|
79
|
+
if (readme.length <= limit) {
|
|
80
|
+
return readme;
|
|
81
|
+
}
|
|
82
|
+
const readmeFirst = readme.slice(0, limit);
|
|
83
|
+
const readmeRest = readme.slice(limit);
|
|
84
|
+
const lines = readmeRest.split('\n');
|
|
85
|
+
const prunedReadme = lines.filter((line) => line.startsWith('#'));
|
|
86
|
+
return `${readmeFirst}\n\nREADME was truncated because it was too long. Remaining headers:\n${prunedReadme.join(', ')}`;
|
|
87
|
+
}
|
|
88
|
+
const GetActorDefinitionArgsSchema = z.object({
|
|
89
|
+
actorName: z.string()
|
|
90
|
+
.describe('Retrieve input, readme, and other details for Actor ID or Actor full name. '
|
|
91
|
+
+ 'Actor name is always composed from `username/name`'),
|
|
92
|
+
limit: z.number()
|
|
93
|
+
.int()
|
|
94
|
+
.default(ACTOR_README_MAX_LENGTH)
|
|
95
|
+
.describe(`Truncate the README to this limit. Default value is ${ACTOR_README_MAX_LENGTH}.`),
|
|
96
|
+
});
|
|
97
|
+
export const actorDefinitionTool = {
|
|
98
|
+
type: 'internal',
|
|
99
|
+
tool: {
|
|
100
|
+
name: HelperTools.GET_TOOL_DETAILS,
|
|
101
|
+
actorFullName: HelperTools.GET_TOOL_DETAILS,
|
|
102
|
+
description: 'Get documentation, readme, input schema and other details about an Actor. '
|
|
103
|
+
+ 'For example, when user says, I need to know more about web crawler Actor.'
|
|
104
|
+
+ 'Get details for an Actor with with Actor ID or Actor full name, i.e. username/name.'
|
|
105
|
+
+ `Limit the length of the README if needed.`,
|
|
106
|
+
inputSchema: zodToJsonSchema(GetActorDefinitionArgsSchema),
|
|
107
|
+
ajvValidate: ajv.compile(zodToJsonSchema(GetActorDefinitionArgsSchema)),
|
|
108
|
+
call: async (toolArgs) => {
|
|
109
|
+
const { args } = toolArgs;
|
|
110
|
+
const parsed = GetActorDefinitionArgsSchema.parse(args);
|
|
111
|
+
const v = await getActorDefinition(parsed.actorName, parsed.limit);
|
|
112
|
+
if (v && v.input && 'properties' in v.input && v.input) {
|
|
113
|
+
const properties = filterSchemaProperties(v.input.properties);
|
|
114
|
+
v.input.properties = shortenProperties(properties);
|
|
115
|
+
}
|
|
116
|
+
return { content: [{ type: 'text', text: JSON.stringify(v) }] };
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
//# 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,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,eAAe,MAAM,oBAAoB,CAAC;AAEjD,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEvE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,aAAqB,EAAE,QAAgB,uBAAuB;IACnG,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IACnE,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAChD,IAAI,CAAC;QACD,sBAAsB;QACtB,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,GAAG,EA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,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;AAKxB,OAAO,KAAK,EAA2B,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIlE,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 { actorNameToToolName } from './utils.js';
|
|
6
|
+
import { getActorsAsTools } from './actor.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 to available tools by Tool 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 to available tools by Actor ID or Actor name. '
|
|
18
|
+
+ 'Do not execute the tool, only add it and list it in available tools. '
|
|
19
|
+
+ 'Never run the tool without user consent! '
|
|
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, args } = toolArgs;
|
|
26
|
+
const parsed = AddToolArgsSchema.parse(args);
|
|
27
|
+
const tools = await getActorsAsTools([parsed.actorName]);
|
|
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 tool 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;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,E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import { callActorGetDataset, getActorsAsTools } from './actor.js';
|
|
2
|
+
import { actorDefinitionTool } from './build.js';
|
|
3
|
+
import { addTool, removeTool } from './helpers.js';
|
|
4
|
+
import { searchTool } from './store_collection.js';
|
|
5
|
+
export { addTool, removeTool, actorDefinitionTool, 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,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,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 { searchTool } from './store_collection.js';
|
|
6
|
+
// Export only the tools that are being used
|
|
7
|
+
export { addTool, removeTool, actorDefinitionTool, 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,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,4CAA4C;AAC5C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,UAAU,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-apify-client.d.ts","sourceRoot":"","sources":["../../src/tools/mcp-apify-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,WAAW,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAiB3D,qBAAa,WAAY,SAAQ,YAAY;gBAC7B,OAAO,EAAE,kBAAkB;CAM1C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ApifyClient as _ApifyClient } from 'apify-client';
|
|
2
|
+
import { USER_AGENT_ORIGIN } from '../const.js';
|
|
3
|
+
/**
|
|
4
|
+
* Adds a User-Agent header to the request config.
|
|
5
|
+
* @param config
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
function addUserAgent(config) {
|
|
9
|
+
const updatedConfig = { ...config };
|
|
10
|
+
updatedConfig.headers = updatedConfig.headers ?? {};
|
|
11
|
+
updatedConfig.headers['User-Agent'] = `${updatedConfig.headers['User-Agent'] ?? ''}; ${USER_AGENT_ORIGIN}`;
|
|
12
|
+
return updatedConfig;
|
|
13
|
+
}
|
|
14
|
+
export class ApifyClient extends _ApifyClient {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
super({
|
|
17
|
+
...options,
|
|
18
|
+
requestInterceptors: [addUserAgent],
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=mcp-apify-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-apify-client.js","sourceRoot":"","sources":["../../src/tools/mcp-apify-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAG3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;GAIG;AACH,SAAS,YAAY,CAAC,MAA0B;IAC5C,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IACpC,aAAa,CAAC,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,EAAE,CAAC;IACpD,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,GAAG,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,iBAAiB,EAAE,CAAC;IAC3G,OAAO,aAAa,CAAC;AACzB,CAAC;AAED,MAAM,OAAO,WAAY,SAAQ,YAAY;IACzC,YAAY,OAA2B;QACnC,KAAK,CAAC;YACF,GAAG,OAAO;YACV,mBAAmB,EAAE,CAAC,YAAY,CAAC;SACtC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ActorStorePruned, ToolWrap } from '../types.js';
|
|
3
|
+
export declare function searchActorsByKeywords(search: 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
|
+
search: string;
|
|
11
|
+
limit: number;
|
|
12
|
+
offset: number;
|
|
13
|
+
category: string;
|
|
14
|
+
}, {
|
|
15
|
+
search?: string | undefined;
|
|
16
|
+
limit?: number | undefined;
|
|
17
|
+
offset?: number | undefined;
|
|
18
|
+
category?: string | undefined;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const searchTool: 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":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,KAAK,EAAE,gBAAgB,EAA2B,QAAQ,EAAE,MAAM,aAAa,CAAC;AA4BvF,wBAAsB,sBAAsB,CACxC,MAAM,EAAE,MAAM,EACd,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,UAAU,EAAE,QAwBxB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Ajv } from 'ajv';
|
|
2
|
+
import { ApifyClient } from 'apify-client';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import zodToJsonSchema from 'zod-to-json-schema';
|
|
5
|
+
import { HelperTools } from '../const.js';
|
|
6
|
+
function pruneActorStoreInfo(response) {
|
|
7
|
+
const stats = response.stats || {};
|
|
8
|
+
const pricingInfo = (response.currentPricingInfo || {});
|
|
9
|
+
return {
|
|
10
|
+
id: response.id,
|
|
11
|
+
name: response.name?.toString() || '',
|
|
12
|
+
username: response.username?.toString() || '',
|
|
13
|
+
actorFullName: `${response.username}/${response.name}`,
|
|
14
|
+
title: response.title?.toString() || '',
|
|
15
|
+
description: response.description?.toString() || '',
|
|
16
|
+
stats: {
|
|
17
|
+
totalRuns: stats.totalRuns,
|
|
18
|
+
totalUsers30Days: stats.totalUsers30Days,
|
|
19
|
+
publicActorRunStats30Days: 'publicActorRunStats30Days' in stats
|
|
20
|
+
? stats.publicActorRunStats30Days : {},
|
|
21
|
+
},
|
|
22
|
+
currentPricingInfo: {
|
|
23
|
+
pricingModel: pricingInfo.pricingModel?.toString() || '',
|
|
24
|
+
pricePerUnitUsd: pricingInfo?.pricePerUnitUsd ?? 0,
|
|
25
|
+
trialMinutes: pricingInfo?.trialMinutes ?? 0,
|
|
26
|
+
},
|
|
27
|
+
url: response.url?.toString() || '',
|
|
28
|
+
totalStars: 'totalStars' in response ? response.totalStars : null,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export async function searchActorsByKeywords(search, limit = undefined, offset = undefined) {
|
|
32
|
+
const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
|
|
33
|
+
const results = await client.store().list({ search, limit, offset });
|
|
34
|
+
return results.items.map((x) => pruneActorStoreInfo(x));
|
|
35
|
+
}
|
|
36
|
+
const ajv = new Ajv({ coerceTypes: 'array', strict: false });
|
|
37
|
+
export const SearchToolArgsSchema = z.object({
|
|
38
|
+
limit: z.number()
|
|
39
|
+
.int()
|
|
40
|
+
.min(1)
|
|
41
|
+
.max(100)
|
|
42
|
+
.default(10)
|
|
43
|
+
.describe('The maximum number of Actors to return. Default value is 10.'),
|
|
44
|
+
offset: z.number()
|
|
45
|
+
.int()
|
|
46
|
+
.min(0)
|
|
47
|
+
.default(0)
|
|
48
|
+
.describe('The number of elements that should be skipped at the start. Default value is 0.'),
|
|
49
|
+
search: z.string()
|
|
50
|
+
.default('')
|
|
51
|
+
.describe('String of key words to search by. '
|
|
52
|
+
+ 'Searches the title, name, description, username, and readme of an Actor.'
|
|
53
|
+
+ 'Only key word search is supported, no advanced search.'
|
|
54
|
+
+ 'Always prefer simple keywords over complex queries.'),
|
|
55
|
+
category: z.string()
|
|
56
|
+
.default('')
|
|
57
|
+
.describe('Filters the results by the specified category.'),
|
|
58
|
+
});
|
|
59
|
+
export const searchTool = {
|
|
60
|
+
type: 'internal',
|
|
61
|
+
tool: {
|
|
62
|
+
name: HelperTools.SEARCH,
|
|
63
|
+
actorFullName: HelperTools.SEARCH,
|
|
64
|
+
description: `Discover available Actors using full text search using keywords.`
|
|
65
|
+
+ `Users try to discover Actors using free form query in this case search query needs to be converted to full text search. `
|
|
66
|
+
+ `Prefer Actors from Apify as they are generally more reliable and have better support. `
|
|
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
|
+
+ `Limit number of results returned but ensure that relevant results are returned. `,
|
|
70
|
+
inputSchema: zodToJsonSchema(SearchToolArgsSchema),
|
|
71
|
+
ajvValidate: ajv.compile(zodToJsonSchema(SearchToolArgsSchema)),
|
|
72
|
+
call: async (toolArgs) => {
|
|
73
|
+
const { args } = toolArgs;
|
|
74
|
+
const parsed = SearchToolArgsSchema.parse(args);
|
|
75
|
+
const actors = await searchActorsByKeywords(parsed.search, parsed.limit, parsed.offset);
|
|
76
|
+
return { content: actors?.map((item) => ({ type: 'text', text: JSON.stringify(item) })) };
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=store_collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store_collection.js","sourceRoot":"","sources":["../../src/tools/store_collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,eAAe,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,SAAS,mBAAmB,CAAC,QAAwB;IACjD,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC;IACnC,MAAM,WAAW,GAAG,CAAC,QAAQ,CAAC,kBAAkB,IAAI,EAAE,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3E,kFAAkF;QACxF,WAAW,EAAE,eAAe,CAAC,oBAAoB,CAAC;QAClD,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC;QAC/D,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;YACrB,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;YAC1B,MAAM,MAAM,GAAG,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAChD,MAAM,MAAM,GAAG,MAAM,sBAAsB,CACvC,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,MAAM,CAChB,CAAC;YACF,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAC9F,CAAC;KACU;CAClB,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { IActorInputSchema, ISchemaProperties } from '../types.js';
|
|
2
|
+
export declare function actorNameToToolName(actorName: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Builds nested properties for object types in the schema.
|
|
5
|
+
*
|
|
6
|
+
* Specifically handles special cases like proxy configuration and request list sources
|
|
7
|
+
* by adding predefined nested properties to these object types.
|
|
8
|
+
* This is necessary for the agent to correctly infer how to structure object inputs
|
|
9
|
+
* when passing arguments to the Actor.
|
|
10
|
+
*
|
|
11
|
+
* For proxy objects (type='object', editor='proxy'), adds 'useApifyProxy' property.
|
|
12
|
+
* For request list sources (type='array', editor='requestListSources'), adds URL structure to items.
|
|
13
|
+
*
|
|
14
|
+
* @param {Record<string, ISchemaProperties>} properties - The input schema properties
|
|
15
|
+
* @returns {Record<string, ISchemaProperties>} Modified properties with nested properties
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildNestedProperties(properties: Record<string, ISchemaProperties>): Record<string, ISchemaProperties>;
|
|
18
|
+
/**
|
|
19
|
+
* Filters schema properties to include only the necessary fields.
|
|
20
|
+
*
|
|
21
|
+
* This is done to reduce the size of the input schema and to make it more readable.
|
|
22
|
+
*
|
|
23
|
+
* @param properties
|
|
24
|
+
*/
|
|
25
|
+
export declare function filterSchemaProperties(properties: {
|
|
26
|
+
[key: string]: ISchemaProperties;
|
|
27
|
+
}): {
|
|
28
|
+
[key: string]: ISchemaProperties;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Marks input properties as required by adding a "REQUIRED" prefix to their descriptions.
|
|
32
|
+
* Takes an IActorInput object and returns a modified Record of SchemaProperties.
|
|
33
|
+
*
|
|
34
|
+
* This is done for maximum compatibility in case where library or agent framework does not consider
|
|
35
|
+
* required fields and does not handle the JSON schema properly: we are prepending this to the description
|
|
36
|
+
* as a preventive measure.
|
|
37
|
+
* @param {IActorInputSchema} input - Actor input object containing properties and required fields
|
|
38
|
+
* @returns {Record<string, ISchemaProperties>} - Modified properties with required fields marked
|
|
39
|
+
*/
|
|
40
|
+
export declare function markInputPropertiesAsRequired(input: IActorInputSchema): Record<string, ISchemaProperties>;
|
|
41
|
+
/**
|
|
42
|
+
* Helps determine the type of items in an array schema property.
|
|
43
|
+
* Priority order: explicit type in items > prefill type > default value type > editor type.
|
|
44
|
+
*
|
|
45
|
+
* Based on JSON schema, the array needs a type, and most of the time Actor input schema does not have this, so we need to infer that.
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
export declare function inferArrayItemType(property: ISchemaProperties): string | null;
|
|
49
|
+
/**
|
|
50
|
+
* Add enum values as string to property descriptions.
|
|
51
|
+
*
|
|
52
|
+
* This is done as a preventive measure to prevent cases where library or agent framework
|
|
53
|
+
* does not handle enums or examples based on JSON schema definition.
|
|
54
|
+
*
|
|
55
|
+
* https://json-schema.org/understanding-json-schema/reference/enum
|
|
56
|
+
* https://json-schema.org/understanding-json-schema/reference/annotations
|
|
57
|
+
*
|
|
58
|
+
* @param properties
|
|
59
|
+
*/
|
|
60
|
+
export declare function addEnumsToDescriptionsWithExamples(properties: Record<string, ISchemaProperties>): Record<string, ISchemaProperties>;
|
|
61
|
+
/**
|
|
62
|
+
* Helper function to shorten the enum list if it is too long.
|
|
63
|
+
*
|
|
64
|
+
* @param {string[]} enumList - The list of enum values to be shortened.
|
|
65
|
+
* @returns {string[] | undefined} - The shortened enum list or undefined if the list is too long.
|
|
66
|
+
*/
|
|
67
|
+
export declare function shortenEnum(enumList: string[]): string[] | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Shortens the description, enum, and items.enum properties of the schema properties.
|
|
70
|
+
* @param properties
|
|
71
|
+
*/
|
|
72
|
+
export declare function shortenProperties(properties: {
|
|
73
|
+
[key: string]: ISchemaProperties;
|
|
74
|
+
}): {
|
|
75
|
+
[key: string]: ISchemaProperties;
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/tools/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAExE,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAK7D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAwCtH;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAA;CAAE,GAAG;IACtF,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAA;CACnC,CA2BA;AAED;;;;;;;;;GASG;AACH,wBAAgB,6B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