11import  {  FastMCP  }  from  'fastmcp/dist/FastMCP.js' ; 
2- import  {  getDriver  }  from  '../sessionStore.js' ; 
32import  {  z  }  from  'zod' ; 
3+ import  {  getDriver ,  getPlatformName  }  from  '../sessionStore.js' ; 
44
55export  default  function  terminateApp ( server : FastMCP ) : void { 
6-   const  terminateAppSchema  =  z . object ( { 
7-     id : z . string ( ) . describe ( 'The app id' ) , 
6+   const  schema  =  z . object ( { 
7+     id : z 
8+       . string ( ) 
9+       . describe ( 'App identifier (package name for Android, bundle ID for iOS)' ) , 
810  } ) ; 
911
1012  server . addTool ( { 
11-     name : 'appium_terminate_app' , 
12-     description : 'Terminate app by id' , 
13-     parameters : terminateAppSchema , 
14-     annotations : { 
15-       readOnlyHint : false , 
16-       openWorldHint : false , 
17-     } , 
18-     execute : async  ( args : {  id : string  } ,  context : any ) : Promise < any >  =>  { 
19-       const  driver  =  getDriver ( ) ; 
13+     name : 'appium_terminateApp' , 
14+     description : 'Terminate an app on the device.' , 
15+     parameters : schema , 
16+     execute : async  ( args : z . infer < typeof  schema > )  =>  { 
17+       const  {  id }  =  args ; 
18+       const  driver  =  await  getDriver ( ) ; 
2019      if  ( ! driver )  { 
2120        throw  new  Error ( 'No driver found' ) ; 
2221      } 
23- 
2422      try  { 
25-         await  driver . terminateApp ( args . id ) ; 
23+         const  platform  =  getPlatformName ( driver ) ; 
24+         const  params  = 
25+           platform  ===  'Android'  ? {  appId : id  }  : {  bundleId : id  } ; 
26+         await  ( driver  as  any ) . execute ( 'mobile: terminateApp' ,  params ) ; 
2627        return  { 
2728          content : [ 
2829            { 
2930              type : 'text' , 
30-               text : ` App ${ args . id }   terminated correctly.` , 
31+               text : ' App terminated successfully' , 
3132            } , 
3233          ] , 
3334        } ; 
@@ -36,11 +37,11 @@ export default function terminateApp(server: FastMCP): void {
3637          content : [ 
3738            { 
3839              type : 'text' , 
39-               text : `Error terminating the  app  ${ args . id } ${ err . toString ( ) }  , 
40+               text : `Failed to terminate  app. err : ${ err . toString ( ) }  , 
4041            } , 
4142          ] , 
4243        } ; 
4344      } 
4445    } , 
4546  } ) ; 
46- } 
47+ } 
0 commit comments