PptxGenJS MCP服务器
一种模型上下文协议(MCP)服务器,使用以下命令提供全面的PowerPoint演示文稿创建功能 PptxGenJS该服务器通过LLM友好的界面公开PptxGenJS的整个功能集。
特性
此MCP服务器提供以下工具:
- 展示管理:使用自定义布局、元数据和属性创建演示文稿
- 滑动操作:添加带有背景、部分和自定义布局的幻灯片
- 文本内容:添加具有丰富样式选项(字体、颜色、对齐方式、项目符号等)的格式化文本
- 形状:插入各种形状,包括矩形、圆形、箭头、流程图元素等
- 图像:从URL、本地路径或base64数据添加图像
- 图像搜索:通过SearXNG搜索图像并自动将其添加到幻灯片中
- 表格:创建具有自定义样式、边框和单元格属性的格式化表格
- HTML表格导入:导入HTML表格并将其转换为保留样式的PowerPoint表格
- 图表:生成各种图表类型(条形图、折线图、饼图、面积图、散点图、气泡图、雷达图、甜甜圈图)
- 演讲者备注:将演示者备注添加到幻灯片中
- 批量操作:在单个操作中添加包含多个内容项的幻灯片,以提高效率
- 幻灯片母版模板:定义和重用幻灯片模板,以实现一致的演示文稿设计
- PPTX模板:将现有的PPTX文件转换为JSON模板,并使用动态内容替换从中创建新的演示文稿
- 出口:将演示文稿保存为文件或导出为base64/二进制数据
安装
地方发展
npm install
npm run buildCloudflare员工部署
此MCP服务器还可以部署到Cloudflare Workers,用于基于云的操作,并使用R2存储进行演示。看 CLOUDFLARE_DEPLOYMENT.md 有关详细的设置说明。
快速启动:
npm install -g wrangler
wrangler login
wrangler r2 bucket create pptx
npm run deploy用法
使用克劳德桌面(本地)
将此添加到您的Claude Desktop配置文件中:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"pptxgenjs": {
"command": "node",
"args": ["/path/to/pptxgenjs-mcp/dist/index.js"]
}
}
}使用MCP客户端
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
const transport = new StdioClientTransport({
command: "node",
args: ["/path/to/pptxgenjs-mcp/dist/index.js"]
});
const client = new Client({
name: "example-client",
version: "1.0.0"
}, {
capabilities: {}
});
await client.connect(transport);可用工具
展示管理
create_presentation
创建新的PowerPoint演示文稿。
参数:
presentationId(可选):演示文稿的自定义IDlayout(可选):布局类型(“Layout_4x3”、“Layout_16x9”、“Layout_16x10”和“Layout_WIDE”)author(可选):作者姓名company(可选):公司名称title(可选):演示文稿标题subject(可选):演示主题rtlMode(可选):启用从右向左模式
退货: 用于后续操作的演示ID
list_presentations
列出内存中所有活动的演示文稿。
define_layout
创建具有特定尺寸的自定义幻灯片布局。
参数:
presentationId:演示文稿IDname:版面名称(例如“A4”)width:宽度(英寸)height:高度(英寸)
滑动操作
add_slide
在演示文稿中添加新幻灯片。
参数:
presentationId:演示文稿IDbackgroundColor(可选):6位十六进制颜色(例如“FF0000”)backgroundImage(可选):图像路径或base64数据
add_section
添加一个命名部分来组织幻灯片。
参数:
presentationId:演示文稿IDtitle:章节标题
内容工具
add_text
为当前幻灯片添加格式丰富的文本。
参数:
presentationId:演示文稿IDtext:文本内容(文本对象的字符串或数组)x,y,w,h:位置和大小(英寸或百分比)fontSize:字体大小(以点为单位)fontFace:字体系列名称color:文本颜色(6位十六进制)bold,italic,underline:文本样式align:水平对齐(“左”、“中”、“右”、“对齐”)valign:垂直对齐(“顶部”、“中部”、“底部”)bullet:启用项目符号lineSpacing:行距乘数
add_shape
向当前幻灯片添加形状。
参数:
presentationId:演示文稿IDshape:形状类型(例如,“矩形”、“椭圆形”、“圆形矩形”、”三角形“、”右箭头“、”星形“)x,y,w,h:位置和尺寸fill:填充配置(颜色、透明度)line:边框配置(颜色、宽度、dashType)
支持的形状包括:
- 基本:矩形、椭圆形、三角形、菱形、星形、心形、云形
- 箭头:右箭头、左箭头、上箭头、下箭头、弯曲箭头
- 流程图:流程图、流程图决策、流程图文档等。
- 还有更多。..
add_image
将图像添加到当前幻灯片。
参数:
presentationId:演示文稿IDpath或data:图像源(URL、本地路径或base64)x,y,w,h:位置和尺寸sizing:尺寸选项(包含、覆盖、裁剪)hyperlink:添加可点击链接rounding:圆角transparency:图像透明度(0-100)
search_and_add_image
通过SearXNG搜索图像,并可选择将其添加到演示幻灯片中。
参数:
query:图像搜索查询(例如,“中世纪城堡建筑”、“工业革命工厂”)maxResults(可选):返回的最大结果数(默认值:10)presentationId(可选):要添加图像的演示文稿ID(如果autoAdd为true,则为必填项)slideIndex(可选):图像放置的目标幻灯片索引(从0开始,如果没有提供,则使用最后一张幻灯片)position(可选):具有属性的对象的位置和大小:
- x, y:位置单位为英寸或百分比 - w, h:宽度和高度,单位为英寸或百分比
autoAdd(可选):如果为true,则自动将第一个搜索结果添加到指定的幻灯片中(默认值:false)
退货:
results:图像搜索结果数组description和sourceUrladdedToSlide(当autoAdd为true时):有关添加的图像的信息,包括presentationId,slideIndex,imageUrl,以及description
示例:
仅搜索:
await callTool("search_and_add_image", {
query: "medieval castle architecture",
maxResults: 5
});搜索和自动添加:
await callTool("search_and_add_image", {
query: "Industrial Revolution factory",
presentationId: "pres_123",
slideIndex: 2,
position: { x: 5, y: 2, w: 4, h: 3 },
autoAdd: true
});add_table
添加具有可自定义样式的表格。
参数:
presentationId:演示文稿IDrows:行数组(每行是单元格数组)x,y,w,h:位置和尺寸colW:列宽数组rowH:行高数组fontSize,fontFace,color:默认文本样式fill:默认单元格背景颜色border:默认单元格边框
每个单元格可以是:
- 一个简单的字符串
- 一个物体
text和options用于单个细胞造型
add_chart
将图表添加到当前幻灯片中。
参数:
presentationId:演示文稿IDtype:图表类型(“条形”、“bar3D”、“直线”、“饼状”、“面积”、“散点”、“气泡”、“雷达”、“甜甜圈”)data:数据序列数组(每个序列都有名称、标签、值)x,y,w,h:位置和尺寸title:图表标题showLabel,showLegend,showTitle,showValue:显示选项legendPos:图例位置('b'、't'、'l'、'r'、'tr')barDir:条形图方向(“Bar”、“col”)barGrouping:分组风格(“聚类”、“堆叠”、“百分比堆叠”)catAxisTitle,valAxisTitle:轴标题
add_notes
在当前幻灯片中添加演讲者备注。
参数:
presentationId:演示文稿IDnotes:注释文本
高级工具
import_html_table
导入HTML表格并将其转换为PowerPoint表格。自动保留样式,包括粗体、斜体、颜色、对齐方式、colspan和rowspan。
参数:
presentationId:演示文稿IDhtml:HTML表标记(应包括 `` 标签)x,y,w,h:位置和大小(英寸或百分比)fontSize(可选):单元格的默认字体大小border(可选):默认边框配置
例子:
await callTool("import_html_table", {
presentationId: "pres_1",
html: `
Header
Data
`,
x: 1,
y: 1.5,
w: 8,
h: 3
});add_slide_with_content
在一次操作中添加包含多个内容项(文本、形状、图像、表格、图表)的新幻灯片。比多个单独的呼叫更有效。
参数:
presentationId:演示文稿IDbackgroundColor(可选):幻灯片背景颜色backgroundImage(可选):背景图像配置content:内容项数组,每个都有type(“文本”、“形状”、“图像”、“表格”、“图表”)以及data(参数与单个工具相同)
例子:
await callTool("add_slide_with_content", {
presentationId: "pres_1",
backgroundColor: "F8F9FA",
content: [
{
type: "text",
data: { text: "Title", x: 1, y: 0.5, w: 8, h: 0.75, fontSize: 32, bold: true }
},
{
type: "shape",
data: { shape: "ellipse", x: 2, y: 2, w: 2, h: 2, fill: { color: "3498DB" } }
}
]
});define_slide_master
定义一个具有预定义布局和样式的可重用幻灯片母版模板,以实现一致的演示设计。
参数:
masterId:幻灯片母版的唯一标识符name:人类可读的名称(例如,“标题幻灯片”、“内容幻灯片”)backgroundColor(可选):默认背景颜色backgroundImage(可选):默认背景图像placeholders:占位符定义数组id,type、位置和样式
例子:
await callTool("define_slide_master", {
masterId: "title-slide",
name: "Title Slide",
backgroundColor: "1A1A2E",
placeholders: [
{
id: "title",
type: "text",
x: 1, y: 2, w: 8, h: 1.5,
fontSize: 44, bold: true, align: "center", color: "FFFFFF"
}
]
});add_slide_from_master
基于预定义的幻灯片母版模板添加新幻灯片。
参数:
presentationId:演示文稿IDmasterId:要应用的幻灯片母版IDplaceholderContent(可选):对象,占位符ID作为键,内容作为值
例子:
await callTool("add_slide_from_master", {
presentationId: "pres_1",
masterId: "title-slide",
placeholderContent: {
title: { text: "My Presentation Title" }
}
});list_slide_masters
列出所有已定义的幻灯片母版。
退货: 幻灯片母版及其ID、名称和占位符计数的数组。
模板工具
模板系统允许您将现有的PPTX演示文稿转换为可重用的JSON模板。这些模板保留了原始演示文稿的布局、样式和结构,同时允许在创建新演示文稿时进行动态内容替换。
convert_pptx_to_template
将现有的PPTX文件转换为JSON模板格式。
参数:
filePath:要转换的PPTX文件的路径
退货: 带有幻灯片结构和元素的JSON模板数据
例子:
const result = await callTool("convert_pptx_to_template", {
filePath: "/path/to/template.pptx"
});
// Returns templateData that can be savedsave_template
保存包含元数据的JSON模板以供以后使用。
参数:
templateData:JSON模板数据(来自convert_pptx_to_template或自定义)templateId(可选):模板的自定义ID(如果未提供,则自动生成)name(可选):模板的人类可读名称description(可选):模板用途的描述
退货: 模板ID和元数据
例子:
await callTool("save_template", {
templateId: "quarterly-report",
templateData: convertedData,
name: "Quarterly Report Template",
description: "Standard template for quarterly business reports"
});list_templates
列出所有已保存的模板及其元数据。
退货: 包含ID、名称、描述、幻灯片计数和创建日期的模板数组
例子:
const result = await callTool("list_templates", {});
// Returns: { templates: [...], count: N }load_template
按ID加载已保存的模板以检查或修改它。
参数:
templateId:要加载的模板的ID
退货: 包含数据和元数据的完整模板对象
delete_template
按ID删除已保存的模板。
参数:
templateId:要删除的模板的ID
create_from_template
使用可选的内容替换从保存的模板创建新的演示文稿。
参数:
templateId:要使用的模板的IDcontentMapping(可选):将元素标识符映射到替换内容的对象
内容映射格式: 这 contentMapping 对象允许您替换模板元素中的内容。密钥可以是:
- 元件位置:
"slide_0_element_1"(幻灯片索引、元素索引) - 元素名称:原始演示文稿中元素的名称
值是具有基于元素类型的属性的对象:
- 文本/形状元素:
{ text: "New text content" } - 图像元素:
{ path: "url/or/path" }或{ data: "base64..." } - 表元素:
{ rows: [[...]] } - 图表元素:
{ chartType: "bar", data: [...] }
退货: 新演示文稿ID
例子:
await callTool("create_from_template", {
templateId: "quarterly-report",
contentMapping: {
"slide_0_element_0": { text: "Q1 2025 Report" },
"slide_1_element_2": { text: "Revenue: $52.8M" },
"Company Logo": { path: "https://example.com/logo.png" },
}
});完整工作流示例:
// 1. Create and save a template presentation
const pres = await callTool("create_presentation", { layout: "LAYOUT_16x9" });
// ... add slides and content ...
await callTool("save_presentation", {
presentationId: pres.presentationId,
fileName: "template.pptx"
});
// 2. Convert to template
const converted = await callTool("convert_pptx_to_template", {
filePath: "template.pptx"
});
// 3. Save as reusable template
await callTool("save_template", {
templateId: "my-template",
templateData: converted.templateData,
name: "My Template"
});
// 4. Create presentations from template
await callTool("create_from_template", {
templateId: "my-template",
contentMapping: {
"slide_0_element_0": { text: "Custom Title" }
}
});导出工具
save_presentation
将演示文稿保存到文件。
参数:
presentationId:演示文稿IDfileName:输出文件名(应以.pptx结尾)compression(可选):启用压缩以减小文件大小
export_presentation
将演示文稿导出为base64或其他格式。
参数:
presentationId:演示文稿IDoutputType:格式类型('base64'、'arraybuffer'、'blob'、'nodebuffer'、'uint8array')
示例用法
以下是创建演示文稿的示例工作流:
// 1. Create a presentation
const createResult = await callTool("create_presentation", {
layout: "LAYOUT_16x9",
title: "My Presentation",
author: "John Doe"
});
const presentationId = createResult.presentationId;
// 2. Add a title slide
await callTool("add_slide", { presentationId });
await callTool("add_text", {
presentationId,
text: "Welcome to My Presentation",
x: 1,
y: 2,
w: 8,
h: 1.5,
fontSize: 44,
bold: true,
align: "center"
});
// 3. Add a content slide with bullet points
await callTool("add_slide", {
presentationId,
backgroundColor: "F0F0F0"
});
await callTool("add_text", {
presentationId,
text: "Key Points",
x: 0.5,
y: 0.5,
w: 9,
h: 0.75,
fontSize: 32,
bold: true
});
await callTool("add_text", {
presentationId,
text: "First point\nSecond point\nThird point",
x: 0.5,
y: 1.5,
w: 9,
h: 3,
fontSize: 20,
bullet: true
});
// 4. Add a chart slide
await callTool("add_slide", { presentationId });
await callTool("add_chart", {
presentationId,
type: "bar",
data: [
{
name: "Sales",
labels: ["Q1", "Q2", "Q3", "Q4"],
values: [15, 28, 35, 42]
}
],
x: 1,
y: 1.5,
w: 8,
h: 4,
title: "Quarterly Sales",
showLegend: true
});
// 5. Add a slide with an image from search
await callTool("add_slide", { presentationId });
await callTool("add_text", {
presentationId,
text: "Historical Context",
x: 0.5,
y: 0.5,
w: 9,
h: 0.75,
fontSize: 32,
bold: true
});
// Search and add an image automatically
await callTool("search_and_add_image", {
query: "industrial revolution historical photo",
presentationId,
maxResults: 5,
position: { x: 1.5, y: 1.5, w: 7, h: 4 },
autoAdd: true
});
// 6. Save the presentation
await callTool("save_presentation", {
presentationId,
fileName: "output.pptx",
compression: true
});发展
# Build the project
npm run build
# Watch mode for development
npm run watch
# Start the server
npm start
# Test template features
node test-templates.cjs这 test-templates.cjs 脚本演示了完整的模板工作流:
- 创建示例演示文稿
- 将其另存为PPTX文件
- 将PPTX转换为JSON模板
- 保存模板以供重用
- 从具有不同内容的模板创建多个演示文稿
- 管理和检查模板
许可证
国际协调委员会
鸣谢
此MCP服务器使用:
- PptxGenJS PowerPoint生成功能
- pptxtojson 用于将PPTX文件转换为JSON模板
