Skip to main content
Glama
Sofias-ai

SharePoint MCP Server

by Sofias-ai

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
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('Upload a new file') but lacks details on permissions required, file size limits, error handling, or whether the operation is idempotent. For a mutation tool with zero annotation coverage, this leaves critical behavioral traits unspecified, though it doesn't contradict any annotations.

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 that front-loads the core action and resource. Every word earns its place without redundancy, making it easy to parse quickly. There's no wasted text or unnecessary elaboration, which is ideal for tool selection.

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 tool's complexity (a mutation operation with 4 parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like authentication needs, error cases, or return values, nor does it fully explain parameter usage. For a file upload tool in a SharePoint context, more detail is warranted to ensure correct invocation.

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 uploading 'a new file to a SharePoint directory', which implies 'folder_name' and 'file_name', but doesn't explain 'content' (e.g., text or binary data) or 'is_base64' (e.g., encoding format). With 4 parameters and no schema descriptions, the description adds minimal semantic value beyond basic inference.

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') and resource ('a new file to a SharePoint directory'), making the purpose immediately understandable. It distinguishes from siblings like 'Create_Folder' or 'Delete_Document' by specifying file upload rather than folder creation or deletion. However, it doesn't explicitly differentiate from 'Upload_Document_From_Path', which handles uploads from a file path instead of content.

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. It doesn't mention prerequisites like authentication, compare with 'Upload_Document_From_Path' for path-based uploads, or indicate scenarios like handling large files or specific SharePoint permissions. Without such context, users must infer usage from the tool name alone.

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