Skip to main content
Glama
Sofias-ai

SharePoint MCP Server

by Sofias-ai

Get_Document_Content

Extract content from specific documents in SharePoint by specifying folder and file names, enabling direct interaction with stored data.

Instructions

Get content of a document in SharePoint

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_nameYes
folder_nameYes

Implementation Reference

  • Core implementation of get_document_content: downloads file from SharePoint, extracts text for supported formats (PDF, Excel, Word, text files), falls back to base64 for binary.
    def get_document_content(folder_name: str, file_name: str) -> dict:
        """Retrieve document content; supports PDF text extraction"""
        file_path = _get_sp_path(f"{folder_name}/{file_name}")
        file = sp_context.web.get_file_by_server_relative_url(file_path)
        sp_context.load(file, ["Exists", "Length", "Name"])
        sp_context.execute_query()
        logger.info(f"File exists: {file.exists}, size: {file.length}")
    
        content = io.BytesIO()
        file.download(content)
        sp_context.execute_query()
        content_bytes = content.getvalue()
        
        # Determine file type and process accordingly
        lower_name = file_name.lower()
        file_type = next((t for t, exts in FILE_TYPES.items() if any(lower_name.endswith(ext) for ext in exts)), 'binary')
        
        if file_type == 'pdf':
            try:
                text, pages = extract_text_from_pdf(content_bytes)
                return {"name": file_name, "content_type": "text", "content": text, "original_type": "pdf", "page_count": pages, "size": len(content_bytes)}
            except Exception as e:
                logger.warning(f"PDF processing failed: {e}")
                return {"name": file_name, "content_type": "binary", "content_base64": base64.b64encode(content_bytes).decode(), "original_type": "pdf", "size": len(content_bytes)}
        
        if file_type == 'excel':
            try:
                text, sheets = extract_text_from_excel(content_bytes)
                return {"name": file_name, "content_type": "text", "content": text, "original_type": "excel", "sheet_count": sheets, "size": len(content_bytes)}
            except Exception as e:
                logger.warning(f"Excel processing failed: {e}")
                return {"name": file_name, "content_type": "binary", "content_base64": base64.b64encode(content_bytes).decode(), "original_type": "excel", "size": len(content_bytes)}
        
        if file_type == 'word':
            try:
                text, paragraphs = extract_text_from_word(content_bytes)
                return {"name": file_name, "content_type": "text", "content": text, "original_type": "word", "paragraph_count": paragraphs, "size": len(content_bytes)}
            except Exception as e:
                logger.warning(f"Word processing failed: {e}")
                return {"name": file_name, "content_type": "binary", "content_base64": base64.b64encode(content_bytes).decode(), "original_type": "word", "size": len(content_bytes)}
        
        if file_type == 'text':
            try:
                return {"name": file_name, "content_type": "text", "content": content_bytes.decode('utf-8'), "size": len(content_bytes)}
            except UnicodeDecodeError:
                pass
        
        return {"name": file_name, "content_type": "binary", "content_base64": base64.b64encode(content_bytes).decode(), "size": len(content_bytes)}
  • MCP tool registration using @mcp.tool decorator. The handler function delegates to resources.get_document_content.
    @mcp.tool(name="Get_Document_Content", description="Get content of a document in SharePoint")
    async def get_document_content_tool(folder_name: str, file_name: str):
        """Get content of a document in SharePoint"""
        return get_document_content(folder_name, file_name)
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 retrieves content, implying a read-only operation, but doesn't specify details like authentication requirements, rate limits, error handling, or output format (e.g., text, binary). This leaves significant gaps in understanding how the tool behaves beyond its basic purpose.

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, clear sentence with no wasted words. It's front-loaded with the core action and resource, making it easy to scan and understand quickly. Every word earns its place by conveying essential information without redundancy.

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 retrieval tool with no annotations, 0% schema coverage, and no output schema, the description is incomplete. It lacks details on parameters, behavioral traits (e.g., permissions, errors), and expected output, making it inadequate for the agent to use the tool effectively without additional context or trial-and-error.

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?

The schema description coverage is 0%, meaning parameters are undocumented in the schema. The description adds no information about the parameters (file_name and folder_name), such as their purpose, format (e.g., paths, names), or constraints. It fails to compensate for the lack of schema documentation, leaving parameters ambiguous.

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 ('Get content') and resource ('document in SharePoint'), which is specific and unambiguous. However, it doesn't differentiate from potential siblings like 'List_SharePoint_Documents' or 'Update_Document', which might also involve document content in some way, so it doesn't reach the highest score.

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 (e.g., needing a document to exist), exclusions (e.g., not for editing), or compare to siblings like 'List_SharePoint_Documents' for browsing or 'Update_Document' for modifications, leaving the agent to infer usage from context 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