Back to MCP directory
publicPublicdnsLocal runtime

mcp-server-microsoft365-filesearch

一个基于MCP协议的服务器实现,提供Microsoft 365(SharePoint/OneDrive)中文件的高级搜索功能,支持文件内容检索、元数据分析和业务工作流集成。

article

README

🚀 MCP 服务器 - 微软 365 文件搜索( SharePoint 和 OneDrive)

本项目是一个模型上下文协议 (MCP) 服务器实现,可在 Microsoft 365 环境中进行高级文件搜索。它能高效实现文件发现、元数据分析,还可与业务流程集成,为用户提供来自 SharePoint/OneDrive 的内容。

🚀 快速开始

若要将服务器与 Claude Desktop 集成,请更新 claude_desktop_config.json

"mcpServers": {
  "M365 File Search (SharePoint/OneDrive)": {
    "command": "uv",
    "args": [
      "--directory",
      "full_path_to_parent_directory",
      "run",
      ".\\src\\mcp_m365_filesearch\\server.py"
    ],
    "env": {
      "CLIENT_ID": "MSGraph 客户端 ID",
      "CLIENT_SECRET": "MS Graph 客户端密钥",
      "TENANT_ID": "租户 ID",
      "REGION": "搜索区域"
    }
  }
}

✨ 主要特性

  • 提供高级文件搜索功能,可在 Microsoft 365 环境中高效进行文件发现和元数据分析。
  • 提供两个核心工具,方便进行文件搜索和内容检索。
  • 采用本地缓存机制,提高性能并减少冗余 API 调用。
  • 可与 Claude Desktop 集成,拓展使用场景。

📦 安装指南

要使用此服务器,您需要在 Azure 门户 中注册一个应用程序:

  1. 注册一个新的应用。
  2. 记录下 客户端 ID租户 ID
  3. 证书和密钥 下创建一个 客户端密钥
  4. API 权限 下,添加以下 委派或应用权限
    • Sites.Read.All
    • Files.Read.All
  5. 点击 授予管理员同意 这些权限。

确保这些值在 MCP 服务器的环境配置中正确设置。

💻 使用示例

基础用法

该服务器提供两个核心工具,以下是它们的使用示例:

search_m365_files

# 在 Microsoft 365 环境中执行文件搜索
# 输入:query (字符串):搜索词或条件
# 返回:文件元数据对象数组。元数据包括文件内容摘要、*驱动器 ID* 和 *文件 ID* 等详细信息
result = search_m365_files(query="example_query")

get_file_content

# 检索特定文件的内容
# 输入:
# - driveid (字符串):父驱动器的唯一标识符。
# - fileid (字符串):文件的唯一标识符。
# 返回:作为二进制流的文件内容
# 注意:使用本地缓存来加速重复访问
content = get_file_content(driveid="example_driveid", fileid="example_fileid")

高级用法

# 结合两个工具,先搜索文件,再获取文件内容
search_result = search_m365_files(query="example_query")
for file in search_result:
    driveid = file["driveid"]
    fileid = file["fileid"]
    content = get_file_content(driveid=driveid, fileid=fileid)
    # 对文件内容进行进一步处理

🔧 技术细节

组件

工具

该服务器提供两个核心工具:

  • search_m365_files:在 Microsoft 365 环境中执行文件搜索,输入搜索词或条件,返回文件元数据对象数组。
  • get_file_content:检索特定文件的内容,输入父驱动器的唯一标识符和文件的唯一标识符,返回作为二进制流的文件内容。使用本地缓存来加速重复访问。

缓存

为了提高性能并减少冗余 API 调用,服务器在本地缓存下载的文件。缓存文件存储在项目根目录下的 ./src/mcp_m365_filesearch/.local/downloads 目录中(相对路径)。当通过 get_file_content 请求文件时,服务器首先检查缓存,如果文件已缓存,则直接从磁盘返回而无需新的 API 调用。

与 Claude Desktop 集成

要将服务器与 Claude Desktop 集成,请更新 claude_desktop_config.json,配置相关的命令、参数和环境变量。

📄 许可证

此项目根据 MIT License 发布。您可以在自由地使用、修改和分发该项目,只需添加适当的引用即可。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client