Skip to main content

Office4AI

Python Version License: MIT Version

Office4AI 是一个 MCP Server,让 AI Agent 通过 Office Add-In 实时读写 Office 文档。

当前状态: Word(9 个工具)已实现,PowerPoint 和 Excel 开发中。

支持平台

平台 状态 工具数
Word 已就绪 9
PowerPoint 规划中 —
Excel 规划中 —

快速开始

1. 安装证书(仅首次)

Office4AI 使用 HTTPS 与 Office Add-In 通信。运行 setup 生成并安装本地 CA 证书:

uvx office4ai-mcp setup

将生成本地 CA 和服务器证书,并将 CA 安装到系统信任存储(需要管理员权限)。

2. 启动服务

uvx office4ai-mcp serve

3. 配置 MCP 客户端

Claude Code(推荐)

claude mcp add office4ai -- uvx --from office4ai office4ai-mcp

Claude Desktop / Cursor 等 MCP 客户端

在 MCP 配置文件中添加:

{
  "mcpServers": {
    "office4ai": {
      "command": "uvx",
      "args": ["office4ai-mcp", "serve"]
    }
  }
}

4. 安装 Office Add-In

Office Add-In 通过 Socket.IO 连接 Microsoft Office 与 MCP Server。

Add-In 安装说明将另行提供,敬请关注。

可用工具

Word 工具(9 个)

工具 说明
word_get_selected_content 获取当前选中内容——文本、元素及元数据
word_get_visible_content 获取当前视口中可见的内容
word_insert_text 在光标处插入文本,支持格式(粗体、斜体、字体、颜色、样式)
word_append_text 在文档开头或末尾追加文本
word_replace_text 查找并替换文本(等同 Ctrl+H),支持大小写敏感和全词匹配
word_insert_image 插入 base64 编码的图片,支持尺寸和替代文字
word_insert_table 插入表格,指定行列数、数据和样式
word_insert_equation 插入 LaTeX 公式(默认为行内公式)
word_insert_toc 插入目录(可配置标题级别)

所有工具均需要 document_uri 参数来标识目标文档。

CLI 命令参考

office4ai-mcp <command>
命令 说明
serve 启动 MCP Server(未指定命令时的默认行为)
setup 生成证书并将 CA 安装到系统信任存储
cleanup 从信任存储移除 CA 并删除证书文件

服务器选项

可通过 CLI 参数或环境变量设置:

选项 环境变量 默认值 说明
--transport TRANSPORT stdio MCP 传输方式:stdio、sse 或 streamable-http
--host HOST 127.0.0.1 服务器绑定地址
--port PORT 8000 MCP HTTP 端口(用于 sse/streamable-http)
--socketio-port SOCKETIO_PORT 3000 Socket.IO 端口(Add-In 连接)

证书位置

证书默认存储在 ~/.office4ai/certs/,可通过 OFFICE4AI_CERT_DIR 环境变量覆盖。

日志位置

日志默认存储在平台标准目录,可通过 OFFICE4AI_LOG_DIR 环境变量覆盖:

平台 默认路径
macOS ~/Library/Logs/office4ai
Linux ~/.local/state/office4ai/log
Windows C:\Users\<user>\AppData\Local\office4ai\Logs

设置 OFFICE4AI_LOG_DIR="" 可禁用文件日志。

系统要求

  • Python 3.10+
  • macOS 或 Windows
  • 支持 Add-In 的 Microsoft Office(Word 桌面版或 Word Online)

开发

开发环境配置、常用命令、代码规范和贡献指南请参考 docs/CONTRIBUTING.md。

许可证

MIT 许可证 - 详见 LICENSE。

联系方式

Metadata

Release files for office4ai 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for office4ai 0.2.0
File Size Uploaded Provenance
office4ai-0.2.0.tar.gz 595.5 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for office4ai 0.2.0
File Interpreter ABI Platform
office4ai-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 711.4 kB

Release files / office4ai-0.2.0.tar.gz

Download URL office4ai-0.2.0.tar.gz
Size 595.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b1a92a24a04c9a36933db0016b4c4dd9bb332674e863d5dc406f98db60f6c72f
BLAKE2b-256 checksum
How to use checksums
710f45e01a195960e458dfde3bcdf722b12fba54d620c2d94b69c8bf362677ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.

Transparency log

Release files / office4ai-0.2.0-py3-none-any.whl

Download URL office4ai-0.2.0-py3-none-any.whl
Size 115.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bdd2caedb8bdf16efe52ebeee2524c5e2de01a2d621b80ac82d23319b59aedd
BLAKE2b-256 checksum
How to use checksums
4ddbe29817a21e4a62e6649fade4a2102f7862803500e3d426dfb29774021a89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.

Transparency log

Security for office4ai 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for office4ai-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page