Skip to main content
Glama
webflow

Webflow

Official
by webflow

add_inline_site_script

Add custom inline scripts to Webflow sites for header or footer placement, enabling functionality like analytics or custom interactions within character limits.

Instructions

Register an inline script for a site. Inline scripts are limited to 2000 characters.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
site_idYesUnique identifier for the site.
requestYesRequest schema to register an inline script for a site.

Implementation Reference

  • Handler function that registers an inline script with Webflow API, fetches existing scripts, adds the new one with location mapping, upserts custom code, and returns the registration response.
    async ({ site_id, request }) => {
      const registerScriptResponse = await getClient().scripts.registerInline(
        site_id,
        {
          sourceCode: request.sourceCode,
          version: request.version,
          displayName: request.displayName,
          canCopy: request.canCopy !== undefined ? request.canCopy : true,
        },
        requestOptions
      );
    
      let existingScripts: any[] = [];
      try {
        const allScriptsResponse =
          await getClient().sites.scripts.getCustomCode(
            site_id,
            requestOptions
          );
        existingScripts = allScriptsResponse.scripts || [];
      } catch (error) {
        formatErrorResponse(error);
        existingScripts = [];
      }
    
      const newScript = {
        id: registerScriptResponse.id ?? " ",
        location:
          request.location === "footer"
            ? ScriptApplyLocation.Footer
            : ScriptApplyLocation.Header,
        version: registerScriptResponse.version ?? " ",
        attributes: request.attributes,
      };
    
      existingScripts.push(newScript);
    
      const addedSiteCustomCoderesponse =
        await getClient().sites.scripts.upsertCustomCode(
          site_id,
          {
            scripts: existingScripts,
          },
          requestOptions
        );
    
      return formatResponse(registerScriptResponse);
    }
  • Zod input schema for the add_inline_site_script tool, defining fields like sourceCode, version, displayName, location, etc.
    export const RegisterInlineSiteScriptSchema = z
      .object({
        sourceCode: z
          .string()
          .describe(
            "The inline script source code (hosted by Webflow). Inline scripts are limited to 2000 characters."
          ),
        version: z
          .string()
          .describe(
            "A Semantic Version (SemVer) string, denoting the version of the script."
          ),
        canCopy: z
          .boolean()
          .optional()
          .describe(
            "Indicates whether the script can be copied on site duplication and transfer."
          ),
        displayName: z
          .string()
          .describe(
            "User-facing name for the script. Must be between 1 and 50 alphanumeric characters."
          ),
        location: z
          .string()
          .optional()
          .describe(
            'Location where the script is applied. Allowed values: "header", "footer".'
          ),
        attributes: z
          .record(z.any())
          .optional()
          .describe(
            "Developer-specified key/value pairs to be applied as attributes to the script."
          ),
      })
      .describe("Request schema to register an inline script for a site.");
  • Tool registration call for 'add_inline_site_script' with title, description, input schema (including site_id and request schema), and handler reference.
      "add_inline_site_script",
      {
        title: "Add Inline Site Script",
        description:
          "Register an inline script for a site. Inline scripts are limited to 2000 characters. ",
        inputSchema: z.object({
          site_id: z.string().describe("Unique identifier for the site."),
          request: RegisterInlineSiteScriptSchema,
        }),
      },
      async ({ site_id, request }) => {
        const registerScriptResponse = await getClient().scripts.registerInline(
          site_id,
          {
            sourceCode: request.sourceCode,
            version: request.version,
            displayName: request.displayName,
            canCopy: request.canCopy !== undefined ? request.canCopy : true,
          },
          requestOptions
        );
    
        let existingScripts: any[] = [];
        try {
          const allScriptsResponse =
            await getClient().sites.scripts.getCustomCode(
              site_id,
              requestOptions
            );
          existingScripts = allScriptsResponse.scripts || [];
        } catch (error) {
          formatErrorResponse(error);
          existingScripts = [];
        }
    
        const newScript = {
          id: registerScriptResponse.id ?? " ",
          location:
            request.location === "footer"
              ? ScriptApplyLocation.Footer
              : ScriptApplyLocation.Header,
          version: registerScriptResponse.version ?? " ",
          attributes: request.attributes,
        };
    
        existingScripts.push(newScript);
    
        const addedSiteCustomCoderesponse =
          await getClient().sites.scripts.upsertCustomCode(
            site_id,
            {
              scripts: existingScripts,
            },
            requestOptions
          );
    
        return formatResponse(registerScriptResponse);
      }
    );

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/webflow/mcp-server'

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