本项目展示了如何借助 MCP(模型完成协议)搭建一个具备 PowerPoint 自动化功能的服务器,为用户提供便捷的演示文稿自动化操作体验。
你可以通过以下链接查看项目演示: 演示链接
要运行服务器,可使用以下命令:
uv run --directory /path/to/mcp-ppt-server mcp-ppt-server
该服务器公开了多种用于 PowerPoint 自动化的工具,可通过 MCP 调用。服务器设计为一次仅处理一个活动演示文稿,从而简化 API,无需跟踪和指定演示文稿 ID。
initialize_powerpoint(): 初始化 PowerPoint 自动化create_presentation(): 创建一个新的演示文稿open_presentation(file_path): 从指定路径打开现有演示文稿get_presentation(): 获取当前活动演示文稿的信息save_presentation(path=None): 将活动演示文稿保存到磁盘(如果之前已保存,路径可选)close_presentation(): 关闭当前活动演示文稿get_slides(): 获取活动演示文稿中所有幻灯片的列表add_slide(layout_index=1): 添加一张新幻灯片(指定布局,默认为标题和内容)
set_slide_title(slide_index, title): 设置幻灯片的标题文本get_slide_text(slide_index): 获取幻灯片中的所有文本内容get_slide_shapes(slide_index): 获取幻灯片中所有形状及其 ID 和属性update_text(slide_index, shape_index, text): 更新形状的文本内容update_shape_by_id(slide_index, shape_id, text=None, left=None, top=None, width=None, height=None): 通过 ID 更新形状属性(可选参数包括文本、左、上、宽、高)update_table_cell(slide_index, shape_index, row, col, text): 更新表格中的单元格文本add_textbox(slide_index, text, left=1, top=1, width=4, height=2): 在幻灯片中添加文本框add_image(slide_index, image_path, left=1, top=1, width=None, height=None): 在幻灯片中添加图片add_table(slide_index, shape_index, rows, cols, text): 在幻灯片中添加表格(参数包括行数、列数和文本内容)add_chart(slide_index, chart_type, data): 在幻灯片中添加图表(参数包括图表类型和数据)如果发生错误,服务器将返回一个包含以下键的字典:
error_code: 错误代码error_message: 错误消息traceback: 调用栈信息示例错误响应:
{
"error_code": 500,
"error_message": "Internal Server Error",
"traceback": "Traceback (most recent call last):
...
"
}
以下是一个 MCP 配置的示例:
{
"server": {
"host": "localhost",
"port": 8000,
"debug": true
},
"database": {
"uri": "mongodb://localhost:27017",
"name": "mcp_ppt"
}
}