SharePoint MCP服务器
用于通过Microsoft Graph API管理SharePoint文件和文件夹的TypeScript MCP(模型上下文协议)服务器。
特性
- 11个MCP工具 用于完整的SharePoint文件/文件夹管理
- 两个身份验证流:客户端凭据(应用程序级别)和代表(用户级别)
- 两次运输:stdio(用于克劳德桌面/CLI)和流式HTTP
- 可恢复上传 用于大文件(>4MB)
- 内容提取 来自PDF、Word(.docx)、Excel(.xlsx)和文本文件
- Markdown到DOCX的转换 通过Pandoc使用SharePoint中的可选样式模板
快速开始
1.安装依赖项```bash
npm install
npm run build
### 2.配置环境```bash
cp .env.example .env
# Edit .env with your Azure AD and SharePoint details
所需的环境变量:
AZURE_TENANT_ID-Azure AD租户IDAZURE_CLIENT_ID-应用注册客户端IDAZURE_CLIENT_SECRET-应用注册客户端密码SHAREPOINT_HOSTNAME-例如。yourcompany.sharepoint.comSHAREPOINT_SITE_NAME-例如。YourSiteNameAUTH_FLOW-client_credentials(默认)或on_behalf_of
3.跑步
stdio传输 (适用于克劳德桌面):```bash
npm start
**HTTP传输**:```bash
npm run start:http
# Server starts on http://localhost:3000/mcp
Claude桌面配置
添加到您的Claude桌面配置(~/Library/Application Support/Claude/claude_desktop_config.json):```json
{
"mcpServers": {
"sharepoint": {
"command": "node",
"args": ["/path/to/sharepoint-mcp-nodejs/dist/index.js"],
"env": {
"AZURE_TENANT_ID": "your-tenant-id",
"AZURE_CLIENT_ID": "your-client-id",
"AZURE_CLIENT_SECRET": "your-client-secret",
"SHAREPOINT_HOSTNAME": "yourcompany.sharepoint.com",
"SHAREPOINT_SITE_NAME": "YourSiteName"
}
}
}
}
## 可用工具
|工具|说明|
|------|-------------|
| `List_SharePoint_Folders` |列出目录中的文件夹|
| `Create_Folder` |创建新文件夹|
| `Delete_Folder` |删除文件夹|
| `Get_SharePoint_Tree` |递归树视图(可配置深度)|
| `List_SharePoint_Documents` |列出包含元数据的文档|
| `Get_Document_Content` |下载+提取文本(PDF/Word/Excel/text)|
| `Create_Document_From_Markdown` |使用可选样式模板将markdown/text转换为.docx|
| `Upload_Document` |从base64或文本内容上传|
| `Upload_Document_From_Path` |上传本地文件(可恢复>4MB)|
| `Update_Document` |更新现有文档内容|
| `Delete_Document` |删除文档|
## Markdown到DOCX的转换
这 `Create_Document_From_Markdown` 该工具使用以下命令将markdown或纯文本转换为.docx文件 潘多克。 并将其上传到SharePoint。
**参数:**
- `content` (必填)--要转换的Markdown或纯文本
- `folder_path` (必需)--SharePoint中的目标文件夹
- `file_name` (必填)--输出文件名(例如。 `report.docx`)
- `template_path` (可选)--SharePoint上用于样式设置的.docx模板的路径
**样式模板:** 在Word中创建一个具有所需样式(字体、标题、边距、颜色)的.docx文件,将其上传到SharePoint,然后将其引用为 `template_path`.Pandoc通过以下方式将模板中的样式应用于生成的文档 `--reference-doc`.
### 测试Markdown到DOCX工具
**先决条件:** 必须安装Pandoc。在Docker中,这是自动处理的。对于当地发展:```bash
# macOS
brew install pandoc
# Ubuntu/Debian
sudo apt-get install pandoc
# Verify
pandoc --version
测试1——基本转换(无模板):
使用MCP检查器:```bash
npx @modelcontextprotocol/inspector node dist/index.js
呼叫 `Create_Document_From_Markdown` 与:```json
{
"content": "# My Report\n\n## Introduction\n\nThis is a **test** document with:\n\n- Bullet point 1\n- Bullet point 2\n\n## Data\n\n| Name | Value |\n|------|-------|\n| A | 100 |\n| B | 200 |",
"folder_path": "Shared Documents",
"file_name": "test-report.docx"
}
然后验证 Get_Document_Content:```json
{
"file_path": "Shared Documents/test-report.docx"
}
**测试2——使用样式模板:**
1. 在Word中创建一个样式化的.docx模板(设置字体、标题样式、边距、颜色)
1. 上传到SharePoint(例如通过 `Upload_Document_From_Path` 或手动)
1. 呼叫 `Create_Document_From_Markdown` 使用模板:```json
{
"content": "# Styled Report\n\nThis document uses corporate styling.",
"folder_path": "Shared Documents",
"file_name": "styled-report.docx",
"template_path": "Templates/corporate-style.docx"
}
测试3——通过curl(HTTP传输):```bash
Initialize session
curl -s -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"test","version":"0.1.0"}}}'
Call the tool (use the mcp-session-id from the response headers above)
curl -s -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-H "mcp-session-id: " \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"Create_Document_From_Markdown","arguments":{"content":"# Hello World\n\nTest document.","folder_path":"Shared Documents","file_name":"curl-test.docx"}}}'
## 上传策略
- **文件\<=4MB**:简单PUT到 `/content` 端点
- **大于4MB的文件**:3.2MB块的可恢复上传会话
## 身份验证流程
### 客户端凭据(默认)
使用客户端ID+密钥进行应用级访问。最适合服务器到服务器场景。
### 代表(OBO)
通过交换用户令牌进行用户级访问。与HTTP传输一起使用,客户端发送 `Authorization: Bearer ` 头球
看 docs/azure setup.md 有关详细的Azure门户设置说明。
## 码头工人
编辑后 `.env` 使用您的凭据,构建并运行:```bash
docker compose up --build -d
服务器将在以下时间可用 http://localhost:3000/mcp.
更改源代码后,重建并重新启动(Docker构建在内部编译TypeScript):```bash
docker compose up --build -d
要查看日志,请执行以下操作:```bash
docker compose logs -f
发展```bash
npm run dev # Watch mode for TypeScript compilation
### MCP检验员测试```bash
npx @modelcontextprotocol/inspector node dist/index.js
