Skip to content

Commit 4a5c35d

Browse files
committed
chore: update upserTools and tool to instantiate client correcty
1 parent 34ff1e3 commit 4a5c35d

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/const.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export const SKYFIRE_SELLER_ID = process.env.SKYFIRE_SELLER_SERVICE_ID;
6161

6262
export const SKYFIRE_TOOL_INSTRUCTIONS = `To run the Actor, you need to provide a Skyfire payment ID in the \`skyfire-pay-id\` input property. You first need to create the Skyfire PAY token by calling the \`create-pay-token\` tool from the Skyfire MCP server and then provide the created token in the \`skyfire-pay-id\` input property when calling Actor tool. The Skyfire PAY token is used for billing purposes and needs to be charged with at least ${SKYFIRE_MIN_CHARGE_USD} USD.${SKYFIRE_SELLER_ID ? ` The Skyfire seller ID for Apify MCP server is "${SKYFIRE_SELLER_ID}".` : ''} When retrieving Actor output using the \`get-actor-output\` tool, you also need to provide the same Skyfire PAY token ID in the \`skyfire-pay-id\` input property.`;
6363

64-
export const SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION = `Skyfire PAY token ID used for billing purposes.`;
64+
export const SKYFIRE_ACTOR_SEARCH_INSTRUCTIONS = `To search for Actors, you need to provide valid Skyfire KYA token for identification in the \`skyfire-pay-id\` input property. You first need to create the Skyfire token by calling the \`create-kya-token\` tool from the Skyfire MCP server.${SKYFIRE_SELLER_ID ? ` The Skyfire seller ID for Apify MCP server is "${SKYFIRE_SELLER_ID}".` : ''} Alternatively you can provide PAY or KYA+PAY token instead.`;
65+
66+
export const SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION = `Skyfire PAY, KYA, KYA+PAY token ID used for authentication and billing purposes.`;
6567

6668
export const SKYFIRE_README_CONTENT = `The Apify MCP Server allows clients to interact with Apify Actors, storage, and documentation. Before running any Apify Actor, you need to set up a Skyfire PAY token for billing purposes. To set up the PAY token you need to use the create-pay-token tool from the Skyfire MCP server. The PAY token must be charged with a minimum of ${SKYFIRE_MIN_CHARGE_USD} USD to be valid.${SKYFIRE_SELLER_ID ? ` The Skyfire seller ID for Apify MCP server is "${SKYFIRE_SELLER_ID}".` : ''} When running an Actor using the call-actor tool, you must provide the Skyfire PAY token ID in the \`skyfire-pay-id\` input property. Similarly, when retrieving Actor output using the get-actor-output tool, you must also provide the same Skyfire PAY token ID in the \`skyfire-pay-id\` input property.`;
6769

src/mcp/server.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
HelperTools,
3131
SERVER_NAME,
3232
SERVER_VERSION,
33+
SKYFIRE_ACTOR_SEARCH_INSTRUCTIONS,
3334
SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION,
3435
SKYFIRE_README_CONTENT,
3536
SKYFIRE_TOOL_INSTRUCTIONS,
@@ -272,7 +273,12 @@ export class ActorsMcpServer {
272273
|| (wrap.type === 'internal' && wrap.tool.name === HelperTools.ACTOR_CALL)
273274
|| (wrap.type === 'internal' && wrap.tool.name === HelperTools.ACTOR_OUTPUT_GET)) {
274275
// Add Skyfire instructions to description if not already present
275-
if (!wrap.tool.description.includes(SKYFIRE_TOOL_INSTRUCTIONS)) {
276+
if (wrap.type === 'internal' && wrap.tool.name === HelperTools.STORE_SEARCH) {
277+
// Add description
278+
if (!wrap.tool.description.includes(SKYFIRE_ACTOR_SEARCH_INSTRUCTIONS)) {
279+
wrap.tool.description += `\n\n${SKYFIRE_ACTOR_SEARCH_INSTRUCTIONS}`;
280+
}
281+
} else if (!wrap.tool.description.includes(SKYFIRE_TOOL_INSTRUCTIONS)) {
276282
wrap.tool.description += `\n\n${SKYFIRE_TOOL_INSTRUCTIONS}`;
277283
}
278284
// Add skyfire-pay-id property if not present

src/tools/store_collection.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { z } from 'zod';
33
import zodToJsonSchema from 'zod-to-json-schema';
44

55
import { ApifyClient } from '../apify-client.js';
6-
import { ACTOR_SEARCH_ABOVE_LIMIT, HelperTools } from '../const.js';
6+
import { ACTOR_SEARCH_ABOVE_LIMIT, HelperTools, SKYFIRE_ACTOR_SEARCH_INSTRUCTIONS } from '../const.js';
77
import type { ActorPricingModel, ExtendedActorStoreList, HelperTool, ToolEntry } from '../types.js';
88
import { formatActorToActorCard } from '../utils/actor-card.js';
99
import { ajv } from '../utils/ajv.js';
@@ -13,11 +13,17 @@ export async function searchActorsByKeywords(
1313
apifyToken: string,
1414
limit: number | undefined = undefined,
1515
offset: number | undefined = undefined,
16-
allowsAgenticUsers: boolean | undefined = undefined,
16+
skyfirePayId: string | undefined = undefined,
1717
): Promise<ExtendedActorStoreList[]> {
18-
const client = new ApifyClient({ token: apifyToken });
18+
19+
/**
20+
* Create Apify token, for Skyfire mode use `skyfire-pay-id` and for normal mode use `apifyToken`.
21+
*/
22+
const client = skyfirePayId
23+
? new ApifyClient({ skyfirePayId })
24+
: new ApifyClient({ token: apifyToken });
1925
const storeClient = client.store();
20-
if (allowsAgenticUsers !== undefined) storeClient.params = { ...storeClient.params, allowsAgenticUsers };
26+
if (skyfirePayId) storeClient.params = { ...storeClient.params, allowsAgenticUsers: true };
2127

2228
const results = await storeClient.list({ search, limit, offset });
2329
return results.items;
@@ -96,12 +102,28 @@ USAGE EXAMPLES:
96102
call: async (toolArgs) => {
97103
const { args, apifyToken, userRentedActorIds, apifyMcpServer } = toolArgs;
98104
const parsed = searchActorsArgsSchema.parse(args);
105+
106+
/**
107+
* In Skyfire mode, we check for the presence of `skyfire-pay-id`.
108+
* If it is missing, we return instructions to the LLM on how to create it and pass it to the tool.
109+
*/
110+
if (apifyMcpServer.options.skyfireMode
111+
&& args['skyfire-pay-id'] === undefined
112+
) {
113+
return {
114+
content: [{
115+
type: 'text',
116+
text: SKYFIRE_ACTOR_SEARCH_INSTRUCTIONS,
117+
}],
118+
};
119+
}
120+
99121
let actors = await searchActorsByKeywords(
100122
parsed.search,
101123
apifyToken,
102124
parsed.limit + ACTOR_SEARCH_ABOVE_LIMIT,
103125
parsed.offset,
104-
apifyMcpServer.options.skyfireMode ? true : undefined, // allowsAgenticUsers - filters Actors available for Agentic users
126+
apifyMcpServer.options.skyfireMode && typeof args['skyfire-pay-id'] === 'string' ? args['skyfire-pay-id'] : undefined, // // skyfirePayId
105127
);
106128
actors = filterRentalActors(actors || [], userRentedActorIds || []).slice(0, parsed.limit);
107129
const actorCards = actors.length === 0 ? [] : actors.map(formatActorToActorCard);

0 commit comments

Comments
 (0)