@@ -12,7 +12,9 @@ import {
1212 SendTransactionArgs ,
1313 DeploymentResult ,
1414 AccountInfo ,
15- ContractInteractionResult
15+ ContractInteractionResult ,
16+ RunScriptArgs ,
17+ RunScriptResult
1618} from '../types/mcpTools' ;
1719import { Plugin } from '@remixproject/engine' ;
1820import { getContractData } from '@remix-project/core-plugin'
@@ -316,6 +318,51 @@ export class CallContractHandler extends BaseToolHandler {
316318 }
317319}
318320
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+
319366/**
320367 * Send Transaction Tool Handler
321368 */
@@ -831,6 +878,14 @@ export function createDeploymentTools(): RemixToolDefinition[] {
831878 category : ToolCategory . DEPLOYMENT ,
832879 permissions : [ 'environment:read' ] ,
833880 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 ( )
834889 }
835890 ] ;
836891}
0 commit comments