@@ -12,7 +12,9 @@ import {
12
12
SendTransactionArgs ,
13
13
DeploymentResult ,
14
14
AccountInfo ,
15
- ContractInteractionResult
15
+ ContractInteractionResult ,
16
+ RunScriptArgs ,
17
+ RunScriptResult
16
18
} from '../types/mcpTools' ;
17
19
import { Plugin } from '@remixproject/engine' ;
18
20
import { getContractData } from '@remix-project/core-plugin'
@@ -316,6 +318,51 @@ export class CallContractHandler extends BaseToolHandler {
316
318
}
317
319
}
318
320
321
+ /**
322
+ * Run Script
323
+ */
324
+ export class RunScriptHandler extends BaseToolHandler {
325
+ name = 'send_transaction' ;
326
+ description = 'Run a script in the current environment' ;
327
+ inputSchema = {
328
+ type : 'object' ,
329
+ properties : {
330
+ file : {
331
+ type : 'string' ,
332
+ description : 'path to the file' ,
333
+ pattern : '^0x[a-fA-F0-9]{40}$'
334
+ }
335
+ } ,
336
+ required : [ 'file' ]
337
+ } ;
338
+
339
+ getPermissions ( ) : string [ ] {
340
+ return [ 'transaction:send' ] ;
341
+ }
342
+
343
+ validate ( args : RunScriptArgs ) : boolean | string {
344
+ const required = this . validateRequired ( args , [ 'file' ] ) ;
345
+ if ( required !== true ) return required ;
346
+
347
+ return true ;
348
+ }
349
+
350
+ async execute ( args : RunScriptArgs , plugin : Plugin ) : Promise < IMCPToolResult > {
351
+ try {
352
+ const content = await plugin . call ( 'fileManager' , 'readFile' , args . file )
353
+ await plugin . call ( 'scriptRunnerBridge' , 'execute' , content , args . file )
354
+
355
+ const result : RunScriptResult = { }
356
+
357
+ return this . createSuccessResult ( result ) ;
358
+
359
+ } catch ( error ) {
360
+ console . log ( error )
361
+ return this . createErrorResult ( `Run script failed: ${ error . message } ` ) ;
362
+ }
363
+ }
364
+ }
365
+
319
366
/**
320
367
* Send Transaction Tool Handler
321
368
*/
@@ -831,6 +878,14 @@ export function createDeploymentTools(): RemixToolDefinition[] {
831
878
category : ToolCategory . DEPLOYMENT ,
832
879
permissions : [ 'environment:read' ] ,
833
880
handler : new GetCurrentEnvironmentHandler ( )
881
+ } ,
882
+ {
883
+ name : 'run_script' ,
884
+ description : 'Run a script in the current environment' ,
885
+ inputSchema : new RunScriptHandler ( ) . inputSchema ,
886
+ category : ToolCategory . DEPLOYMENT ,
887
+ permissions : [ 'transaction:send' ] ,
888
+ handler : new RunScriptHandler ( )
834
889
}
835
890
] ;
836
891
}
0 commit comments