Skip to content

Commit ec92cde

Browse files
committed
move cache to top, rename var and add clarification, add search
integration test
1 parent 37949a7 commit ec92cde

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

src/mcp/actors.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export async function getActorStandbyURL(actorID: string, apifyToken: string, st
5656
return `https://${actorRealID}.${standbyBaseUrl}`;
5757
}
5858

59-
// TODO: optimize this to only use /builds/default endpoint with Actor name replacing / with ~
6059
export async function getActorDefinition(actorID: string, apifyToken: string): Promise<ActorDefinition> {
6160
const apifyClient = new ApifyClient({ token: apifyToken });
6261
const actor = apifyClient.actor(actorID);

src/tools/actor.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ import {
2121
shortenProperties,
2222
} from './utils.js';
2323

24+
25+
// Cache for normal Actor tools
26+
const normalActorToolsCache = new LruCache<ToolCacheEntry>({
27+
maxLength: TOOL_CACHE_MAX_SIZE,
28+
});
29+
2430
/**
2531
* Calls an Apify actor and retrieves the dataset items.
2632
*
@@ -59,10 +65,6 @@ export async function callActorGetDataset(
5965
}
6066
}
6167

62-
// Cache for normal Actor tools
63-
const normalActorToolsCache = new LruCache<ToolCacheEntry>({
64-
maxLength: TOOL_CACHE_MAX_SIZE,
65-
});
6668
/**
6769
* This function is used to fetch normal non-MCP server Actors as a tool.
6870
*
@@ -111,7 +113,11 @@ export async function getNormalActorsAsTools(
111113
// Zip the results with their corresponding actorIDs
112114
for (let i = 0; i < results.length; i++) {
113115
const result = results[i];
114-
const actorID = actorsToLoad[i];
116+
// We need to get the orignal input from the user
117+
// sonce the user can input real Actor ID like '3ox4R101TgZz67sLr' instead of
118+
// 'username/actorName' even though we encourage that.
119+
// And the getActorDefinition does not return the original input it received, just the actorFullName or actorID
120+
const actorIDOrName = actorsToLoad[i];
115121

116122
if (result) {
117123
if (result.input && 'properties' in result.input && result.input) {
@@ -135,7 +141,7 @@ export async function getNormalActorsAsTools(
135141
},
136142
};
137143
tools.push(tool);
138-
normalActorToolsCache.add(actorID, {
144+
normalActorToolsCache.add(actorIDOrName, {
139145
tool,
140146
expiresAt: Date.now() + TOOL_CACHE_TTL_SECS * 1000,
141147
});

tests/integration/suite.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,27 @@ export function createIntegrationTestsSuite(
167167
await client.close();
168168
});
169169

170+
it('should search for Actor successfully', async () => {
171+
const query = 'python-example';
172+
const actorName = 'apify/python-example';
173+
const client = await createClientFn({
174+
enableAddingActors: false,
175+
});
176+
177+
// Remove the actor
178+
const result = await client.callTool({
179+
name: HelperTools.SEARCH_ACTORS,
180+
arguments: {
181+
search: query,
182+
limit: 5,
183+
},
184+
});
185+
const content = result.content as {text: string}[];
186+
expect(content.some((item) => item.text.includes(actorName))).toBe(true);
187+
188+
await client.close();
189+
});
190+
170191
it('should remove Actor from tools list', async () => {
171192
const actor = 'apify/python-example';
172193
const selectedToolName = actorNameToToolName(actor);

vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export default defineConfig({
77
globals: true,
88
environment: 'node',
99
include: ['tests/**/*.test.ts'],
10-
testTimeout: 60_000, // 1 minute
10+
testTimeout: 120_000,
1111
},
1212
});

0 commit comments

Comments
 (0)