run_script
Execute JavaScript scripts in LibreSprite to automate pixel art creation and retrieve console output.
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
| Name | Required | Description | Default |
|---|---|---|---|
| script | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/libresprite_mcp/mcp_server.py:28-41 (registration)Registers the 'run_script' tool via the FastMCP 'tool' decorator. This is where the tool is declared as an MCP tool with its name, schema (script: str), and handler delegation.
@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) - src/libresprite_mcp/mcp_server.py:28-41 (handler)Handler function that receives the script string and context, delegates execution to the proxy's run_script 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) - Helper/proxy method that sends the script via an HTTP relay server (Flask), blocks waiting for the output from the remote Libresprite instance, and returns the result.
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