Skip to content

Commit 2e41b61

Browse files
committed
fix: fix stdio.only add-actor tool related circular dependency cause by import of getActorsAsTools and pass it as internal tool arg instead.
1 parent f06d72e commit 2e41b61

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/mcp/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ export class ActorsMcpServer {
404404
apifyToken,
405405
userRentedActorIds,
406406
progressTracker,
407+
getActorsAsTools,
407408
}) as object;
408409

409410
if (progressTracker) {

src/tools/helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import zodToJsonSchema from 'zod-to-json-schema';
44

55
import { HelperTools } from '../const.js';
66
import type { InternalTool, ToolEntry } from '../types';
7-
import { getActorsAsTools } from './actor.js';
87
import { actorNameToToolName } from './utils.js';
98

109
const ajv = new Ajv({ coerceTypes: 'array', strict: false });
@@ -49,7 +48,7 @@ export const addTool: ToolEntry = {
4948
ajvValidate: ajv.compile(zodToJsonSchema(addToolArgsSchema)),
5049
// TODO: I don't like that we are passing apifyMcpServer and mcpServer to the tool
5150
call: async (toolArgs) => {
52-
const { apifyMcpServer, apifyToken, args, extra: { sendNotification } } = toolArgs;
51+
const { apifyMcpServer, apifyToken, args, extra: { sendNotification }, getActorsAsTools } = toolArgs;
5352
const parsed = addToolArgsSchema.parse(args);
5453
if (apifyMcpServer.listAllToolNames().includes(parsed.actor)) {
5554
return {
@@ -59,6 +58,9 @@ export const addTool: ToolEntry = {
5958
}],
6059
};
6160
}
61+
if (!getActorsAsTools) {
62+
throw new Error('Internal configuration error: getActorsAsTools must be passed via InternalToolArgs from the MCP server');
63+
}
6264
const tools = await getActorsAsTools([parsed.actor], apifyToken);
6365
/**
6466
* If no tools were found, return a message that the Actor was not found

src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ export type InternalToolArgs = {
108108
userRentedActorIds?: string[];
109109
/** Optional progress tracker for long running internal tools, like call-actor */
110110
progressTracker?: ProgressTracker | null;
111+
/**
112+
* Injected dependency for turning Actor names/IDs into tools.
113+
* Passing it from the server avoids a stdio-only circular import that made the
114+
* add-actor tool null during module initialization.
115+
*/
116+
getActorsAsTools?: (actorIdsOrNames: string[], apifyToken: string) => Promise<ToolEntry[]>;
111117
}
112118

113119
/**

0 commit comments

Comments
 (0)