Skip to main content
Glama

List_SharePoint_Documents

Retrieve a comprehensive list of all documents within a specified SharePoint folder using this tool, ensuring efficient document management and access.

Instructions

List all documents in a specified SharePoint folder

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
folder_nameYes

Implementation Reference

  • MCP handler function for the 'List_SharePoint_Documents' tool. Registers the tool and delegates execution to the list_documents helper function from resources.py.
    @mcp.tool(name="List_SharePoint_Documents", description="List all documents in a specified SharePoint folder") async def list_documents_tool(folder_name: str): """List all documents in a specified SharePoint folder""" return list_documents(folder_name)
  • Core helper function that lists documents in the specified SharePoint folder by invoking the generic _load_sp_items with item_type='files'.
    def list_documents(folder_name: str) -> List[Dict[str, Any]]: """List all documents in a specified folder""" logger.info(f"Listing documents in folder: {folder_name}") return _load_sp_items(_get_sp_path(folder_name), "files")
  • Generic helper that loads SharePoint folders or files (used for documents with 'files'), retrieves properties like name, url, size, timestamps.
    def _load_sp_items(path: str, item_type: str) -> List[Dict[str, Any]]: """Generic function to load folders or files from SharePoint""" folder = sp_context.web.get_folder_by_server_relative_url(path) items = getattr(folder, item_type) props = ["ServerRelativeUrl", "Name", "TimeCreated", "TimeLastModified"] + (["Length"] if item_type == "files" else []) sp_context.load(items, props) sp_context.execute_query() return [{ "name": item.name, "url": item.properties.get("ServerRelativeUrl"), **({"size": item.properties.get("Length")} if item_type == "files" else {}), "created": item.properties.get("TimeCreated").isoformat() if item.properties.get("TimeCreated") else None, "modified": item.properties.get("TimeLastModified").isoformat() if item.properties.get("TimeLastModified") else None } for item in items]
  • Helper to construct the full SharePoint server-relative path from folder name, prepending the document library.
    def _get_sp_path(sub_path: Optional[str] = None) -> str: """Create a properly formatted SharePoint path""" return f"{SHP_DOC_LIBRARY}/{sub_path or ''}".rstrip('/')
  • The @mcp.tool decorator that registers 'List_SharePoint_Documents' with MCP, including name and description.
    @mcp.tool(name="List_SharePoint_Documents", description="List all documents in a specified SharePoint folder")

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