返回市场
幻灯片-MCP

幻灯片-MCP

作者:samos12325 星标更新:2025-05-20

项目介绍

PPTX MCP Server

这是一个由FastMCP驱动的服务器,用于程序化地创建、编辑和渲染PowerPoint(PPTX)演示文稿。支持幻灯片创建、文本和形状插入、图片嵌入以及将幻灯片渲染为PNG图像(使用LibreOffice)。

功能

  • 创建/清除演示文稿: 开始新的或重置现有的PPTX文件。
  • 添加幻灯片: 插入具有可定制布局的幻灯片。
  • 文本与内容: 向幻灯片中添加标题、内容和自定义文本框。
  • 形状: 插入各种PowerPoint形状(包括流程图元素)。
  • 图片: 将图片嵌入到幻灯片中。
  • 幻灯片描述: 获取幻灯片内容的文字摘要以供验证。
  • 幻灯片渲染: 将幻灯片渲染为PNG图像(需要LibreOffice)。
  • 下载PPTX: 下载生成的演示文稿文件。

要求

安装

  1. 安装Python依赖项:

    pip install .
    

    (从pyproject.toml安装依赖项)

  2. 可选:安装python-dotenv以设置开发环境变量:

    pip install python-dotenv
    
  3. 安装LibreOffice(用于图像渲染):

    • Linux: sudo pacman -S libreoffice-freshsudo apt install libreoffice
    • macOS: brew install --cask libreoffice
    • Windows: 从libreoffice.org下载

使用方法

启动服务器:

python server.py

对于带有环境变量的开发:

您可以使用环境变量设置服务器的主机和端口:

  • HOST(默认:127.0.0.1
  • PORT(默认:8000

例如,要在所有接口上运行并使用端口9000:

HOST=0.0.0.0 PORT=9000 python server.py

或者

在项目根目录下创建或编辑.env文件: 例如,要在所有接口上运行并使用端口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/中添加自己的模板。

许可证

详情见LICENSE