Skip to main content
Glama
sitebay
by sitebay

sitebay_site_edit_file

Edit files in WordPress wp-content directory to update themes, plugins, or custom code. Specify site domain, file path, and new content to modify site files.

Instructions

Edit a file in the site's wp-content directory.

Args: fqdn: The fully qualified domain name of the site file_path: Path to the file in wp-content (e.g., "wp-content/themes/mytheme/style.css") content: New content for the file

Returns: Success confirmation with file details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fqdnYes
file_pathYes
file_edit_using_search_replace_blocksYes

Implementation Reference

  • Core handler function implementing the file edit logic using search-replace blocks via SiteBayClient.edit_file, including input validation and response formatting.
    async def sitebay_site_edit_file(
        client: SiteBayClient,
        fqdn: str,
        file_path: str,
        file_edit_using_search_replace_blocks: str,
    ) -> str:
        """
        Edit a file in the site's wp-content directory using diff-edit blocks.
        
        Args:
            fqdn: The fully qualified domain name of the site
            file_path: Path to the file relative to wp-content (e.g., "wp-content/themes/mytheme/style.css")
            file_edit_using_search_replace_blocks: A single string containing blocks in the form:
                <<<<<< SEARCH\nold text\n=======\nnew text\n>>>>>> REPLACE
        
        Returns:
            Success message or error
        """
        try:
            # Normalize path (server also handles this, but we pre-normalize to help users)
            normalized_path = file_path.replace(
                "/bitnami/wordpress/wp-content", "wp-content"
            )
            
            if not normalized_path.startswith("wp-content"):
                return (
                    "❌ Invalid file_path: must start with 'wp-content/'. "
                    "Example: wp-content/themes/mytheme/style.css"
                )
            
            text = file_edit_using_search_replace_blocks
            if (
                "<<<<<< SEARCH" not in text
                or "=======" not in text
                or ">>>>>> REPLACE" not in text
            ):
                return (
                    "❌ Invalid diff-edit block format. Make sure blocks are in correct sequence, "
                    "and the markers are on separate lines:\n\n"
                    "<<<<<< SEARCH\n    example old\n=======\n    example new\n>>>>>> REPLACE\n"
                )
            
            result = await client.edit_file(
                fqdn, normalized_path, text
            )
            
            response = f"✅ **File Updated Successfully**\n\n"
            response += f"• **Site**: {fqdn}\n"
            response += f"• **File**: wp-content/{file_path}\n"
            response += f"• **Content Length**: {len(text)} characters\n"
            
            if isinstance(result, str) and result:
                response += f"\n**Server Response:**\n```\n{result}\n```"
            
            return response
            
        except SiteBayError as e:
            return f"Error editing file on {fqdn}: {str(e)}"
  • FastMCP tool registration with @mcp.tool decorator. Thin wrapper that initializes the SiteBayClient and delegates to the operations module implementation.
    @mcp.tool
    async def sitebay_site_edit_file(
        fqdn: str,
        file_path: str,
        file_edit_using_search_replace_blocks: str,
    ) -> str:
        """
        Edit a file in the site's wp-content directory.
        
        Args:
            fqdn: The fully qualified domain name of the site
            file_path: Path to the file in wp-content (e.g., "wp-content/themes/mytheme/style.css")
            content: New content for the file
        
        Returns:
            Success confirmation with file details
        """
        client = await initialize_client()
        return await operations.sitebay_site_edit_file(
            client, fqdn, file_path, file_edit_using_search_replace_blocks
        )

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/sitebay/sitebay-mcp'

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