Skip to main content
Glama

Upload_Document

Upload files to a specified directory on SharePoint, supporting both text and Base64 content. Streamline document management and integration with SharePoint workflows.

Instructions

Upload a new file to a SharePoint directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYes
file_nameYes
folder_nameYes
is_base64No

Implementation Reference

  • The main handler function for the 'Upload_Document' tool. It is decorated with @mcp.tool for registration and @_handle_sp_operation for error handling. The function uploads the provided content (decoded from base64 if specified) as a new file to the specified SharePoint folder using the SharePoint context.
    @mcp.tool(name="Upload_Document", description="Upload a new file to a SharePoint directory") @_handle_sp_operation async def upload_document(folder_name: str, file_name: str, content: str, is_base64: bool = False): """Upload a new file to a directory""" logger.info(f"Uploading document {file_name} to folder {folder_name}") # Convert content and upload 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)) uploaded_file = folder.upload_file(file_name, file_content) sp_context.execute_query() return _file_success_response(uploaded_file, f"File {file_name} uploaded successfully")
  • Helper decorator applied to the upload handler for standardized error handling in SharePoint operations.
    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
  • Helper function used by the handler to format successful upload responses.
    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} }
  • Helper function used in the handler to construct the full SharePoint server-relative path.
    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
  • Import of the tools module in the server entrypoint, which triggers registration of all @mcp.tool decorated functions when the server starts.
    from . import resources, tools

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