article
README
🚀 PPTX MCP 服务器
PPTX MCP 服务器是一个基于 FastMCP 的服务器,可用于以编程方式创建、编辑和渲染 PowerPoint (PPTX) 演示文稿。它支持幻灯片创建、文本和形状插入、图片嵌入,还能将幻灯片渲染为 PNG 图像(借助 LibreOffice),功能强大且实用。
🚀 快速开始
启动服务器:
python server.py
你可以通过环境变量设置服务器的主机和端口:
HOST(默认:127.0.0.1)PORT(默认:8000)
例如,要在所有接口上运行并使用 9000 端口:
HOST=0.0.0.0 PORT=9000 python server.py
或(用于开发环境中的 FastMCP):
fastmcp dev server.py
✨ 主要特性
- 创建/清除演示文稿:启动新的或重置现有 PPTX 文件。
- 添加幻灯片:插入具有自定义布局的幻灯片。
- 文本与内容:在幻灯片中添加标题、内容和自定义文本框。
- 形状:插入多种多样的 PowerPoint 形状(包括流程图元素)。
- 图片:将图片嵌入到幻灯片中。
- 幻灯片描述:获取幻灯片内容的文字摘要以进行验证。
- 幻灯片渲染:将幻灯片渲染为 PNG 图像(需要 LibreOffice)。
- 下载 PPTX:下载生成的演示文稿文件。
📦 安装指南
安装 Python 依赖
pip install -r requirements.txt
(或查看 pyproject.toml 获取依赖信息)
安装 LibreOffice(用于图像渲染)
- Linux:
sudo pacman -S libreoffice-fresh或sudo apt install libreoffice - macOS:
brew install --cask libreoffice - Windows:从 libreoffice.org 下载
💻 使用示例
基础用法
# 启动服务器
python server.py
高级用法
# 在所有接口上运行并使用 9000 端口
HOST=0.0.0.0 PORT=9000 python server.py
# 用于开发环境中的 FastMCP
fastmcp dev server.py
📚 详细文档
API 概览
服务器通过 FastMCP 提供工具和资源,包括:
create_or_clear_presentation(filename)add_slide(filename, layout_index)add_title_and_content(filename, slide_index, title, content)add_textbox(filename, slide_index, text, left_inches, top_inches, width_inches, height_inches, font_size_pt, bold)add_shape(filename, slide_index, shape_type_name, left_inches, top_inches, width_inches, height_inches, text)add_picture(filename, slide_index, image, left_inches, top_inches, width_inches, height_inches)get_slide_content_description(filename, slide_index)get_slide_image(filename, slide_index)(需要 LibreOffice)get_pptx_file(filename)
参见代码获取完整参数细节和可用的形状类型。
演示文稿与模板
- 演示文稿保存在
presentations/目录中。 - 你可以在
presentations/templates/中添加自己的模板。
🔧 技术细节
需求
- Python 3.12+
- python-pptx
- Pillow
- FastMCP
- LibreOffice(用于幻灯片图像渲染;需单独安装并确保系统 PATH 中可用)
Scan to contact