Skip to main content
Glama
Sofias-ai

SharePoint MCP Server

by Sofias-ai

Upload_Document_From_Path

Transfer files from a local path to SharePoint by specifying folder name and file path, optionally renaming the file during upload using the SharePoint MCP Server.

Instructions

Upload a file directly from a file path to SharePoint

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
folder_nameYes
new_file_nameNo

Implementation Reference

  • Core handler logic for uploading a document from a local file path to a SharePoint folder. Opens the file in binary mode, determines filename if not provided, uploads via SharePoint context, returns success response.
    async def upload_document_from_path(folder_name: str, file_path: str, new_file_name: Optional[str] = None):
        """Upload a file directly from a path without needing to convert to base64 first"""
        logger.info(f"Uploading document from path {file_path} to folder {folder_name}")
        
        try:
            with open(file_path, "rb") as file:
                file_content = file.read()
            
            if not new_file_name:
                new_file_name = os.path.basename(file_path)
                
            folder = sp_context.web.get_folder_by_server_relative_url(_get_path(folder_name))
            uploaded_file = folder.upload_file(new_file_name, file_content)
            sp_context.execute_query()
            
            return _file_success_response(uploaded_file, f"File {new_file_name} uploaded successfully")
        except Exception as e:
            logger.error(f"Error uploading file from path: {str(e)}")
            raise
  • Registers the tool 'Upload_Document_From_Path' with MCP using @mcp.tool decorator including description. Applies error handling decorator. Input schema defined by function parameters: folder_name (str), file_path (str), new_file_name (Optional[str]).
    @mcp.tool(name="Upload_Document_From_Path", description="Upload a file directly from a file path to SharePoint")
    @_handle_sp_operation
  • Decorator _handle_sp_operation applied to the tool for standardized error handling, logging, and consistent error response format.
    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 _file_success_response formats the standardized success response with file name and URL.
    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 _get_path constructs the SharePoint server-relative path for the target folder.
    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
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states the basic operation. It doesn't disclose behavioral traits such as required permissions, file size limits, overwrite behavior, error handling, or response format, leaving significant gaps 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, clearly front-loaded with the core action. It's appropriately sized for the tool's scope without unnecessary elaboration.

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 file upload operation, no annotations, no output schema, and low schema coverage, the description is incomplete. It lacks details on behavior, parameters, and outcomes, making it inadequate for safe and effective use 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 but adds no parameter details. It doesn't explain what 'file_path', 'folder_name', or 'new_file_name' mean, their formats, or constraints, failing to address the undocumented parameters.

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 ('Upload a file') and target resource ('to SharePoint') with a specific method ('directly from a file path'). It distinguishes from the sibling 'Upload_Document' by specifying the source method, though not explicitly contrasting them.

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 like 'Upload_Document' or other siblings. The description implies usage for file uploads from local paths but lacks explicit context, prerequisites, or exclusions.

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