Skip to main content

SharePoint

Overview

The SharePoint integration provides full CRUD operations over SharePoint resources via Microsoft Graph API. It supports:

  • Sites: Search and discover SharePoint sites
  • Files: List, read, upload, update, delete files in document libraries
  • Lists: CRUD operations on SharePoint lists and list items
  • Streaming Downloads: Zero-copy proxy streaming for file downloads

All operations use the existing Microsoft 365 OAuth flow. No separate consent is required.

Prerequisites

  1. Microsoft 365 integration must be active for your tenant
  2. The following OAuth scopes must be authorized:
    • Files.ReadWrite.All — File CRUD on document libraries
    • Sites.Read.All — Site discovery and enumeration
    • Sites.ReadWrite.All — List item operations and metadata

If you authorized before these scopes were added, you'll receive a 407 response with an auth_url on your first SharePoint call. Visit the URL to re-authorize with the new permissions.

API Reference

Sites

MethodPathDescription
GET/microsoft365/sharepoint/sitesSearch and list SharePoint sites
GET/microsoft365/sharepoint/sites/{site_id}Get a specific site by ID
GET/microsoft365/sharepoint/sites/{site_id}/drivesList document libraries

Search sites

curl -X GET "https://api.yourdomain.com/microsoft365/sharepoint/sites?search=projects" \
-H "Access-Token: <token>"

Get site by ID

curl -X GET "https://api.yourdomain.com/microsoft365/sharepoint/sites/{site_id}" \
-H "Access-Token: <token>"

List document libraries

curl -X GET "https://api.yourdomain.com/microsoft365/sharepoint/sites/{site_id}/drives" \
-H "Access-Token: <token>"

Files

MethodPathDescription
GET/microsoft365/sharepoint/sites/{site_id}/drives/{drive_id}/itemsList files/folders
GET.../items/{item_id}Get file metadata
GET.../items/{item_id}/contentDownload file (streaming)
PUT.../items/{parent_id}/children/{filename}Upload file
PATCH.../items/{item_id}Update/rename file
DELETE.../items/{item_id}Delete file
POST.../foldersCreate folder

List files in a document library

curl -X GET "https://api.yourdomain.com/microsoft365/sharepoint/sites/{site_id}/drives/{drive_id}/items" \
-H "Access-Token: <token>"

Download a file (streaming)

The download endpoint returns a StreamingResponse — the file bytes are piped directly from Microsoft Graph without buffering in memory.

curl -X GET "https://api.yourdomain.com/microsoft365/sharepoint/sites/{site_id}/drives/{drive_id}/items/{item_id}/content" \
-H "Access-Token: <token>" \
-o downloaded-file.pdf

Memory guarantee: Regardless of file size (1KB or 2GB), the download uses ~65KB of Python memory (httpx internal buffer only).

Upload a file

curl -X PUT "https://api.yourdomain.com/microsoft365/sharepoint/sites/{site_id}/drives/{drive_id}/items/{parent_id}/children/document.pdf" \
-H "Access-Token: <token>" \
-H "Content-Type: application/octet-stream" \
--data-binary @document.pdf

Size limit: 25MB per upload. For larger files, use Microsoft Graph's chunked upload session API directly.

Create a folder

curl -X POST "https://api.yourdomain.com/microsoft365/sharepoint/sites/{site_id}/drives/{drive_id}/folders" \
-H "Access-Token: <token>" \
-H "Content-Type: application/json" \
-d '{"parent_path": "/Documents", "folder_name": "NewFolder"}'

Lists

MethodPathDescription
GET/microsoft365/sharepoint/sites/{site_id}/listsList SharePoint lists
GET.../lists/{list_id}/itemsList items in a list
GET.../lists/{list_id}/items/{item_id}Get a list item
POST.../lists/{list_id}/itemsCreate a list item
PATCH.../lists/{list_id}/items/{item_id}Update a list item
DELETE.../lists/{list_id}/items/{item_id}Delete a list item

List items in a SharePoint list

curl -X GET "https://api.yourdomain.com/microsoft365/sharepoint/sites/{site_id}/lists/{list_id}/items" \
-H "Access-Token: <token>"

Create a list item

curl -X POST "https://api.yourdomain.com/microsoft365/sharepoint/sites/{site_id}/lists/{list_id}/items" \
-H "Access-Token: <token>" \
-H "Content-Type: application/json" \
-d '{"fields": {"Title": "New Task", "Status": "Not Started"}}'

Update a list item

curl -X PATCH "https://api.yourdomain.com/microsoft365/sharepoint/sites/{site_id}/lists/{list_id}/items/{item_id}" \
-H "Access-Token: <token>" \
-H "Content-Type: application/json" \
-d '{"fields": {"Status": "Completed"}}'

Streaming Downloads Architecture

The SharePoint download endpoint (GET .../items/{item_id}/content) uses zero-copy proxy streaming:

Microsoft Graph API
│ GET /sites/{id}/drive/items/{item}/content

httpx AsyncClient (shared connection pool)
│ client.stream("GET", url, headers=headers)

SharePointBase._stream_binary()
│ yields bytes chunks one at a time
│ enforces byte limit mid-stream

FastAPI StreamingResponse
│ pipes chunks directly to client TCP socket

Client receives attachment download

Safety Guarantees

ScenarioMemory CostWhy Safe
2KB text file~65KBhttpx internal buffer only
100MB PDF~65KBStreaming, never assembled
2GB video~65KBStreaming, never assembled
Malicious oversized file413 errorRejected at Content-Length check
Missing Content-Length413 errorRuntime byte counter catches it

Error Handling During Streams

  • 401 mid-stream: Token refresh attempted once, retry on success
  • 403 (InsufficientPermissions): Returns 407 with re-auth URL
  • File exceeds 100MB: Returns 413 with size limit message

Error Reference

HTTPConditionMeaning
400Invalid ODataBad filter/select/orderby parameter
401Missing tokenNo Access-Token header
403Insufficient permissionsRe-authorize with SharePoint scopes
404Resource not foundSite/drive/file/list doesn't exist
407OAuth requiredToken expired or new scopes needed
413File too largeUpload >25MB or download >100MB
429Rate limitedToo many requests, retry after backoff

If you authorized Microsoft 365 before the SharePoint scopes were added:

  1. Call any SharePoint endpoint
  2. Receive 407 response with auth_url
  3. Visit auth_url to complete the consent screen
  4. The new scopes (Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All) will be granted
  5. Retry your original SharePoint call

MCP Tools

SharePoint is also available via MCP tools with the following naming convention:

ToolDescription
sharepointsite:listSearch and list SharePoint sites
sharepointsite:readGet a SharePoint site by ID
sharepointdrive:listList document libraries
sharepointfile:listList files in a document library
sharepointfile:readGet file metadata
sharepointfile:downloadDownload a file (base64-encoded)
sharepointfile:createUpload a file
sharepointfile:updateUpdate/rename a file
sharepointfile:deleteDelete a file
sharepointfile:mkdirCreate a folder
sharepointlist:listList SharePoint lists
sharepointitem:listList items in a list
sharepointitem:readGet a list item
sharepointitem:createCreate a list item
sharepointitem:updateUpdate a list item
sharepointitem:deleteDelete a list item

See also: Microsoft 365