MCP Server: SharePoint and OneDrive File Search
Search Microsoft 365 files in SharePoint and OneDrive with MCP server to retrieve PDF/DOCX documents, presentations, spreadsheets, and images.
npx -y @godwin3737/mcp-server-microsoft365-filesearchOverview
This MCP (Model Context Protocol) server provides a simple bridge between LLMs and Microsoft 365 file storage (SharePoint and OneDrive). It lets developers expose a searchable, protocol-compatible tool that returns matching documents (PDF, DOCX), spreadsheets, presentations, and common image formats. The server is designed to be used as a tool endpoint for LLMs that support MCP or tool-calling, enabling retrieval-augmented workflows and contextual document lookup.
Why this is useful: instead of manually crawling or building your own SharePoint/OneDrive integration, this server handles authentication against Microsoft Graph, file-type filtering, and a lightweight search API that returns references and content snippets (or file downloads). It’s optimized for developer integration into conversational agents, knowledge workers, and automated document processing pipelines.
Features
- Search SharePoint and OneDrive using Microsoft Graph search APIs
- Return results for PDFs, DOCX, PPTX, XLSX and common image formats
- MCP-compatible tool descriptions for use with tool-aware LLMs
- Pagination and simple ranking / snippet extraction
- Authentication via Azure app registration (OAuth client credentials)
- Lightweight JSON API suitable for wrapping in chains or tool calls
Installation / Configuration
Prerequisites:
- Node.js (14+)
- An Azure AD application with Microsoft Graph permissions to access SharePoint and OneDrive (Files.Read.All or Sites.Read.All)
- Clone and install dependencies
- Configure environment variables
Create a .env file in the project root (or set env vars in your host). Required variables:
PORT=8080
AZURE_TENANT_ID=your-tenant-id
AZURE_CLIENT_ID=your-client-id
AZURE_CLIENT_SECRET=your-client-secret
ALLOWED_SITE_IDS=site-id-1,site-id-2 # optional: comma-separated SharePoint site IDs to restrict search
MAX_RESULTS=50 # optional: limit results per request
Table: Key environment variables
| Variable | Description |
|---|---|
| AZURE_TENANT_ID | Azure AD tenant ID for your Microsoft 365 organization |
| AZURE_CLIENT_ID | Azure AD application (client) ID |
| AZURE_CLIENT_SECRET | Client secret for the Azure AD app |
| ALLOWED_SITE_IDS | Optional comma-separated site IDs to restrict search scope |
| PORT | Server port to listen on (default 8080) |
- Start the server
# or
The server starts on the configured port and exposes MCP-compatible endpoints.
Available Tools / Resources
The server exposes a small set of HTTP endpoints and MCP tool descriptions to integrate with LLMs.
GET /mcp/tools
- Returns a JSON array of MCP tool descriptions (name, input schema, description).
- Typical tool: “microsoftFilesSearch” — accepts a text query and optional filters (fileType, siteId, top).
POST /search
- Payload: { “query”: “contract renewal”, “fileTypes”: [“pdf”,“docx”], “siteId”: “…” , “top”: 10 }
- Returns: list of results with metadata: { id, name, fileType, url, snippet, lastModified }
GET /download/:itemId
- Returns direct file stream for a given Microsoft Graph item id (requires auth and ACLs).
Example /search request:
POST /search
Content-Type: application/json
{
"query": "yearly financial report",
"fileTypes": ["xlsx", "pdf"],
"top": 5
}
Example response (trimmed):
Use Cases
Conversational enterprise assistant
- Integrate the MCP tool into an LLM agent so users can ask “Show me the latest contract with Contoso” and the model calls the microsoftFilesSearch tool, retrieves matching DOCX/PDF files, and includes file snippets in the response.
Retrieval-augmented generation (RAG)
- Use the server to fetch relevant document contents (or snippets) for RAG pipelines. The agent queries /search, downloads top documents, and constructs a context window for the LLM to answer questions grounded in company documents.
Content discovery dashboard
- Build a UI that calls the /search endpoint to populate search results with previews, file type icons, and download links for users who need quick access to shared files across SharePoint and OneDrive.
Automated processing pipelines
- Use the API to locate newly uploaded or updated spreadsheets/presentations and trigger downstream ETL, analysis, or indexing workflows.
Notes and Best Practices
- Permissions: Run with least privilege — grant only the Graph API permissions you need (prefer Sites.Read.All or Files.Read.All for read-only scenarios).
- Rate limits: Microsoft Graph enforces throttling. Implement retries and backoff for large-scale search workloads.
- Security: Host the server behind your application firewall and restrict access to trusted clients or internal networks. Validate or restrict ALLOWED_SITE_IDS to prevent broad data exposure.
- Snippets & privacy: Snippet extraction can reveal content; ensure your usage complies with data handling and compliance requirements.
For developer reference, use the /mcp/tools endpoint to programmatically discover the tool schema and integrate the server into tool-enabled LLM frameworks.