Skip to content

Commit 9c5af46

Browse files
committed
fix: simplify error handling and return the error message for all errors
1 parent e479103 commit 9c5af46

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/mcp/server.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { getToolPublicFieldOnly } from '../utils/tools.js';
4444
import { connectMCPClient } from './client.js';
4545
import { EXTERNAL_TOOL_CALL_TIMEOUT_MSEC, LOG_LEVEL_MAP } from './const.js';
4646
import { processParamsGetTools } from './utils.js';
47+
import { buildMCPResponse } from '../utils/mcp.js';
4748

4849
type ToolsChangedHandler = (toolNames: string[]) => void;
4950

@@ -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

Comments
 (0)