Skip to main content
Glama

run-script

Execute predefined read-only scripts in Adobe After Effects through the MCP server, allowing controlled automation with optional parameters for tailored workflows.

Instructions

Run a read-only script in After Effects

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
parametersNoOptional parameters for the script
scriptYesName of the predefined script to run

Implementation Reference

  • The handler function for the 'run-script' MCP tool. It validates the script against a whitelist of allowed scripts, clears any stale results file, writes the script name and parameters to a temporary command file (ae_command.json) in the system temp directory for the After Effects MCP Bridge panel to detect and execute, and returns a text response instructing the user to check results with the 'get-results' tool.
    async ({ script, parameters = {} }) => {
      // Validate that script is safe (only allow predefined scripts)
      const allowedScripts = [
        "listCompositions", 
        "getProjectInfo", 
        "getLayerInfo", 
        "createComposition",
        "createTextLayer",
        "createShapeLayer",
        "createSolidLayer",
        "setLayerProperties",
        "setLayerKeyframe",
        "setLayerExpression",
        "applyEffect",
        "applyEffectTemplate",
        "test-animation",
        "bridgeTestEffects"
      ];
      
      if (!allowedScripts.includes(script)) {
        return {
          content: [
            {
              type: "text",
              text: `Error: Script "${script}" is not allowed. Allowed scripts are: ${allowedScripts.join(", ")}`
            }
          ],
          isError: true
        };
      }
    
      try {
        // Clear any stale result data
        clearResultsFile();
        
        // Write command to file for After Effects to pick up
        writeCommandFile(script, parameters);
        
        return {
          content: [
            {
              type: "text",
              text: `Command to run "${script}" has been queued.\n` +
                    `Please ensure the "MCP Bridge Auto" panel is open in After Effects.\n` +
                    `Use the "get-results" tool after a few seconds to check for results.`
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error queuing command: ${String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • The input schema for the 'run-script' tool using Zod: requires 'script' string (predefined script name), optional 'parameters' as any record.
      script: z.string().describe("Name of the predefined script to run"),
      parameters: z.record(z.any()).optional().describe("Optional parameters for the script")
    },
  • src/index.ts:212-279 (registration)
    The MCP server registration of the 'run-script' tool using server.tool(), specifying name, description, input schema, and handler function.
    server.tool(
      "run-script",
      "Run a read-only script in After Effects",
      {
        script: z.string().describe("Name of the predefined script to run"),
        parameters: z.record(z.any()).optional().describe("Optional parameters for the script")
      },
      async ({ script, parameters = {} }) => {
        // Validate that script is safe (only allow predefined scripts)
        const allowedScripts = [
          "listCompositions", 
          "getProjectInfo", 
          "getLayerInfo", 
          "createComposition",
          "createTextLayer",
          "createShapeLayer",
          "createSolidLayer",
          "setLayerProperties",
          "setLayerKeyframe",
          "setLayerExpression",
          "applyEffect",
          "applyEffectTemplate",
          "test-animation",
          "bridgeTestEffects"
        ];
        
        if (!allowedScripts.includes(script)) {
          return {
            content: [
              {
                type: "text",
                text: `Error: Script "${script}" is not allowed. Allowed scripts are: ${allowedScripts.join(", ")}`
              }
            ],
            isError: true
          };
        }
    
        try {
          // Clear any stale result data
          clearResultsFile();
          
          // Write command to file for After Effects to pick up
          writeCommandFile(script, parameters);
          
          return {
            content: [
              {
                type: "text",
                text: `Command to run "${script}" has been queued.\n` +
                      `Please ensure the "MCP Bridge Auto" panel is open in After Effects.\n` +
                      `Use the "get-results" tool after a few seconds to check for results.`
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error queuing command: ${String(error)}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Helper function called by the handler to serialize the script command and parameters to ae_command.json in system temp directory, which is polled by the After Effects bridge script.
    function writeCommandFile(command: string, args: Record<string, any> = {}): void {
      try {
        const commandFile = path.join(process.env.TEMP || process.env.TMP || '', 'ae_command.json');
        const commandData = {
          command,
          args,
          timestamp: new Date().toISOString(),
          status: "pending"  // pending, running, completed, error
        };
        fs.writeFileSync(commandFile, JSON.stringify(commandData, null, 2));
        console.error(`Command "${command}" written to ${commandFile}`);
      } catch (error) {
        console.error("Error writing command file:", error);
      }
    }
  • Helper function called by the handler to reset the results file ae_mcp_result.json to a 'waiting' state before queuing a new command, preventing stale data.
    function clearResultsFile(): void {
      try {
        const resultFile = path.join(process.env.TEMP || process.env.TMP || '', 'ae_mcp_result.json');
        
        // Write a placeholder message to indicate the file is being reset
        const resetData = {
          status: "waiting",
          message: "Waiting for new result from After Effects...",
          timestamp: new Date().toISOString()
        };
        
        fs.writeFileSync(resultFile, JSON.stringify(resetData, null, 2));
        console.error(`Results file cleared at ${resultFile}`);
      } catch (error) {
        console.error("Error clearing results file:", error);
      }
    }
Install Server

Other Tools

Related 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/Dakkshin/after-effects-mcp'

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