File tree Expand file tree Collapse file tree
x-pack/platform/plugins/shared/agent_builder/server/services/tools/tool_types/mcp Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -273,6 +273,36 @@ describe('MCP tool_type', () => {
273273 } ) ;
274274 } ) ;
275275
276+ it ( 'should prefer serviceMessage over message when connector execution returns error status' , async ( ) => {
277+ const toolType = getMcpToolType ( { actions : mockActions } ) ;
278+ const dynamicProps = await toolType . getDynamicProps ( testConfig , {
279+ request : mockRequest ,
280+ spaceId : 'default' ,
281+ } ) ;
282+
283+ mockActionsClient . execute . mockResolvedValue ( {
284+ status : 'error' ,
285+ message : 'an error occurred while running the action' ,
286+ serviceMessage : 'redacted upstream tool error' ,
287+ } ) ;
288+
289+ const handler = await dynamicProps . getHandler ( ) ;
290+ const result = await handler ( { } , {
291+ logger : mockLogger ,
292+ } as any ) ;
293+
294+ expect ( result ) . toEqual ( {
295+ results : [
296+ {
297+ type : ToolResultType . error ,
298+ data : {
299+ message : 'redacted upstream tool error' ,
300+ } ,
301+ } ,
302+ ] ,
303+ } ) ;
304+ } ) ;
305+
276306 it ( 'should return error result with default message when connector error has no message' , async ( ) => {
277307 const toolType = getMcpToolType ( { actions : mockActions } ) ;
278308 const dynamicProps = await toolType . getDynamicProps ( testConfig , {
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ async function executeMcpTool({
145145 if ( result . status === 'error' ) {
146146 return {
147147 isError : true ,
148- content : result . message || 'MCP tool execution failed' ,
148+ content : result . serviceMessage ?? result . message ?? 'MCP tool execution failed' ,
149149 } ;
150150 }
151151
You can’t perform that action at this time.
0 commit comments