List_SharePoint_Folders
List folders in a specified SharePoint directory or root using the SharePoint MCP Server. Simplify folder navigation and organization by retrieving folder details directly.
Instructions
List folders in the specified SharePoint directory or root if not specified
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parent_folder | No |
Implementation Reference
- src/mcp_sharepoint/tools.py:33-37 (handler)MCP tool handler: decorated function that executes the tool by delegating to list_folders helper.@mcp.tool(name="List_SharePoint_Folders", description="List folders in the specified SharePoint directory or root if not specified") async def list_folders_tool(parent_folder: Optional[str] = None): """List folders in the specified SharePoint directory or root if not specified""" return list_folders(parent_folder)
- Primary helper function implementing the folder listing logic by calling generic _load_sp_items.def list_folders(parent_folder: Optional[str] = None) -> List[Dict[str, Any]]: """List folders in the specified directory or root if not specified""" logger.info(f"Listing folders in {parent_folder or 'root directory'}") return _load_sp_items(_get_sp_path(parent_folder), "folders")
- Core generic helper that loads SharePoint folders or files with metadata properties using office365 API.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 SharePoint paths from library and subpath.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('/')
- src/mcp_sharepoint/tools.py:33-33 (registration)Tool registration decorator specifying name and description.@mcp.tool(name="List_SharePoint_Folders", description="List folders in the specified SharePoint directory or root if not specified")