sharepoint-mcp-server
v1.0.3
Published
A Model Context Protocol (MCP) server for SharePoint Online content
Maintainers
Readme
SharePoint MCP Server and AI Chatbot
This project provides a Model Context Protocol (MCP) server for SharePoint Online and an AI-powered chatbot that can interact with SharePoint content.
Features
- List available SharePoint documents and pages
- Fetch and read document content from SharePoint
- Query SharePoint pages (ASPX)
- Search SharePoint content
- Summarize document paragraphs
- Convert Office documents to text
- Interactive AI chatbot interface
Prerequisites
- Node.js 16+ or Bun runtime
- SharePoint Online site
- Microsoft Graph API credentials
- OpenAI API key (for AI chatbot)
Setup
Install dependencies:
bun installConfigure environment variables:
# SharePoint/Microsoft Graph credentials export TENANT_ID="your-tenant-id" export CLIENT_ID="your-client-id" export CLIENT_SECRET="your-client-secret" export SITE_ID="your-sharepoint-site-id" # For AI Chatbot export OPENAI_API_KEY="your-openai-api-key"
Running the Application
IMPORTANT: Two-Step Process
The AI chatbot connects to the MCP server over HTTP, so you need to run them as separate processes:
Step 1: Start the HTTP server first:
bun run httpStep 2: In a separate terminal, start the AI chatbot:
bun run aiOther Run Options
Command-line chatbot (no AI):
bun run cliRun MCP server with stdio transport (for direct integration):
bun run stdio
Available Commands in AI Chatbot
list documents- Show all available SharePoint documentslist pages- Show all SharePoint pagessearch [query]- Search for content in SharePointdocument [id]- Get content of a specific documentpage [id]- Get content of a specific SharePoint pagesummarize [id]- Get a summary of document contentexitorquit- Exit the chatbot
Troubleshooting
- "No valid session ID provided" error: Make sure you're running the HTTP server (Step 1) before starting the AI chatbot (Step 2).
- OpenAI API errors: Check that your OPENAI_API_KEY is set correctly.
- SharePoint connection issues: Verify your Microsoft Graph credentials and site ID.
License
MIT
Available Resources
| Resource URI | Description |
|--------------|-------------|
| sharepoint://documents | Lists all documents in the root folder |
| sharepoint://document/{documentId} | Retrieves a specific document's content |
| sharepoint://pages | Lists all SharePoint pages |
| sharepoint://page/{pageId} | Retrieves a specific page's content |
Available Tools
| Tool Name | Parameters | Description |
|-----------|------------|-------------|
| search-sharepoint | { query: string } | Searches SharePoint content |
| summarize-content | { documentId: string, paragraphIndex?: number } | Summarizes document content or specific paragraphs |
| document-to-text | { documentId: string } | Converts Office documents to text |
Azure App Registration
- Register a new application in the Azure Portal
- Add the following API permissions:
- Microsoft Graph > Application permissions:
- Files.Read.All
- Sites.Read.All
- SharePoint > Application permissions:
- Sites.Read.All
- Microsoft Graph > Application permissions:
- Generate a client secret
- Grant admin consent for the permissions
Finding Your SharePoint Site ID
You can find your SharePoint site ID using the Microsoft Graph Explorer:
- Go to https://developer.microsoft.com/graph/graph-explorer
- Sign in with your Microsoft 365 account
- Make a GET request to:
/sites/{domain}:/sites/{site-name}Example:/sites/contoso.sharepoint.com:/sites/marketing - The response will include your site ID
Usage with AI Models
Example: Using with a model like Claude or GPT
- Connect your AI client to this MCP server
- List available documents:
- Request the
sharepoint://documentsresource
- Request the
- Read a specific document:
- Request the
sharepoint://document/{documentId}resource
- Request the
- Search for content:
- Call the
search-sharepointtool with a query parameter
- Call the
- Summarize a document:
- Call the
summarize-contenttool with a documentId parameter
- Call the
Example: Flow for Document Summarization
1. AI: "I need to find documents about marketing strategy"
2. User: "Let me help you search SharePoint"
3. [AI calls search-sharepoint tool with query="marketing strategy"]
4. AI: "I found a marketing plan document. Let me get its content"
5. [AI requests the sharepoint://document/{documentId} resource]
6. AI: "Here's a summary of the marketing plan..."
7. User: "Can you focus on the first quarter strategy?"
8. [AI calls summarize-content tool with documentId and paragraphIndex parameters]Architecture
This MCP server uses:
- Microsoft Graph API: To interact with SharePoint Online
- Azure Identity: For authentication with Microsoft services
- MCP SDK: To implement the Model Context Protocol
- Two transport options:
- StdioServerTransport: For direct integration with AI clients
- StreamableHTTPServerTransport: For remote access over HTTP
Extending the Server
You can extend this server by:
- Adding more resources in
index.tsorhttp-server.ts - Implementing additional tools for specific SharePoint operations
- Supporting more document types and extraction methods
