Skip to content

Commit 45073ea

Browse files
authored
fix: Actor auto loading (corret tool->Actor name conversion) (#31)
* fix: Actor auto loading
1 parent 4bc610d commit 45073ea

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ The server provides a set of helper tools to discover available Actors and retri
9797

9898
There are also tools to manage the available tools list. However, dynamically adding and removing tools requires the MCP client to have the capability to manage the tools list, which is typically not supported.
9999

100-
You can try this functionality using the [Apify Tester MCP Client](https://apify.com/jiri.spilka/tester-mcp-client) Actor. To enable it, set the `enableActorAutoLoading` parameter.
100+
You can try this functionality using the [Apify Tester MCP Client](https://apify.com/jiri.spilka/tester-mcp-client) Actor.
101+
To enable it, set the `enableActorAutoLoading` parameter.
101102

102103
- `add-actor-as-tool`: Adds an Actor by name to the available tools list without executing it, requiring user consent to run later.
103104
- `remove-actor-from-tool`: Removes an Actor by name from the available tools list when it's no longer needed.
@@ -206,7 +207,6 @@ Alternatively, you can use simple python [client_see.py](https://github.com/apif
206207
207208
### Install
208209
209-
Follow the steps below to set up and run the server on your local machine:
210210
First, clone the repository using the following command:
211211
212212
```bash

src/actors.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ import { ApifyClient } from 'apify-client';
33

44
import { ACTOR_ADDITIONAL_INSTRUCTIONS, defaults, MAX_DESCRIPTION_LENGTH } from './const.js';
55
import { log } from './logger.js';
6-
import type {
7-
ActorDefinitionPruned,
8-
ActorDefinitionWithDesc,
9-
SchemaProperties,
10-
Tool,
11-
} from './types.js';
6+
import type { ActorDefinitionPruned, ActorDefinitionWithDesc, SchemaProperties, Tool } from './types.js';
127

138
export function actorNameToToolName(actorName: string): string {
149
return actorName.replace('/', '--');
@@ -59,7 +54,7 @@ export async function getActorDefinition(actorFullName: string): Promise<ActorDe
5954
return null;
6055
} catch (error) {
6156
log.error(`Failed to fetch input schema for actor: ${actorFullName} with error ${error}.`);
62-
return null;
57+
throw new Error(`Failed to fetch input schema for actor: ${actorFullName} with error ${error}.`);
6358
}
6459
}
6560

src/main.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ async function processParamsAndUpdateTools(url: string) {
4545
const input = await processInput(params as unknown as Input);
4646
if (input.actors) {
4747
await mcpServer.addToolsFromActors(input.actors as string[]);
48-
} else {
49-
log.debug(`Server is running in STANDBY mode with the following Actors (tools): ${mcpServer.getToolNames()}.
50-
To use different Actors, provide them in query parameter "actors" or include them in the Actor Task input.`);
5148
}
49+
if (input.enableActorAutoLoading) {
50+
mcpServer.updateTools(getActorAutoLoadingTools());
51+
}
52+
log.debug(`Server is running in STANDBY mode with the following Actors (tools): ${mcpServer.getToolNames()}.
53+
To use different Actors, provide them in query parameter "actors" or include them in the Actor Task input.`);
5254
}
5355

5456
app.route(Routes.ROOT)

src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ export class ApifyMcpServer {
175175
case InternalTools.ADD_ACTOR_TO_TOOLS: {
176176
const parsed = AddActorToToolsArgsSchema.parse(args);
177177
await this.addToolsFromActors([parsed.actorFullName]);
178-
return { content: [{ type: 'text', text: `Actor ${args.name} was added to tools` }] };
178+
return { content: [{ type: 'text', text: `Actor ${parsed.actorFullName} was added to tools` }] };
179179
}
180180
case InternalTools.REMOVE_ACTOR_FROM_TOOLS: {
181181
const parsed = RemoveActorToolArgsSchema.parse(args);
182182
this.tools.delete(parsed.toolName);
183-
return { content: [{ type: 'text', text: `Actor ${args.name} was removed from tools` }] };
183+
return { content: [{ type: 'text', text: `Tool ${parsed.toolName} was removed` }] };
184184
}
185185
case InternalTools.DISCOVER_ACTORS: {
186186
const parsed = DiscoverActorsArgsSchema.parse(args);

src/tools.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ApifyClient } from 'apify-client';
44
import { z } from 'zod';
55
import { zodToJsonSchema } from 'zod-to-json-schema';
66

7-
import { actorNameToToolName, toolNameToActorName } from './actors.js';
7+
import { toolNameToActorName } from './actors.js';
88
import { InternalTools } from './const.js';
99
import type { ActorStorePruned, PricingInfo, Tool } from './types.js';
1010

@@ -35,14 +35,14 @@ export const RemoveActorToolArgsSchema = z.object({
3535
toolName: z.string()
3636
.describe('Full name of the Actor to remove. Actor full name is always composed from `username--name`'
3737
+ 'Never use name or username only')
38-
.transform((val) => actorNameToToolName(val)),
38+
.transform((val) => toolNameToActorName(val)),
3939
});
4040

4141
export const AddActorToToolsArgsSchema = z.object({
4242
actorFullName: z.string()
4343
.describe('Full name of the Actor to add as tool. Tool name is always composed from `username--name`'
4444
+ 'Never use name or username only')
45-
.transform((val) => actorNameToToolName(val)),
45+
.transform((val) => toolNameToActorName(val)),
4646
});
4747

4848
export const GetActorDefinition = z.object({

0 commit comments

Comments
 (0)