Skip to main content
Glama
GongRzhe

Office Word MCP Server

unprotect_document

Remove password protection from Microsoft Word documents to enable editing and access. Enter the filename and password to unlock the document.

Instructions

Remove password protection from a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
passwordYes

Implementation Reference

  • The primary handler function implementing the unprotect_document tool. It decrypts password-protected Word documents using msoffcrypto, overwrites the original file with decrypted content, handles file permissions, and provides detailed error messages for invalid passwords or formats.
    async def unprotect_document(filename: str, password: str) -> str:
        """Remove password protection from a Word document.
    
        Args:
            filename: Path to the Word document
            password: Password that was used to protect the document
        """
        filename = ensure_docx_extension(filename)
    
        if not os.path.exists(filename):
            return f"Document {filename} does not exist"
    
        # Check if file is writeable
        is_writeable, error_message = check_file_writeable(filename)
        if not is_writeable:
            return f"Cannot modify document: {error_message}"
    
        try:
            # Read the encrypted file content
            with open(filename, "rb") as infile:
                encrypted_data = infile.read()
    
            # Create an msoffcrypto file object from the encrypted data
            file = msoffcrypto.OfficeFile(io.BytesIO(encrypted_data))
            file.load_key(password=password) # Set the password for decryption
    
            # Decrypt the data into an in-memory buffer
            decrypted_data_io = io.BytesIO()
            file.decrypt(outfile=decrypted_data_io) # Pass the buffer as the 'outfile' argument
    
            # Overwrite the original file with the decrypted data
            with open(filename, "wb") as outfile:
                outfile.write(decrypted_data_io.getvalue())
    
            return f"Document {filename} decrypted successfully."
    
        except msoffcrypto.exceptions.InvalidKeyError:
             return f"Failed to decrypt document {filename}: Incorrect password."
        except msoffcrypto.exceptions.InvalidFormatError:
             return f"Failed to decrypt document {filename}: File is not encrypted or is not a supported Office format."
        except Exception as e:
            # Attempt to restore encrypted file content on failure
            try:
                if 'encrypted_data' in locals():
                    with open(filename, "wb") as outfile:
                        outfile.write(encrypted_data)
                    return f"Failed to decrypt document {filename}: {str(e)}. Encrypted file restored."
                else:
                     return f"Failed to decrypt document {filename}: {str(e)}. Could not restore encrypted file."
            except Exception as restore_e:
                 return f"Failed to decrypt document {filename}: {str(e)}. Also failed to restore encrypted file: {str(restore_e)}"
  • The registration of the 'unprotect_document' tool using the @mcp.tool() decorator in the main server file. This sync wrapper delegates execution to the async implementation in protection_tools.
    @mcp.tool()
    def unprotect_document(filename: str, password: str):
        """Remove password protection from a Word document."""
        return protection_tools.unprotect_document(filename, password)
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 of behavioral disclosure. It states the tool's purpose but lacks details on permissions, side effects (e.g., irreversible changes), error handling, or output format, which are critical for a mutation tool.

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 a single, efficient sentence with zero waste, front-loaded with the core action. It's appropriately sized for the tool's complexity, making it easy to parse quickly.

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

Completeness2/5

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

For a mutation tool with no annotations, 0% schema coverage, and no output schema, the description is inadequate. It lacks details on behavior, parameters, and outcomes, failing to provide enough context for safe and effective use.

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

Parameters2/5

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

Schema description coverage is 0%, and the description doesn't explain the two required parameters ('filename' and 'password'). It fails to add meaning beyond the schema, such as file format expectations or password validation rules, leaving parameters undocumented.

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

Purpose4/5

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

The description clearly states the action ('Remove password protection') and the resource ('from a Word document'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'protect_document' beyond the obvious opposite action, missing explicit contrast.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. While 'protect_document' is a sibling, the description doesn't mention it or any prerequisites, leaving usage context implied rather than explicit.

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/GongRzhe/Office-Word-MCP-Server'

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