Skip to content

Commit cb9be76

Browse files
committed
fix get default build in get actor definition
1 parent 29f3561 commit cb9be76

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/apify-client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ function addUserAgent(config: AxiosRequestConfig): AxiosRequestConfig {
1717
return updatedConfig;
1818
}
1919

20+
export function getApifyAPIBaseUrl(): string {
21+
return process.env.APIFY_API_BASE_URL || 'https://api.apify.com';
22+
}
23+
2024
export class ApifyClient extends _ApifyClient {
2125
constructor(options: ApifyClientOptions) {
2226
super({
2327
...options,
24-
baseUrl: process.env.APIFY_API_BASE_URL || undefined,
28+
baseUrl: getApifyAPIBaseUrl(),
2529
requestInterceptors: [addUserAgent],
2630
});
2731
}

src/mcp/actors.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { ActorDefinition } from "apify-client";
3-
import { ApifyClient } from "../apify-client.js";
3+
import { ApifyClient, getApifyAPIBaseUrl } from "../apify-client.js";
44

55

66
export async function isActorMCPServer(actorID: string, apifyToken: string): Promise<boolean> {
@@ -58,18 +58,23 @@ export async function getActorDefinition(actorID: string, apifyToken: string): P
5858
if (!info) {
5959
throw new Error(`Actor ${actorID} not found`);
6060
}
61-
const latestBuildID = info.taggedBuilds?.['latest']?.buildId;
62-
if (!latestBuildID) {
63-
throw new Error(`Actor ${actorID} does not have a latest build`);
61+
const actorObjID = info.id;
62+
const res = await fetch(`${getApifyAPIBaseUrl()}/v2/acts/${actorObjID}/builds/default`, {
63+
headers: {
64+
'Authorization': `Bearer ${apifyToken}`
65+
}
66+
});
67+
if (!res.ok) {
68+
throw new Error(`Failed to fetch default build for actor ${actorID}: ${res.statusText}`);
6469
}
65-
const build = apifyClient.build(latestBuildID);
66-
const buildInfo = await build.get();
70+
const json = await res.json() as any;
71+
const buildInfo = json.data;
6772
if (!buildInfo) {
68-
throw new Error(`Build ${latestBuildID} not found`);
73+
throw new Error(`Default build for Actor ${actorID} not found`);
6974
}
7075
const actorDefinition = buildInfo.actorDefinition;
7176
if (!actorDefinition) {
72-
throw new Error(`Build ${latestBuildID} does not have an actor definition`);
77+
throw new Error(`Actor default build ${actorID} does not have Actor definition`);
7378
}
7479

7580
return actorDefinition;

0 commit comments

Comments
 (0)