Skip to main content
Glama

unprotect_document

Remove password protection from Word documents. Enter the filename and password to unlock and edit secure files with ease.

Instructions

Remove password protection from a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
passwordYes

Implementation Reference

  • The core handler function implementing the unprotect_document tool logic using msoffcrypto to decrypt password-protected Word documents.
    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)}"
  • MCP tool registration for 'unprotect_document' using FastMCP @mcp.tool() decorator. This wrapper delegates execution to the implementation in protection_tools.py.
    async def unprotect_document(filename: str, password: str):
        """Remove password protection from a Word document."""
        return await 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 full burden for behavioral disclosure. It states the tool performs a mutation ('Remove password protection'), but doesn't mention permissions needed, whether the operation is reversible, error conditions, or what happens to the document after processing. This is inadequate for a mutation tool with zero annotation coverage.

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 wasted words. It's front-loaded with the core purpose and appropriately sized for the tool's complexity.

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, no output schema, and 2 undocumented parameters, the description is incomplete. It states what the tool does but lacks crucial behavioral context, parameter guidance, and output expectations that would help an agent use it correctly.

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 description coverage is 0%, so parameters are undocumented in the schema. The description doesn't mention any parameters at all, failing to compensate for the coverage gap. However, with only 2 parameters and their names being self-explanatory ('filename', 'password'), the baseline is 3 as the description doesn't add value but the minimal parameter count reduces impact.

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 resource ('from a Word document'), making the purpose immediately understandable. It doesn't explicitly distinguish from sibling tools like 'protect_document', but the verb 'remove' versus 'protect' provides implicit differentiation.

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?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or constraints. It doesn't mention the sibling 'protect_document' tool or any other related operations, leaving usage context entirely implicit.

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

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/franlealp1/mcp-word'

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