Skip to main content
Glama
hostinger

hostinger-api-mcp

Official

hosting_deployWordpressTheme

Upload a WordPress theme from a local directory to your hosting server and optionally activate it after deployment.

Instructions

Deploy a WordPress theme from a directory to a hosting server. This tool uploads all theme files and triggers theme deployment. The uploaded theme can optionally be activated after deployment.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
domainYesDomain name associated with the hosting account (e.g., example.com)
slugYesWordPress theme slug (e.g., twentytwentyfive)
themePathYesAbsolute or relative path to the theme directory containing all theme files
activateNoWhether to activate the theme after deployment (default: false)

Implementation Reference

  • Schema/definition for the hosting_deployWordpressTheme tool. Defines the tool with name, description, inputSchema (domain, slug, themePath, activate), and references handlerMethod 'handleWordpressThemeDeploy'.
    {
      "name": "hosting_deployWordpressTheme",
      "topic": "hosting",
      "description": "Deploy a WordPress theme from a directory to a hosting server. This tool uploads all theme files and triggers theme deployment. The uploaded theme can optionally be activated after deployment.",
      "method": "",
      "path": "",
      "inputSchema": {
        "type": "object",
        "properties": {
          "domain": {
            "type": "string",
            "description": "Domain name associated with the hosting account (e.g., example.com)"
          },
          "slug": {
            "type": "string",
            "description": "WordPress theme slug (e.g., twentytwentyfive)"
          },
          "themePath": {
            "type": "string",
            "description": "Absolute or relative path to the theme directory containing all theme files"
          },
          "activate": {
            "type": "boolean",
            "description": "Whether to activate the theme after deployment (default: false)"
          }
        },
        "required": [
          "domain",
          "slug",
          "themePath"
        ]
      },
      "security": [],
      "custom": true,
      "templateFile": "deploy-wordpress-theme.template.js",
      "templateFileTS": "deploy-wordpress-theme.template.ts",
      "handlerMethod": "handleWordpressThemeDeploy",
      "group": "hosting"
    },
  • Main handler function for hosting_deployWordpressTheme. Validates params, resolves username from domain, generates a unique upload dir name, scans the theme directory, uploads all files via TUS to wp-content/themes/, and finally triggers theme deployment via the Hostinger API with optional activation.
    private async handleWordpressThemeDeploy(params: Record<string, any>): Promise<any> {
      const { domain, slug, themePath, activate = false } = params;
    
      this.hosting_deployWordpressTheme_validateRequiredParams(params);
      this.hosting_deployWordpressTheme_validateThemeDirectory(themePath);
    
      this.log('info', `Resolving username from domain: ${domain}`);
      const username = await this.resolveUsername(domain);
    
      const randomSuffix = this.hosting_deployWordpressTheme_generateRandomString(8);
      const uploadDirName = `${slug}-${randomSuffix}`;
    
      this.log('info', `Scanning theme directory: ${themePath}`);
      const themeFiles = this.hosting_deployWordpressTheme_scanDirectory(themePath);
    
      if (themeFiles.length === 0) {
        throw new Error(`No files found in theme directory: ${themePath}`);
      }
    
      this.log('info', `Found ${themeFiles.length} files to upload`);
    
      let uploadCredentials: any;
      try {
        uploadCredentials = await this.fetchUploadCredentials(username, domain);
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        throw new Error(`Failed to fetch upload credentials: ${errorMessage}`);
      }
    
      const { url: uploadUrl, auth_key: authToken, rest_auth_key: authRestToken } = uploadCredentials;
    
      if (!uploadUrl || !authToken || !authRestToken) {
        throw new Error('Invalid upload credentials received from API');
      }
    
      this.log('info', `Starting theme file upload to ${uploadUrl}`);
    
      const results: any[] = [];
      let successCount = 0;
      let failureCount = 0;
    
      for (const fileInfo of themeFiles) {
        try {
          const normalizedRelativePath = this.normalizePath(fileInfo.relativePath);
          const uploadPath = `wp-content/themes/${uploadDirName}/${normalizedRelativePath}`;
          this.log('info', `Uploading: ${fileInfo.absolutePath} -> ${uploadPath}`);
    
          const stats = fs.statSync(fileInfo.absolutePath);
          const uploadResult = await this.uploadFile(
            fileInfo.absolutePath,
            uploadPath,
            uploadUrl,
            authRestToken,
            authToken
          );
    
          results.push({
            file: fileInfo.absolutePath,
            remotePath: uploadPath,
            status: 'success',
            uploadUrl: uploadResult.url,
            size: stats.size
          });
    
          successCount++;
          this.log('info', `Successfully uploaded: ${uploadPath}`);
    
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          const normalizedRelativePath = this.normalizePath(fileInfo.relativePath);
          const uploadPath = `wp-content/themes/${uploadDirName}/${normalizedRelativePath}`;
          
          results.push({
            file: fileInfo.absolutePath,
            remotePath: uploadPath,
            status: 'error',
            error: errorMessage
          });
    
          failureCount++;
          this.log('error', `Failed to upload ${fileInfo.absolutePath}: ${errorMessage}`);
        }
      }
    
      const overallStatus = failureCount === 0 ? 'success' : (successCount === 0 ? 'failure' : 'partial');
    
      if (failureCount === 0) {
        try {
          this.log('info', 'All files uploaded successfully, triggering theme deployment...');
          await this.hosting_deployWordpressTheme_deployTheme(username, domain, slug, uploadDirName, activate);
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          this.log('error', `Theme deployment failed: ${errorMessage}`);
          return {
            status: 'partial',
            summary: {
              total: themeFiles.length,
              successful: successCount,
              failed: failureCount
            },
            results,
            deploymentError: errorMessage
          };
        }
      }
    
      return {
        status: overallStatus,
        summary: {
          total: themeFiles.length,
          successful: successCount,
          failed: failureCount
        },
        results,
        uploadDirName,
        activated: activate
      };
    }
  • Registration of hosting_deployWordpressTheme in the executeCustomTool switch statement, routing tool name to the handleWordpressThemeDeploy handler.
    private async executeCustomTool(tool: OpenApiTool, params: Record<string, any>): Promise<any> {
      switch (tool.name) {
        case 'hosting_importWordpressWebsite':
          return await this.handleWordpressWebsiteImport(params);
        case 'hosting_deployWordpressPlugin':
          return await this.handleWordpressPluginDeploy(params);
        case 'hosting_deployWordpressTheme':
          return await this.handleWordpressThemeDeploy(params);
        case 'hosting_deployJsApplication':
          return await this.handleJavascriptApplicationDeploy(params);
        case 'hosting_deployStaticWebsite':
          return await this.handleStaticWebsiteDeploy(params);
        case 'hosting_listJsDeployments':
          return await this.handleListJavascriptDeployments(params);
        case 'hosting_showJsDeploymentLogs':
          return await this.handleShowJsDeploymentLogs(params);
        default:
          throw new Error(`Unknown custom tool: ${tool.name}`);
      }
    }
  • Helper that recursively scans a theme directory, returning all files with their absolute and relative paths.
    private hosting_deployWordpressTheme_scanDirectory(dirPath: string, basePath: string = dirPath): Array<{absolutePath: string, relativePath: string}> {
      const files: Array<{absolutePath: string, relativePath: string}> = [];
      
      const scanDir = (currentPath: string) => {
        const items = fs.readdirSync(currentPath);
        
        for (const item of items) {
          const itemPath = path.join(currentPath, item);
          const stats = fs.statSync(itemPath);
          
          if (stats.isDirectory()) {
            scanDir(itemPath);
          } else if (stats.isFile()) {
            const relativePath = path.relative(basePath, itemPath);
            files.push({
              absolutePath: itemPath,
              relativePath: relativePath
            });
          }
        }
      };
      
      scanDir(dirPath);
      return files;
    }
  • Helper that calls the Hostinger API endpoint POST /api/hosting/v1/accounts/{username}/websites/{domain}/wordpress/themes/deploy to trigger the theme deployment with optional activation (is_activated).
    private async hosting_deployWordpressTheme_deployTheme(username: string, domain: string, slug: string, themePath: string, activate: boolean = false): Promise<boolean> {
      const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
      const url = new URL(`api/hosting/v1/accounts/${username}/websites/${domain}/wordpress/themes/deploy`, baseUrl).toString();
    
      try {
        const bearerToken = process.env['API_TOKEN'] || process.env['APITOKEN'];
        if (!bearerToken) {
          throw new Error('API_TOKEN environment variable not found');
        }
    
        const config: AxiosRequestConfig = {
          method: 'post',
          url,
          headers: {
            ...this.headers,
            'Authorization': `Bearer ${bearerToken}`,
            'Content-Type': 'application/json'
          },
          data: {
            slug,
            theme_path: themePath,
            is_activated: activate
          },
          timeout: 60000, // 60s
          validateStatus: function (status: number): boolean {
            return status < 500;
          }
        };
    
        const response = await axios(config);
    
        if (response.status !== 200) {
          throw new Error(`API returned status ${response.status}: ${JSON.stringify(response.data)}`);
        }
    
        this.log('info', `Successfully triggered theme deployment for ${domain}`);
        return true;
    
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        this.log('error', `Failed to trigger theme deployment: ${errorMessage}`);
    
        if (axios.isAxiosError(error)) {
          const responseData = error.response?.data;
          const responseStatus = error.response?.status;
          this.log('error', 'API Error Details:', {
            status: responseStatus,
            data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData
          });
        }
    
        throw error;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It mentions uploading files and triggering deployment, but lacks details on whether it overwrites existing themes, requires a WordPress installation, affects live sites, or any prerequisites. Behavioral traits like destructiveness are not disclosed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise (two sentences, 30 words) and front-loaded with the primary purpose. Every sentence provides value, with no wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the absence of output schema, the description does not explain what the tool returns (e.g., status, deployment ID). It also omits potential preconditions or constraints (e.g., theme size limits). However, it covers the essential action and optional activation, making it minimally adequate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so parameters are fully described in the schema. The description adds no additional meaning beyond what the schema already provides, meeting the baseline for this dimension.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool deploys a WordPress theme from a directory to a hosting server, using specific verbs and resource identification. It distinguishes from siblings like hosting_deployWordpressPlugin by explicitly mentioning 'theme'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for WordPress theme deployment but does not provide explicit guidance on when to use this tool over alternatives (e.g., manual deployment or importing a site). No exclusions or comparison with similar tools are given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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

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