Skip to main content
Glama

run_script

Execute JavaScript scripts within LibreSprite to automate pixel art creation and editing tasks through code-based commands.

Instructions

        Run a JavaScript script inside Libresprite.

        IMPORTANT: Make sure you are well versed with the documentation and examples provided in the resources `docs:reference` and `docs:examples`.

        Args:
            script: The script to execute

        Returns:
            Console output
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'run_script', decorated with @self.mcp.tool(), delegates to LibrespriteProxy.
    @self.mcp.tool()
    def run_script(script: str, ctx: Context) -> str:
        """
        Run a JavaScript script inside Libresprite.
    
        IMPORTANT: Make sure you are well versed with the documentation and examples provided in the resources `docs:reference` and `docs:examples`.
    
        Args:
            script: The script to execute
    
        Returns:
            Console output
        """
        return self._libresprite_proxy.run_script(script, ctx)
  • Core logic of run_script in LibrespriteProxy: sets script on Flask endpoint, waits for output from remote JS, returns console output.
    def run_script(self, script: str, ctx: Context) -> str:
        """
        Run a script in the execution context.
    
        WARNING: This method is synchronous and blocking.
    
        Args:
            script: The script to execute
        """
        # This proxy only allows one script to be executed at a time
        if self._lock:
            ctx.error("Script execution is already in progress...")
            raise RuntimeError("Script execution is already in progress.")
    
        # Sending the script
        ctx.info("Sending script to libresprite...")
        self._lock = True
        self._script = script
        self._script_event.set()
    
        # Waiting for execution
        if not self._output_event.wait(timeout=15):
            ctx.warning("This is taking longer than usual, make sure the user has the Libresprite application with the remote script running?")
        self._output_event.wait()
        self._output_event.clear()
    
        # Return the output
        ctx.info("Script execution completed, checking the logs...")
        output = self._output
        self._output = None
        self._lock = False
        return output
  • Remote JS implementation: executes the received script using new Function, captures output via overridden console.log.
    function runScript(script) {
        if (!script) {
            return;
        }
        try {
            // Execute in global scope with our custom logger...
            new Function('console', script)(console);
        } catch (e) {
            console.log('Error in script:', e.message);
        }
    }
  • Registration of the 'run_script' tool via FastMCP decorator in _setup_tools method.
    @self.mcp.tool()
    def run_script(script: str, ctx: Context) -> str:
        """
        Run a JavaScript script inside Libresprite.
    
        IMPORTANT: Make sure you are well versed with the documentation and examples provided in the resources `docs:reference` and `docs:examples`.
    
        Args:
            script: The script to execute
    
        Returns:
            Console output
        """
        return self._libresprite_proxy.run_script(script, ctx)

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Snehil-Shah/libresprite-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server