File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,19 @@ export const addTool: ToolEntry = {
6060 } ;
6161 }
6262 const tools = await getActorsAsTools ( [ parsed . actor ] , apifyToken ) ;
63+ /**
64+ * If no tools were found, return a message that the Actor was not found
65+ * instead of returning that non existent tool was added since the
66+ * getActorsAsTools function returns an empty array and does not throw an error.
67+ */
68+ if ( tools . length === 0 ) {
69+ return {
70+ content : [ {
71+ type : 'text' ,
72+ text : `Actor ${ parsed . actor } not found, no tools were added.` ,
73+ } ] ,
74+ } ;
75+ }
6376 const toolsAdded = apifyMcpServer . upsertTools ( tools , true ) ;
6477 await sendNotification ( { method : 'notifications/tools/list_changed' } ) ;
6578
Original file line number Diff line number Diff line change @@ -312,6 +312,20 @@ export function createIntegrationTestsSuite(
312312 await client . close ( ) ;
313313 } ) ;
314314
315+ it ( 'should return no tools were added when adding a non-existent actor' , async ( ) => {
316+ const client = await createClientFn ( { enableAddingActors : true } ) ;
317+ const nonExistentActor = 'apify/this-actor-does-not-exist' ;
318+ const result = await client . callTool ( {
319+ name : HelperTools . ACTOR_ADD ,
320+ arguments : { actor : nonExistentActor } ,
321+ } ) ;
322+ expect ( result ) . toBeDefined ( ) ;
323+ const content = result . content as { text : string } [ ] ;
324+ expect ( content . length ) . toBeGreaterThan ( 0 ) ;
325+ expect ( content [ 0 ] . text ) . toContain ( 'no tools were added' ) ;
326+ await client . close ( ) ;
327+ } ) ;
328+
315329 it ( 'should be able to add and call Actorized MCP server' , async ( ) => {
316330 const client = await createClientFn ( { enableAddingActors : true } ) ;
317331
You can’t perform that action at this time.
0 commit comments