mcpcn-office-powerpoint-mcp-server 2.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,290 @@
1
+ """
2
+ Professional design tools for PowerPoint MCP Server.
3
+ Handles themes, effects, fonts, and advanced formatting.
4
+ """
5
+ from typing import Dict, List, Optional, Any
6
+ from mcp.server.fastmcp import FastMCP
7
+ import utils as ppt_utils
8
+
9
+
10
+ def register_professional_tools(app: FastMCP, presentations: Dict, get_current_presentation_id):
11
+ """Register professional design tools with the FastMCP app"""
12
+
13
+ @app.tool()
14
+ def apply_professional_design(
15
+ operation: str, # "professional_slide", "theme", "enhance", "get_schemes"
16
+ slide_index: Optional[int] = None,
17
+ slide_type: str = "title_content",
18
+ color_scheme: str = "modern_blue",
19
+ title: Optional[str] = None,
20
+ content: Optional[List[str]] = None,
21
+ apply_to_existing: bool = True,
22
+ enhance_title: bool = True,
23
+ enhance_content: bool = True,
24
+ enhance_shapes: bool = True,
25
+ enhance_charts: bool = True,
26
+ presentation_id: Optional[str] = None
27
+ ) -> Dict:
28
+ """Unified professional design tool for themes, slides, and visual enhancements.
29
+ This applies professional styling and themes rather than structural layout changes."""
30
+ pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
31
+
32
+ if operation == "get_schemes":
33
+ # Return available color schemes
34
+ return ppt_utils.get_color_schemes()
35
+
36
+ if pres_id is None or pres_id not in presentations:
37
+ return {
38
+ "error": "No presentation is currently loaded or the specified ID is invalid"
39
+ }
40
+
41
+ pres = presentations[pres_id]
42
+
43
+ try:
44
+ if operation == "professional_slide":
45
+ # Add professional slide with advanced styling
46
+ if slide_index is not None and (slide_index < 0 or slide_index >= len(pres.slides)):
47
+ return {
48
+ "error": f"Invalid slide index: {slide_index}. Available slides: 0-{len(pres.slides) - 1}"
49
+ }
50
+
51
+ result = ppt_utils.add_professional_slide(
52
+ pres,
53
+ slide_type=slide_type,
54
+ color_scheme=color_scheme,
55
+ title=title,
56
+ content=content
57
+ )
58
+
59
+ return {
60
+ "message": f"Added professional {slide_type} slide",
61
+ "slide_index": len(pres.slides) - 1,
62
+ "color_scheme": color_scheme,
63
+ "slide_type": slide_type
64
+ }
65
+
66
+ elif operation == "theme":
67
+ # Apply professional theme
68
+ ppt_utils.apply_professional_theme(
69
+ pres,
70
+ color_scheme=color_scheme,
71
+ apply_to_existing=apply_to_existing
72
+ )
73
+
74
+ return {
75
+ "message": f"Applied {color_scheme} theme to presentation",
76
+ "color_scheme": color_scheme,
77
+ "applied_to_existing": apply_to_existing
78
+ }
79
+
80
+ elif operation == "enhance":
81
+ # Enhance existing slide
82
+ if slide_index is None:
83
+ return {
84
+ "error": "slide_index is required for enhance operation"
85
+ }
86
+
87
+ if slide_index < 0 or slide_index >= len(pres.slides):
88
+ return {
89
+ "error": f"Invalid slide index: {slide_index}. Available slides: 0-{len(pres.slides) - 1}"
90
+ }
91
+
92
+ slide = pres.slides[slide_index]
93
+ result = ppt_utils.enhance_existing_slide(
94
+ slide,
95
+ color_scheme=color_scheme,
96
+ enhance_title=enhance_title,
97
+ enhance_content=enhance_content,
98
+ enhance_shapes=enhance_shapes,
99
+ enhance_charts=enhance_charts
100
+ )
101
+
102
+ return {
103
+ "message": f"Enhanced slide {slide_index} with {color_scheme} scheme",
104
+ "slide_index": slide_index,
105
+ "color_scheme": color_scheme,
106
+ "enhancements_applied": result.get("enhancements_applied", [])
107
+ }
108
+
109
+ else:
110
+ return {
111
+ "error": f"Invalid operation: {operation}. Must be 'slide', 'theme', 'enhance', or 'get_schemes'"
112
+ }
113
+
114
+ except Exception as e:
115
+ return {
116
+ "error": f"Failed to apply professional design: {str(e)}"
117
+ }
118
+
119
+ @app.tool()
120
+ def apply_picture_effects(
121
+ slide_index: int,
122
+ shape_index: int,
123
+ effects: Dict[str, Dict], # {"shadow": {"blur_radius": 4.0, ...}, "glow": {...}}
124
+ presentation_id: Optional[str] = None
125
+ ) -> Dict:
126
+ """Apply multiple picture effects in combination."""
127
+ pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
128
+
129
+ if pres_id is None or pres_id not in presentations:
130
+ return {
131
+ "error": "No presentation is currently loaded or the specified ID is invalid"
132
+ }
133
+
134
+ pres = presentations[pres_id]
135
+
136
+ if slide_index < 0 or slide_index >= len(pres.slides):
137
+ return {
138
+ "error": f"Invalid slide index: {slide_index}. Available slides: 0-{len(pres.slides) - 1}"
139
+ }
140
+
141
+ slide = pres.slides[slide_index]
142
+
143
+ if shape_index < 0 or shape_index >= len(slide.shapes):
144
+ return {
145
+ "error": f"Invalid shape index: {shape_index}. Available shapes: 0-{len(slide.shapes) - 1}"
146
+ }
147
+
148
+ shape = slide.shapes[shape_index]
149
+
150
+ try:
151
+ applied_effects = []
152
+ warnings = []
153
+
154
+ # Apply each effect
155
+ for effect_type, effect_params in effects.items():
156
+ try:
157
+ if effect_type == "shadow":
158
+ ppt_utils.apply_picture_shadow(
159
+ shape,
160
+ shadow_type=effect_params.get("shadow_type", "outer"),
161
+ blur_radius=effect_params.get("blur_radius", 4.0),
162
+ distance=effect_params.get("distance", 3.0),
163
+ direction=effect_params.get("direction", 315.0),
164
+ color=effect_params.get("color", [0, 0, 0]),
165
+ transparency=effect_params.get("transparency", 0.6)
166
+ )
167
+ applied_effects.append("shadow")
168
+
169
+ elif effect_type == "reflection":
170
+ ppt_utils.apply_picture_reflection(
171
+ shape,
172
+ size=effect_params.get("size", 0.5),
173
+ transparency=effect_params.get("transparency", 0.5),
174
+ distance=effect_params.get("distance", 0.0),
175
+ blur=effect_params.get("blur", 4.0)
176
+ )
177
+ applied_effects.append("reflection")
178
+
179
+ elif effect_type == "glow":
180
+ ppt_utils.apply_picture_glow(
181
+ shape,
182
+ size=effect_params.get("size", 5.0),
183
+ color=effect_params.get("color", [0, 176, 240]),
184
+ transparency=effect_params.get("transparency", 0.4)
185
+ )
186
+ applied_effects.append("glow")
187
+
188
+ elif effect_type == "soft_edges":
189
+ ppt_utils.apply_picture_soft_edges(
190
+ shape,
191
+ radius=effect_params.get("radius", 2.5)
192
+ )
193
+ applied_effects.append("soft_edges")
194
+
195
+ elif effect_type == "rotation":
196
+ ppt_utils.apply_picture_rotation(
197
+ shape,
198
+ rotation=effect_params.get("rotation", 0.0)
199
+ )
200
+ applied_effects.append("rotation")
201
+
202
+ elif effect_type == "transparency":
203
+ ppt_utils.apply_picture_transparency(
204
+ shape,
205
+ transparency=effect_params.get("transparency", 0.0)
206
+ )
207
+ applied_effects.append("transparency")
208
+
209
+ elif effect_type == "bevel":
210
+ ppt_utils.apply_picture_bevel(
211
+ shape,
212
+ bevel_type=effect_params.get("bevel_type", "circle"),
213
+ width=effect_params.get("width", 6.0),
214
+ height=effect_params.get("height", 6.0)
215
+ )
216
+ applied_effects.append("bevel")
217
+
218
+ elif effect_type == "filter":
219
+ ppt_utils.apply_picture_filter(
220
+ shape,
221
+ filter_type=effect_params.get("filter_type", "none"),
222
+ intensity=effect_params.get("intensity", 0.5)
223
+ )
224
+ applied_effects.append("filter")
225
+
226
+ else:
227
+ warnings.append(f"Unknown effect type: {effect_type}")
228
+
229
+ except Exception as e:
230
+ warnings.append(f"Failed to apply {effect_type} effect: {str(e)}")
231
+
232
+ result = {
233
+ "message": f"Applied {len(applied_effects)} effects to shape {shape_index} on slide {slide_index}",
234
+ "applied_effects": applied_effects
235
+ }
236
+
237
+ if warnings:
238
+ result["warnings"] = warnings
239
+
240
+ return result
241
+
242
+ except Exception as e:
243
+ return {
244
+ "error": f"Failed to apply picture effects: {str(e)}"
245
+ }
246
+
247
+ @app.tool()
248
+ def manage_fonts(
249
+ operation: str, # "analyze", "optimize", "recommend"
250
+ font_path: str,
251
+ output_path: Optional[str] = None,
252
+ presentation_type: str = "business",
253
+ text_content: Optional[str] = None
254
+ ) -> Dict:
255
+ """Unified font management tool for analysis, optimization, and recommendations."""
256
+ try:
257
+ if operation == "analyze":
258
+ # Analyze font file
259
+ return ppt_utils.analyze_font_file(font_path)
260
+
261
+ elif operation == "optimize":
262
+ # Optimize font file
263
+ optimized_path = ppt_utils.optimize_font_for_presentation(
264
+ font_path,
265
+ output_path=output_path,
266
+ text_content=text_content
267
+ )
268
+
269
+ return {
270
+ "message": f"Optimized font: {font_path}",
271
+ "original_path": font_path,
272
+ "optimized_path": optimized_path
273
+ }
274
+
275
+ elif operation == "recommend":
276
+ # Get font recommendations
277
+ return ppt_utils.get_font_recommendations(
278
+ font_path,
279
+ presentation_type=presentation_type
280
+ )
281
+
282
+ else:
283
+ return {
284
+ "error": f"Invalid operation: {operation}. Must be 'analyze', 'optimize', or 'recommend'"
285
+ }
286
+
287
+ except Exception as e:
288
+ return {
289
+ "error": f"Failed to {operation} font: {str(e)}"
290
+ }
@@ -0,0 +1,373 @@
1
+ """
2
+ Structural element tools for PowerPoint MCP Server.
3
+ Handles tables, shapes, and charts.
4
+ """
5
+ from typing import Dict, List, Optional, Any
6
+ from mcp.server.fastmcp import FastMCP
7
+ import utils as ppt_utils
8
+
9
+
10
+ def register_structural_tools(app: FastMCP, presentations: Dict, get_current_presentation_id, validate_parameters, is_positive, is_non_negative, is_in_range, is_valid_rgb, add_shape_direct):
11
+ """Register structural element tools with the FastMCP app"""
12
+
13
+ @app.tool()
14
+ def add_table(
15
+ slide_index: int,
16
+ rows: int,
17
+ cols: int,
18
+ left: float,
19
+ top: float,
20
+ width: float,
21
+ height: float,
22
+ data: Optional[List[List[str]]] = None,
23
+ header_row: bool = True,
24
+ header_font_size: int = 12,
25
+ body_font_size: int = 10,
26
+ header_bg_color: Optional[List[int]] = None,
27
+ body_bg_color: Optional[List[int]] = None,
28
+ border_color: Optional[List[int]] = None,
29
+ presentation_id: Optional[str] = None
30
+ ) -> Dict:
31
+ """Add a table to a slide with enhanced formatting options."""
32
+ pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
33
+
34
+ if pres_id is None or pres_id not in presentations:
35
+ return {
36
+ "error": "No presentation is currently loaded or the specified ID is invalid"
37
+ }
38
+
39
+ pres = presentations[pres_id]
40
+
41
+ if slide_index < 0 or slide_index >= len(pres.slides):
42
+ return {
43
+ "error": f"Invalid slide index: {slide_index}. Available slides: 0-{len(pres.slides) - 1}"
44
+ }
45
+
46
+ slide = pres.slides[slide_index]
47
+
48
+ # Validate parameters
49
+ validations = {
50
+ "rows": (rows, [(is_positive, "must be a positive integer")]),
51
+ "cols": (cols, [(is_positive, "must be a positive integer")]),
52
+ "left": (left, [(is_non_negative, "must be non-negative")]),
53
+ "top": (top, [(is_non_negative, "must be non-negative")]),
54
+ "width": (width, [(is_positive, "must be positive")]),
55
+ "height": (height, [(is_positive, "must be positive")])
56
+ }
57
+
58
+ if header_bg_color is not None:
59
+ validations["header_bg_color"] = (header_bg_color, [(is_valid_rgb, "must be a valid RGB list [R, G, B] with values 0-255")])
60
+ if body_bg_color is not None:
61
+ validations["body_bg_color"] = (body_bg_color, [(is_valid_rgb, "must be a valid RGB list [R, G, B] with values 0-255")])
62
+ if border_color is not None:
63
+ validations["border_color"] = (border_color, [(is_valid_rgb, "must be a valid RGB list [R, G, B] with values 0-255")])
64
+
65
+ valid, error = validate_parameters(validations)
66
+ if not valid:
67
+ return {"error": error}
68
+
69
+ # Validate data if provided
70
+ if data:
71
+ if len(data) != rows:
72
+ return {
73
+ "error": f"Data has {len(data)} rows but table should have {rows} rows"
74
+ }
75
+ for i, row in enumerate(data):
76
+ if len(row) != cols:
77
+ return {
78
+ "error": f"Row {i} has {len(row)} columns but table should have {cols} columns"
79
+ }
80
+
81
+ try:
82
+ # Add the table
83
+ table_shape = ppt_utils.add_table(slide, rows, cols, left, top, width, height)
84
+ table = table_shape.table
85
+
86
+ # Populate with data if provided
87
+ if data:
88
+ for r in range(rows):
89
+ for c in range(cols):
90
+ if r < len(data) and c < len(data[r]):
91
+ table.cell(r, c).text = str(data[r][c])
92
+
93
+ # Apply formatting
94
+ for r in range(rows):
95
+ for c in range(cols):
96
+ cell = table.cell(r, c)
97
+
98
+ # Header row formatting
99
+ if r == 0 and header_row:
100
+ if header_bg_color:
101
+ ppt_utils.format_table_cell(
102
+ cell, bg_color=tuple(header_bg_color), font_size=header_font_size, bold=True
103
+ )
104
+ else:
105
+ ppt_utils.format_table_cell(cell, font_size=header_font_size, bold=True)
106
+ else:
107
+ # Body cell formatting
108
+ if body_bg_color:
109
+ ppt_utils.format_table_cell(
110
+ cell, bg_color=tuple(body_bg_color), font_size=body_font_size
111
+ )
112
+ else:
113
+ ppt_utils.format_table_cell(cell, font_size=body_font_size)
114
+
115
+ return {
116
+ "message": f"Added {rows}x{cols} table to slide {slide_index}",
117
+ "shape_index": len(slide.shapes) - 1,
118
+ "rows": rows,
119
+ "cols": cols
120
+ }
121
+ except Exception as e:
122
+ return {
123
+ "error": f"Failed to add table: {str(e)}"
124
+ }
125
+
126
+ @app.tool()
127
+ def format_table_cell(
128
+ slide_index: int,
129
+ shape_index: int,
130
+ row: int,
131
+ col: int,
132
+ font_size: Optional[int] = None,
133
+ font_name: Optional[str] = None,
134
+ bold: Optional[bool] = None,
135
+ italic: Optional[bool] = None,
136
+ color: Optional[List[int]] = None,
137
+ bg_color: Optional[List[int]] = None,
138
+ alignment: Optional[str] = None,
139
+ vertical_alignment: Optional[str] = None,
140
+ presentation_id: Optional[str] = None
141
+ ) -> Dict:
142
+ """Format a specific table cell."""
143
+ pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
144
+
145
+ if pres_id is None or pres_id not in presentations:
146
+ return {
147
+ "error": "No presentation is currently loaded or the specified ID is invalid"
148
+ }
149
+
150
+ pres = presentations[pres_id]
151
+
152
+ if slide_index < 0 or slide_index >= len(pres.slides):
153
+ return {
154
+ "error": f"Invalid slide index: {slide_index}. Available slides: 0-{len(pres.slides) - 1}"
155
+ }
156
+
157
+ slide = pres.slides[slide_index]
158
+
159
+ if shape_index < 0 or shape_index >= len(slide.shapes):
160
+ return {
161
+ "error": f"Invalid shape index: {shape_index}. Available shapes: 0-{len(slide.shapes) - 1}"
162
+ }
163
+
164
+ shape = slide.shapes[shape_index]
165
+
166
+ try:
167
+ if not hasattr(shape, 'table'):
168
+ return {
169
+ "error": f"Shape at index {shape_index} is not a table"
170
+ }
171
+
172
+ table = shape.table
173
+
174
+ if row < 0 or row >= len(table.rows):
175
+ return {
176
+ "error": f"Invalid row index: {row}. Available rows: 0-{len(table.rows) - 1}"
177
+ }
178
+
179
+ if col < 0 or col >= len(table.columns):
180
+ return {
181
+ "error": f"Invalid column index: {col}. Available columns: 0-{len(table.columns) - 1}"
182
+ }
183
+
184
+ cell = table.cell(row, col)
185
+
186
+ ppt_utils.format_table_cell(
187
+ cell,
188
+ font_size=font_size,
189
+ font_name=font_name,
190
+ bold=bold,
191
+ italic=italic,
192
+ color=tuple(color) if color else None,
193
+ bg_color=tuple(bg_color) if bg_color else None,
194
+ alignment=alignment,
195
+ vertical_alignment=vertical_alignment
196
+ )
197
+
198
+ return {
199
+ "message": f"Formatted cell at row {row}, column {col} in table at shape index {shape_index} on slide {slide_index}"
200
+ }
201
+ except Exception as e:
202
+ return {
203
+ "error": f"Failed to format table cell: {str(e)}"
204
+ }
205
+
206
+ @app.tool()
207
+ def add_shape(
208
+ slide_index: int,
209
+ shape_type: str,
210
+ left: float,
211
+ top: float,
212
+ width: float,
213
+ height: float,
214
+ fill_color: Optional[List[int]] = None,
215
+ line_color: Optional[List[int]] = None,
216
+ line_width: Optional[float] = None,
217
+ text: Optional[str] = None, # Add text to shape
218
+ font_size: Optional[int] = None,
219
+ font_color: Optional[List[int]] = None,
220
+ presentation_id: Optional[str] = None
221
+ ) -> Dict:
222
+ """Add an auto shape to a slide with enhanced options."""
223
+ pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
224
+
225
+ if pres_id is None or pres_id not in presentations:
226
+ return {
227
+ "error": "No presentation is currently loaded or the specified ID is invalid"
228
+ }
229
+
230
+ pres = presentations[pres_id]
231
+
232
+ if slide_index < 0 or slide_index >= len(pres.slides):
233
+ return {
234
+ "error": f"Invalid slide index: {slide_index}. Available slides: 0-{len(pres.slides) - 1}"
235
+ }
236
+
237
+ slide = pres.slides[slide_index]
238
+
239
+ try:
240
+ # Use the direct implementation that bypasses the enum issues
241
+ shape = add_shape_direct(slide, shape_type, left, top, width, height)
242
+
243
+ # Format the shape if formatting options are provided
244
+ if any([fill_color, line_color, line_width]):
245
+ ppt_utils.format_shape(
246
+ shape,
247
+ fill_color=tuple(fill_color) if fill_color else None,
248
+ line_color=tuple(line_color) if line_color else None,
249
+ line_width=line_width
250
+ )
251
+
252
+ # Add text to shape if provided
253
+ if text and hasattr(shape, 'text_frame'):
254
+ shape.text_frame.text = text
255
+ if font_size or font_color:
256
+ ppt_utils.format_text(
257
+ shape.text_frame,
258
+ font_size=font_size,
259
+ color=tuple(font_color) if font_color else None
260
+ )
261
+
262
+ return {
263
+ "message": f"Added {shape_type} shape to slide {slide_index}",
264
+ "shape_index": len(slide.shapes) - 1
265
+ }
266
+ except ValueError as e:
267
+ return {
268
+ "error": str(e)
269
+ }
270
+ except Exception as e:
271
+ return {
272
+ "error": f"Failed to add shape '{shape_type}': {str(e)}"
273
+ }
274
+
275
+ @app.tool()
276
+ def add_chart(
277
+ slide_index: int,
278
+ chart_type: str,
279
+ left: float,
280
+ top: float,
281
+ width: float,
282
+ height: float,
283
+ categories: List[str],
284
+ series_names: List[str],
285
+ series_values: List[List[float]],
286
+ has_legend: bool = True,
287
+ legend_position: str = "right",
288
+ has_data_labels: bool = False,
289
+ title: Optional[str] = None,
290
+ x_axis_title: Optional[str] = None,
291
+ y_axis_title: Optional[str] = None,
292
+ color_scheme: Optional[str] = None,
293
+ presentation_id: Optional[str] = None
294
+ ) -> Dict:
295
+ """Add a chart to a slide with comprehensive formatting options."""
296
+ pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
297
+
298
+ if pres_id is None or pres_id not in presentations:
299
+ return {
300
+ "error": "No presentation is currently loaded or the specified ID is invalid"
301
+ }
302
+
303
+ pres = presentations[pres_id]
304
+
305
+ if slide_index < 0 or slide_index >= len(pres.slides):
306
+ return {
307
+ "error": f"Invalid slide index: {slide_index}. Available slides: 0-{len(pres.slides) - 1}"
308
+ }
309
+
310
+ slide = pres.slides[slide_index]
311
+
312
+ # Validate chart type
313
+ valid_chart_types = [
314
+ 'column', 'stacked_column', 'bar', 'stacked_bar', 'line',
315
+ 'line_markers', 'pie', 'doughnut', 'area', 'stacked_area',
316
+ 'scatter', 'radar', 'radar_markers'
317
+ ]
318
+ if chart_type.lower() not in valid_chart_types:
319
+ return {
320
+ "error": f"Invalid chart type: '{chart_type}'. Valid types are: {', '.join(valid_chart_types)}"
321
+ }
322
+
323
+ # Validate series data
324
+ if len(series_names) != len(series_values):
325
+ return {
326
+ "error": f"Number of series names ({len(series_names)}) must match number of series values ({len(series_values)})"
327
+ }
328
+
329
+ if not categories:
330
+ return {
331
+ "error": "Categories list cannot be empty"
332
+ }
333
+
334
+ # Validate that all series have the same number of values as categories
335
+ for i, values in enumerate(series_values):
336
+ if len(values) != len(categories):
337
+ return {
338
+ "error": f"Series '{series_names[i]}' has {len(values)} values but there are {len(categories)} categories"
339
+ }
340
+
341
+ try:
342
+ # Add the chart
343
+ chart = ppt_utils.add_chart(
344
+ slide, chart_type, left, top, width, height,
345
+ categories, series_names, series_values
346
+ )
347
+
348
+ if chart is None:
349
+ return {"error": "Failed to create chart"}
350
+
351
+ # Format the chart
352
+ ppt_utils.format_chart(
353
+ chart,
354
+ has_legend=has_legend,
355
+ legend_position=legend_position,
356
+ has_data_labels=has_data_labels,
357
+ title=title,
358
+ x_axis_title=x_axis_title,
359
+ y_axis_title=y_axis_title,
360
+ color_scheme=color_scheme
361
+ )
362
+
363
+ return {
364
+ "message": f"Added {chart_type} chart to slide {slide_index}",
365
+ "shape_index": len(slide.shapes) - 1,
366
+ "chart_type": chart_type,
367
+ "series_count": len(series_names),
368
+ "categories_count": len(categories)
369
+ }
370
+ except Exception as e:
371
+ return {
372
+ "error": f"Failed to add chart: {str(e)}"
373
+ }