@@ -21,7 +21,7 @@ import {
2121 SetLevelRequestSchema ,
2222} from '@modelcontextprotocol/sdk/types.js' ;
2323import type { ValidateFunction } from 'ajv' ;
24- import { type ActorCallOptions , ApifyApiError } from 'apify-client' ;
24+ import { type ActorCallOptions } from 'apify-client' ;
2525
2626import log from '@apify/log' ;
2727
@@ -39,6 +39,7 @@ import { callActorGetDataset, defaultTools, getActorsAsTools, toolCategories } f
3939import { decodeDotPropertyNames } from '../tools/utils.js' ;
4040import type { ActorMcpTool , ActorTool , HelperTool , ToolEntry } from '../types.js' ;
4141import { buildActorResponseContent } from '../utils/actor-response.js' ;
42+ import { buildMCPResponse } from '../utils/mcp.js' ;
4243import { createProgressTracker } from '../utils/progress.js' ;
4344import { getToolPublicFieldOnly } from '../utils/tools.js' ;
4445import { connectMCPClient } from './client.js' ;
@@ -654,19 +655,11 @@ export class ActorsMcpServer {
654655 }
655656 }
656657 } catch ( error ) {
657- if ( error instanceof ApifyApiError ) {
658- log . error ( 'Apify API error calling tool' , { toolName : name , error } ) ;
659- return {
660- content : [
661- { type : 'text' , text : `Apify API error calling tool ${ name } : ${ error . message } ` } ,
662- ] ,
663- } ;
664- }
665- log . error ( 'Error calling tool' , { toolName : name , error } ) ;
666- throw new McpError (
667- ErrorCode . InternalError ,
668- `An error occurred while calling the tool.` ,
669- ) ;
658+ log . error ( 'Error occurred while calling tool' , { toolName : name , error } ) ;
659+ const errorMessage = ( error instanceof Error ) ? error . message : 'Unknown error' ;
660+ return buildMCPResponse ( [
661+ `Error calling tool ${ name } : ${ errorMessage } ` ,
662+ ] ) ;
670663 }
671664
672665 const msg = `Unknown tool: ${ name } ` ;
0 commit comments