Skip to main content
Glama
Sofias-ai

SharePoint MCP Server

by Sofias-ai

Update_Document

Modify existing documents in a SharePoint directory by specifying folder name, file name, and updated content. Supports Base64 encoding for complex data.

Instructions

Update an existing document in a SharePoint directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYes
file_nameYes
folder_nameYes
is_base64No

Implementation Reference

  • Full handler implementation for the 'Update_Document' tool. Registers the tool with MCP, applies error handling decorator, defines input parameters (folder_name, file_name, content, is_base64), checks file existence, decodes content if base64-encoded, overwrites the file in SharePoint using upload_file, and returns success response with file info.
    @mcp.tool(name="Update_Document", description="Update an existing document in a SharePoint directory")
    @_handle_sp_operation
    async def update_document(folder_name: str, file_name: str, content: str, is_base64: bool = False):
        """Update an existing document in a SharePoint directory"""
        logger.info(f"Updating document {file_name} in folder {folder_name}")
        
        # Check if file exists
        file_path = _get_path(folder_name, file_name)
        file = sp_context.web.get_file_by_server_relative_url(file_path)
        sp_context.load(file, ["Exists", "Name", "ServerRelativeUrl"])
        sp_context.execute_query()
        
        if not file.exists:
            return {"success": False, "message": f"File {file_name} does not exist in folder {folder_name}"}
        
        # Update file using upload method
        file_content = base64.b64decode(content) if is_base64 else content.encode('utf-8')
        folder = sp_context.web.get_folder_by_server_relative_url(_get_path(folder_name))
        updated_file = folder.upload_file(file_name, file_content)
        sp_context.execute_query()
        
        return _file_success_response(updated_file, f"File {file_name} updated successfully")
  • Explicit registration of the Update_Document tool using the @mcp.tool decorator, specifying the tool name.
    @mcp.tool(name="Update_Document", description="Update an existing document in a SharePoint directory")
  • Helper decorator applied to the Update_Document handler for standardized SharePoint error handling and logging.
    def _handle_sp_operation(func):
        """Decorator for SharePoint operations with error handling"""
        @wraps(func)
        async def wrapper(*args, **kwargs):
            try:
                return await func(*args, **kwargs)
            except Exception as e:
                logger.error(f"Error in {func.__name__}: {str(e)}")
                return {"success": False, "message": f"Operation failed: {str(e)}"}
        return wrapper
  • Utility function used to build SharePoint server-relative paths for the document location.
    def _get_path(folder: str = "", file: Optional[str] = None) -> str:
        """Construct SharePoint path from components"""
        path = f"{SHP_DOC_LIBRARY}/{folder}".rstrip('/')
        return f"{path}/{file}" if file else path
  • Helper function to format the success response returned by the Update_Document tool.
    def _file_success_response(file_obj, message: str) -> Dict[str, Any]:
        """Standard success response for file operations"""
        return {
            "success": True,
            "message": message,
            "file": {"name": file_obj.name, "url": file_obj.serverRelativeUrl}
        }
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 updates documents but fails to mention critical aspects like required permissions, whether the update overwrites or merges content, error handling, or any rate limits. This leaves significant gaps in understanding the tool's behavior.

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, straightforward sentence with no wasted words. It is appropriately sized and front-loaded, clearly stating the tool's purpose without unnecessary elaboration, making it efficient and easy to parse.

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?

Given the complexity of a document update operation, no annotations, no output schema, and 0% schema coverage, the description is inadequate. It lacks details on parameters, behavior, error cases, and output, making it incomplete for effective tool invocation by an AI agent.

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%, so the description must compensate for undocumented parameters. It mentions no parameters at all, failing to explain the meaning of 'content', 'file_name', 'folder_name', or 'is_base64'. This leaves all four parameters semantically unclear beyond their titles.

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 ('Update') and resource ('an existing document in a SharePoint directory'), making the purpose immediately understandable. However, it doesn't distinguish this tool from its sibling 'Upload_Document', which might also modify documents, leaving room for ambiguity in sibling 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 like 'Upload_Document' or 'Delete_Document'. It lacks context about prerequisites (e.g., document must exist), exclusions, or comparisons to sibling tools, offering minimal usage direction.

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/Sofias-ai/mcp-sharepoint'

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