Skip to content

Commit cb17b39

Browse files
committed
fix actorNameToToolName
1 parent df5d7f8 commit cb17b39

File tree

5 files changed

+14
-36
lines changed

5 files changed

+14
-36
lines changed

src/actors.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ import type { ActorDefinitionPruned, ActorDefinitionWithDesc, SchemaProperties,
88
export function actorNameToToolName(actorName: string): string {
99
return actorName
1010
.replace(/\//g, '-slash-')
11-
.replace(/\./g, '-dot-');
12-
}
13-
14-
export function toolNameToActorName(toolName: string): string {
15-
return toolName
16-
.replace(/-slash-/g, '/')
17-
.replace(/-dot-/g, '.');
11+
.replace(/\./g, '-dot-')
12+
.slice(0, 64);
1813
}
1914

2015
/**

src/input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function processInput(originalInput: Partial<Input>): Promise<Input
1313
input.actors = input.actors.split(',').map((format: string) => format.trim()) as string[];
1414
}
1515
if (!input.enableActorAutoLoading) {
16-
input.enableActorAutoLoading = true;
16+
input.enableActorAutoLoading = false;
1717
}
1818
return input;
1919
}

src/server.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ import { ApifyClient } from 'apify-client';
1212
import type { AxiosRequestConfig } from 'axios';
1313

1414
import {
15-
actorNameToToolName,
1615
filterSchemaProperties,
1716
getActorDefinition,
1817
getActorsAsTools,
1918
shortenProperties,
20-
toolNameToActorName,
2119
} from './actors.js';
2220
import {
2321
ACTOR_OUTPUT_MAX_CHARS_PER_ITEM,
@@ -91,7 +89,7 @@ export class ApifyMcpServer {
9189
input: unknown,
9290
callOptions: ActorCallOptions | undefined = undefined,
9391
): Promise<object[]> {
94-
const name = toolNameToActorName(actorName);
92+
const name = actorName;
9593
try {
9694
log.info(`Calling actor ${name} with input: ${JSON.stringify(input)}`);
9795

@@ -162,8 +160,7 @@ export class ApifyMcpServer {
162160
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
163161
const { name, arguments: args } = request.params;
164162

165-
// Anthropic can't handle '/' in tool names. The replace is only necessary when calling the tool from stdio clients.
166-
const tool = this.tools.get(name) || this.tools.get(actorNameToToolName(name));
163+
const tool = Array.from(this.tools.values()).find((t) => t.name === name || t.actorFullName === name);
167164
if (!tool) {
168165
throw new Error(`Unknown tool: ${name}`);
169166
}

src/tools.ts

Lines changed: 4 additions & 5 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 { actorNameToToolName } from './actors.js';
88
import { ACTOR_README_MAX_LENGTH, InternalTools } from './const.js';
99
import type { ActorStorePruned, PricingInfo, Tool } from './types.js';
1010

@@ -39,15 +39,14 @@ export const RemoveActorToolArgsSchema = z.object({
3939

4040
export const AddActorToToolsArgsSchema = z.object({
4141
actorName: z.string()
42-
.describe('Add an Actor to available tools by Actor ID or Actor name.')
43-
.transform((val) => toolNameToActorName(val)),
42+
.describe('Add an Actor to available tools by Actor ID or Actor full name.'
43+
+ 'Actor name is always composed from `username/name`'),
4444
});
4545

4646
export const GetActorDefinition = z.object({
4747
actorName: z.string()
4848
.describe('Retrieve input, readme, and other details for Actor ID or Actor full name. '
49-
+ 'Actor name is always composed from `username/name`')
50-
.transform((val) => toolNameToActorName(val)),
49+
+ 'Actor name is always composed from `username/name`'),
5150
limit: z.number()
5251
.int()
5352
.default(ACTOR_README_MAX_LENGTH)

tests/actors-test.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from 'vitest';
22

3-
import { actorNameToToolName, toolNameToActorName } from '../src/actors.js';
3+
import { actorNameToToolName } from '../src/actors.js';
44

55
describe('actors', () => {
66
describe('actorNameToToolName', () => {
@@ -20,24 +20,11 @@ describe('actors', () => {
2020
it('should handle strings with multiple slashes and dots', () => {
2121
expect(actorNameToToolName('actor/name.with/multiple.parts')).toBe('actor-slash-name-dot-with-slash-multiple-dot-parts');
2222
});
23-
});
24-
25-
describe('toolNameToActorName', () => {
26-
it('should convert dash notation back to slashes and dots', () => {
27-
expect(toolNameToActorName('apify-slash-web-scraper')).toBe('apify/web-scraper');
28-
expect(toolNameToActorName('my-dot-actor-dot-name')).toBe('my.actor.name');
29-
});
30-
31-
it('should handle empty strings', () => {
32-
expect(toolNameToActorName('')).toBe('');
33-
});
34-
35-
it('should handle strings without dash notation', () => {
36-
expect(toolNameToActorName('actorname')).toBe('actorname');
37-
});
3823

39-
it('should handle strings with multiple dash notations', () => {
40-
expect(toolNameToActorName('actor-slash-name-dot-with-slash-multiple-dot-parts')).toBe('actor/name.with/multiple.parts');
24+
it('should handle tool names longer than 64 characters', () => {
25+
const longName = 'a'.repeat(70);
26+
const expected = 'a'.repeat(64);
27+
expect(actorNameToToolName(longName)).toBe(expected);
4128
});
4229
});
4330
});

0 commit comments

Comments
 (0)