mcp-onedrive-sharepoint
Enables file and site management across OneDrive and SharePoint via Microsoft Graph API, with support for 33 tools and a CLI.
README
MCP OneDrive/SharePoint Server
MCP server for Microsoft Graph focused on OneDrive, SharePoint and related document workflows. Device-code or client-credentials auth, 33 tools, also usable as a standalone ods CLI for shell scripting.
Onboarding commands on a clean clone:
npm run buildnpm run lintnpm testnpm run cinpm run setup-auth
What is implemented
The server exposes 33 MCP tools grouped into:
- Files:
list_files,download_file,upload_file,create_folder,move_item,delete_item,search_files,get_file_metadata,share_item,copy_item - SharePoint:
discover_sites,resolve_site,list_site_lists,get_list_schema,list_items,get_list_item,create_list_item,update_list_item,delete_list_item - Utilities:
health_check,get_user_profile,list_drives,global_search,batch_operations - Advanced:
advanced_share,manage_permissions,check_user_access,sync_folder,batch_file_operations,storage_analytics,version_management,excel_operations,excel_analysis
Recent foundation improvements
This version includes real structural improvements instead of documentation-only changes:
- fixed
npm run setup-authto call the real TypeScript auth setup flow - added working ESLint configuration
- added executable tests with Node's built-in test runner
- aligned README and
.env.examplewith the real environment variables and scripts - introduced reusable Graph helpers for:
- consistent MCP JSON/error envelopes
- pagination extraction from Microsoft Graph responses
- resolving OneDrive/SharePoint resources by
driveId,siteId,itemIdand path
- updated key listing/search flows to return pagination metadata and support
driveId
Requirements
- Node.js 18+
- A Microsoft Entra ID / Azure AD app registration. Two auth modes are supported:
- Device-code (default): Public client registration with Delegated permissions (
Files.ReadWrite.All,Sites.ReadWrite.All,User.Read,offline_access). No client secret needed. - Client credentials: Confidential client registration with Application permissions (
Files.ReadWrite.All,Sites.ReadWrite.All). RequiresMICROSOFT_GRAPH_CLIENT_SECRET/SP_CLIENT_SECRETin env and admin consent in Azure AD.MICROSOFT_GRAPH_TENANT_IDmust be a specific tenant UUID —commondoes not work with this flow.
- Device-code (default): Public client registration with Delegated permissions (
Installation
git clone https://github.com/ftaricano/mcp-onedrive-sharepoint.git
cd mcp-onedrive-sharepoint
npm install
cp .env.example .env
Operational wrappers
Important operational rule:
- use this MCP on demand
- do not keep it permanently bound/loaded in Hermes or Claude Code when not needed
- prefer one-shot
spcall/mcporter --stdioexecution so the process exits right after the call and does not accumulate zombie or idle MCP processes - the
spcallwrapper includes post-call cleanup for stray repo-local MCP child processes
This repo includes lightweight wrappers for local operational use:
./scripts/run-stdio.sh: start the MCP stdio server with the repo-local.envloaded safely./scripts/spcall.sh: run ad-hocmcportercalls against the local MCP servernpm run stdio: same as./scripts/run-stdio.shnpm run spcall -- <tool> ...: same as./scripts/spcall.sh <tool> ...
Quick examples:
npm run build
./scripts/spcall.sh health_check
./scripts/spcall.sh list_drives
./scripts/spcall.sh list_files driveId=b!abc123 path=/Shared%20Documents
Tenant-specific site aliases and drive ids are loaded from a local file — see Site registry below.
CLI (ods)
Every MCP tool is also exposed as a plain subcommand through the ods CLI. It shares the same auth, config and handlers as the MCP server, so anything the MCP does is one-shot runnable from a terminal or a shell script.
npm run build
ods list # list all tools with descriptions
ods schema list_files # print JSON schema for a tool
ods auth # interactive device-code login
ods <tool> --key=value [--key value] # invoke a tool with CLI flags
ods <tool> --json '{"k":"v"}' # pass the full payload as JSON
During development you can skip the build with npm run cli -- <tool> ....
Examples
ods health_check
ods list_files --site=primary --path=/
ods list_files --driveId=b!abc --path=/Shared%20Documents --limit=50
ods upload_file --json '{"driveId":"b!abc","path":"/x.txt","content":"hello"}'
Rules for flags
--key=valueand--key valueare both accepted.true/false/nulland numeric strings are coerced automatically; anything else stays a string.- Bare flags (no value, or followed by another flag) become
true. --json '<payload>'takes a JSON object; individual--key=valueflags layered on top override fields from the payload. Use this for tools with nested objects/arrays (e.g. advanced Excel tools).- Output is the raw tool payload (usually pretty-printed JSON). If the handler returns an error envelope, the process exits with code
2.
Configuration
The server reads the following environment variables:
MICROSOFT_GRAPH_CLIENT_ID=your_app_client_id
MICROSOFT_GRAPH_TENANT_ID=your_tenant_uuid # use specific UUID for client-credentials; "common" works only for device-code
MICROSOFT_GRAPH_CLIENT_SECRET= # optional — activates client-credentials mode; alias SP_CLIENT_SECRET also accepted
MICROSOFT_GRAPH_SCOPES=Files.ReadWrite.All,Sites.ReadWrite.All,Directory.Read.All,User.Read,offline_access
MICROSOFT_GRAPH_BASE_URL=https://graph.microsoft.com/v1.0
MICROSOFT_GRAPH_TIMEOUT=30000
MICROSOFT_GRAPH_MAX_RETRIES=3
MICROSOFT_GRAPH_CACHE_ENABLED=true
MICROSOFT_GRAPH_CACHE_TTL=3600
Notes:
- use
MICROSOFT_GRAPH_TENANT_ID=commonfor multi-tenant/device-code onboarding - use a specific tenant id if you want tenant-scoped sign-in
- delegated scopes are what the current auth flow uses
Authentication modes
Client credentials (recommended for automation)
Set MICROSOFT_GRAPH_CLIENT_SECRET (or the alias SP_CLIENT_SECRET) in the environment. When either variable is present, the server authenticates as the app identity — no user login, no token expiry issue, no Keychain MSAL cache needed.
# In .env or via cpz_keychain_env.sh / Keychain:
MICROSOFT_GRAPH_CLIENT_ID=your_app_client_id
MICROSOFT_GRAPH_TENANT_ID=your_tenant_uuid # must be specific UUID, not "common"
MICROSOFT_GRAPH_CLIENT_SECRET=your_client_secret
The app registration in Azure AD must use Application permissions (not Delegated) with admin consent granted.
Device code (interactive, default fallback)
When no clientSecret is present, the server falls back to delegated device-code flow. On first use:
npm run setup-auth
The script reads MICROSOFT_GRAPH_CLIENT_ID / MICROSOFT_GRAPH_TENANT_ID from .env, starts the device-code login, and stores the resulting MSAL token in the macOS Keychain (service mcp-onedrive-sharepoint, accounts access_token and msal_token_cache).
Token maintenance: the MSAL refresh token is valid for 90 days of inactivity. If the server is not used for several days, re-run npm run setup-auth to renew. To clear stale tokens:
security delete-generic-password -s "mcp-onedrive-sharepoint" -a "access_token"
security delete-generic-password -s "mcp-onedrive-sharepoint" -a "msal_token_cache"
Development commands
npm run build
npm run lint
npm test
npm run ci
npm start
npm run stdio
npm run spcall -- health_check
npm run ci is the local verification entrypoint and is also what GitHub Actions runs on every PR/push.
MCP behavior notes
Root site inclusion
discover_sites.includePersonalSite=true currently attempts to append the tenant root SharePoint site (/sites/root) when it is available to the authenticated user.
It does not discover or synthesize a personal OneDrive site.
Pagination
The following tools now expose consistent pagination metadata in their JSON payloads:
list_filessearch_filesdiscover_siteslist_site_listslist_items
When Microsoft Graph returns @odata.nextLink, the response includes:
pagination.returnedpagination.limitpagination.totalCountwhen availablepagination.nextPageTokenpagination.hasMore
Pass pageToken back to the same tool to continue paging.
Drive/site targeting
Core file listing/search/download flows now accept:
siteIdfor a SharePoint site's default drivedriveIdfor a specific document library or drive- path-based addressing where supported
This is the current foundation for moving beyond a /me/drive-only model.
Site registry
The resolver can target named SharePoint sites by alias (e.g. site=primary). The registry is loaded from an external JSON file so no tenant-specific ids are committed:
- Copy
config/sites.example.jsontoconfig/sites.local.json(gitignored) and fill in your values. - Or set
MCP_SITES_CONFIG_PATHto point at a different JSON file. - If the file is missing, the registry stays empty and the tools only accept explicit
siteId,siteUrl, ordriveId.
Each site entry looks like:
{
"key": "primary",
"name": "Primary",
"siteId": "yourtenant.sharepoint.com,<guid>,<guid>",
"siteUrl": "https://yourtenant.sharepoint.com/sites/Primary",
"driveId": "b!<drive-id>",
"aliases": ["primary", "/sites/Primary"]
}
MCP stdio snippet
Use the wrapper as the MCP command so the repo-local .env is loaded automatically:
{
"mcpServers": {
"sharepoint": {
"command": "/absolute/path/to/mcp-onedrive-sharepoint/scripts/run-stdio.sh"
}
}
}
Example tool inputs
List files from a specific drive
{
"driveId": "b!abc123",
"path": "/Shared Documents",
"limit": 50
}
Continue a paginated file listing
{
"driveId": "b!abc123",
"pageToken": "https://graph.microsoft.com/v1.0/drives/b!abc123/root/children?$skiptoken=..."
}
Search files in a site drive
{
"siteId": "contoso.sharepoint.com,123,456",
"query": "quarterly report",
"limit": 25
}
List SharePoint list items with pagination
{
"siteId": "contoso.sharepoint.com,123,456",
"listId": "9c6b8b70-0000-0000-0000-111111111111",
"orderBy": "Created desc",
"limit": 100
}
Troubleshooting
invalid_grant/AADSTSon first run: token store is empty or expired. Runnpm run setup-authagain.403 Forbiddenon SharePoint lists/drives: the signed-in user lacks permission to the target site. Check with the site owner.404on adriveIdorsiteId: the identifier is stale or the resource was deleted. Uselist_drives/discover_sitesto re-discover.- Build fails on a clean clone: make sure Node.js is 18+ and run
npm installbeforenpm run build. AADSTS700016or401with client credentials: ensureMICROSOFT_GRAPH_TENANT_IDis a specific tenant UUID (notcommon) and that Application permissions have admin consent in Azure AD.AADSTS7000215(invalid client secret): the secret has expired or was deleted in Azure AD. Rotate it in the app registration and updateMICROSOFT_GRAPH_CLIENT_SECRET.- Silent token refresh failed / device-code prompt in automated run: token cache in Keychain is stale. Either set
MICROSOFT_GRAPH_CLIENT_SECRETto switch to client-credentials mode (no expiry), or clear the Keychain entries above and re-runnpm run setup-auth.
Security
This server handles Microsoft Graph OAuth tokens and delegated access to corporate file storage. Treat it accordingly:
.env,tokens.json,credentials.jsonand the OS keychain entries are never committed — see .gitignore.- Report security issues privately via GitHub security advisories — do not open a public issue.
- If a token leaks, revoke it from Azure AD → Enterprise Applications → your app → Users & groups and re-run
npm run setup-auth.
Contributing
Issues and PRs welcome. Before opening a PR:
npm run cipasses (build + lint + tests)- one focused change per PR
- no credentials, tenant-specific ids, or internal paths in commits or README
License
MIT © Fernando Taricano
Current limitations
- in device-code mode, authentication requires an interactive login on first use and periodic renewal; in client-credentials mode the flow is fully non-interactive but requires Application permissions and admin consent in Azure AD
- only the most critical listing/search flows use the pagination/resource helpers; other tools still use direct endpoint construction
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。