npm package: @piyapat/sharepoint-mcp-server
Description: MCP server for Microsoft SharePoint Online via Microsoft Graph API
Latest version: 1.0.1

# SharePoint MCP Server

An MCP (Model Context Protocol) server for Microsoft SharePoint Online. Provides tools to list, read, and write files via the Microsoft Graph API.

## Tools

| Tool | Description |
|------|-------------|
| `sharepoint_list_files` | List files and folders in a SharePoint document library |
| `sharepoint_read_file` | Read file contents (text or binary as base64) |
| `sharepoint_write_file` | Upload/write a file to SharePoint |

## Prerequisites

### 1. Register an Azure AD App

1. Go to [Azure Portal](https://portal.azure.com) → **Azure Active Directory** → **App registrations** → **New registration**
2. Name your app (e.g., `sharepoint-mcp-server`), click **Register**
3. Note the **Application (client) ID** and **Directory (tenant) ID**

### 2. Add API Permissions

1. Go to **API permissions** → **Add a permission** → **Microsoft Graph** → **Application permissions**
2. Add these permissions:
   - `Sites.Read.All` — for list and read operations
   - `Sites.ReadWrite.All` — for write operations
3. Click **Grant admin consent for [your tenant]**

### 3. Create a Client Secret

1. Go to **Certificates & secrets** → **New client secret**
2. Set an expiry and click **Add**
3. Copy the **Value** immediately (it won't be shown again)

### 4. Find Your Site ID

Use [Graph Explorer](https://developer.microsoft.com/en-us/graph/graph-explorer) to find your site ID:
```
GET https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/mysite
```
Copy the `id` field from the response (format: `contoso.sharepoint.com,<site-collection-id>,<web-id>`).

## Usage with `npx`

### Claude Desktop Configuration

Add to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "sharepoint": {
      "command": "npx",
      "args": ["-y", "@piyapat/sharepoint-mcp-server"],
      "env": {
        "SHAREPOINT_TENANT_ID": "your-tenant-id",
        "SHAREPOINT_CLIENT_ID": "your-client-id",
        "SHAREPOINT_CLIENT_SECRET": "your-client-secret"
      }
    }
  }
}
```

### Claude Code / MCP CLI

```bash
SHAREPOINT_TENANT_ID=... \
SHAREPOINT_CLIENT_ID=... \
SHAREPOINT_CLIENT_SECRET=... \
npx @piyapat/sharepoint-mcp-server
```

### Using a `.env` file

Copy `.env.example` to `.env` and fill in your credentials, then run:

```bash
npx @piyapat/sharepoint-mcp-server
```

## Tool Reference

### `sharepoint_list_files`

List files in a SharePoint folder.

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `site_id` | string | ✅ | — | SharePoint site ID (e.g., `contoso.sharepoint.com,abc...,def...`) |
| `drive_id` | string | ❌ | default drive | Document library drive ID; omit to use the site's default library |
| `folder_path` | string | ❌ | `/` | Folder path relative to drive root (e.g., `/Documents/Reports`) |
| `page_size` | number | ❌ | `50` | Max items to return (1–200) |
| `response_format` | `markdown`\|`json` | ❌ | `markdown` | Output format |

### `sharepoint_read_file`

Read a file from SharePoint. Maximum file size: **20 MB**.

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `site_id` | string | ✅ | — | SharePoint site ID |
| `drive_id` | string | ❌ | default drive | Document library drive ID; omit to use the site's default library |
| `file_path` | string | ✅ | — | Path to file relative to drive root (e.g., `/Documents/report.txt`) |
| `encoding` | `utf8`\|`base64` | ❌ | `utf8` | Return encoding; binary files are auto-detected and returned as base64 |
| `response_format` | `markdown`\|`json` | ❌ | `markdown` | Output format |

### `sharepoint_write_file`

Upload a file to SharePoint. Files ≤ 4 MB use simple PUT upload; files > 4 MB automatically use resumable upload sessions with 3.2 MB chunks.

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `site_id` | string | ✅ | — | SharePoint site ID |
| `drive_id` | string | ❌ | default drive | Document library drive ID; omit to use the site's default library |
| `file_path` | string | ✅ | — | Destination path relative to drive root (e.g., `/Documents/report.txt`) |
| `content` | string | ✅ | — | File content (plain text or base64 for binary files) |
| `encoding` | `utf8`\|`base64` | ❌ | `utf8` | Encoding of the `content` parameter |
| `conflict_behavior` | `replace`\|`rename`\|`fail` | ❌ | `replace` | What to do if the file already exists |
| `response_format` | `markdown`\|`json` | ❌ | `markdown` | Output format |

## Development

```bash
# Install dependencies
npm install

# Build
npm run build

# Run locally
npm start
```

## Required Graph API Permissions

| Permission | Type | Used by |
|------------|------|---------|
| `Sites.Read.All` | Application | `sharepoint_list_files`, `sharepoint_read_file` |
| `Sites.ReadWrite.All` | Application | `sharepoint_write_file` |

All permissions require **admin consent** in your Azure AD tenant.

## License

MIT