Skip to content

Commit e368c97

Browse files
authored
fix: calling mcp server when calling wihtout any tool name and add integration test case (#309)
1 parent 356d40e commit e368c97

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/const.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export const SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION = `Skyfire PAY token ID used fo
6565

6666
export const SKYFIRE_README_CONTENT = `The Apify MCP Server allows clients to interact with Apify Actors, storage, and documentation. Before running any Apify Actor, you need to set up a Skyfire PAY token for billing purposes. To set up the PAY token you need to use the create-pay-token tool from the Skyfire MCP server. The PAY token must be charged with a minimum of ${SKYFIRE_MIN_CHARGE_USD} USD to be valid.${SKYFIRE_SELLER_ID ? ` The Skyfire seller ID for Apify MCP server is "${SKYFIRE_SELLER_ID}".` : ''} When running an Actor using the call-actor tool, you must provide the Skyfire PAY token ID in the \`skyfire-pay-id\` input property. Similarly, when retrieving Actor output using the get-actor-output tool, you must also provide the same Skyfire PAY token ID in the \`skyfire-pay-id\` input property.`;
6767

68+
export const CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG = `When calling an MCP server Actor, you must specify the tool name in the actor parameter as "{actorName}:{toolName}" in the "actor" input property.`;
69+
6870
// Cache
6971
export const ACTOR_CACHE_MAX_SIZE = 500;
7072
export const ACTOR_CACHE_TTL_SECS = 30 * 60; // 30 minutes

src/tools/actor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import log from '@apify/log';
88
import { ApifyClient } from '../apify-client.js';
99
import {
1010
ACTOR_MAX_MEMORY_MBYTES,
11+
CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG,
1112
HelperTools,
1213
RAG_WEB_BROWSER,
1314
RAG_WEB_BROWSER_ADDITIONAL_DESC,
@@ -384,8 +385,7 @@ EXAMPLES:
384385
// For definition resolution we always use token-based client; Skyfire is only for actual Actor runs
385386
const apifyClientForDefinition = new ApifyClient({ token: apifyToken });
386387
// Resolve MCP server URL
387-
const needsMcpUrl = mcpToolName !== undefined || performStep === 'info';
388-
const mcpServerUrlOrFalse = needsMcpUrl ? await getActorMcpUrlCached(baseActorName, apifyClientForDefinition) : false;
388+
const mcpServerUrlOrFalse = await getActorMcpUrlCached(baseActorName, apifyClientForDefinition);
389389
const isActorMcpServer = mcpServerUrlOrFalse && typeof mcpServerUrlOrFalse === 'string';
390390

391391
// Standby Actors, thus MCPs, are not supported in Skyfire mode
@@ -465,7 +465,7 @@ EXAMPLES:
465465
// and does not provide the tool name.
466466
const isMcpToolNameInvalid = mcpToolName === undefined || mcpToolName.trim().length === 0;
467467
if (isActorMcpServer && isMcpToolNameInvalid) {
468-
return buildMCPResponse([`When calling an MCP server Actor, you must specify the tool name in the actor parameter as "{actorName}:{toolName}" in the "actor" input property.`]);
468+
return buildMCPResponse([CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG]);
469469
}
470470

471471
// Handle MCP tool calls

tests/integration/suite.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CallToolResultSchema, ToolListChangedNotificationSchema } from '@modelc
44
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
55

66
import { ApifyClient } from '../../src/apify-client.js';
7-
import { defaults, HelperTools } from '../../src/const.js';
7+
import { CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG, defaults, HelperTools } from '../../src/const.js';
88
import { addTool } from '../../src/tools/helpers.js';
99
import { defaultTools, toolCategories } from '../../src/tools/index.js';
1010
import { actorNameToToolName } from '../../src/tools/utils.js';
@@ -989,5 +989,25 @@ export function createIntegrationTestsSuite(
989989

990990
await client.close();
991991
});
992+
993+
it.only('should return error message when tryging to call MCP server Actor without tool name in actor parameter', async () => {
994+
client = await createClientFn({ tools: ['actors'] });
995+
996+
const response = await client.callTool({
997+
name: 'call-actor',
998+
arguments: {
999+
actor: ACTOR_MCP_SERVER_ACTOR_NAME,
1000+
step: 'call',
1001+
input: { url: 'https://docs.apify.com' },
1002+
},
1003+
});
1004+
1005+
expect(response.content).toBeDefined();
1006+
const content = response.content as { text: string }[];
1007+
expect(content.length).toBeGreaterThan(0);
1008+
expect(content[0].text).toContain(CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG);
1009+
1010+
await client.close();
1011+
});
9921012
});
9931013
}

0 commit comments

Comments
 (0)