mcpcn-office-powerpoint-mcp-server 2.1.0__py3-none-any.whl → 2.1.2__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.
@@ -1,212 +1,212 @@
1
- """
2
- Presentation management tools for PowerPoint MCP Server.
3
- Handles presentation creation, opening, saving, and core properties.
4
- """
5
- from typing import Dict, List, Optional, Any
6
- import os
7
- from mcp.server.fastmcp import FastMCP
8
- import utils as ppt_utils
9
-
10
-
11
- def register_presentation_tools(app: FastMCP, presentations: Dict, get_current_presentation_id, get_template_search_directories):
12
- """Register presentation management tools with the FastMCP app"""
13
-
14
- @app.tool()
15
- def create_presentation(id: Optional[str] = None) -> Dict:
16
- """Create a new PowerPoint presentation."""
17
- # Create a new presentation
18
- pres = ppt_utils.create_presentation()
19
-
20
- # Generate an ID if not provided
21
- if id is None:
22
- id = f"presentation_{len(presentations) + 1}"
23
-
24
- # Store the presentation
25
- presentations[id] = pres
26
- # Set as current presentation (this would need to be handled by caller)
27
-
28
- return {
29
- "presentation_id": id,
30
- "message": f"Created new presentation with ID: {id}",
31
- "slide_count": len(pres.slides)
32
- }
33
-
34
- @app.tool()
35
- def create_presentation_from_template(template_path: str, id: Optional[str] = None) -> Dict:
36
- """Create a new PowerPoint presentation from a template file."""
37
- # Check if template file exists
38
- if not os.path.exists(template_path):
39
- # Try to find the template by searching in configured directories
40
- search_dirs = get_template_search_directories()
41
- template_name = os.path.basename(template_path)
42
-
43
- for directory in search_dirs:
44
- potential_path = os.path.join(directory, template_name)
45
- if os.path.exists(potential_path):
46
- template_path = potential_path
47
- break
48
- else:
49
- env_path_info = f" (PPT_TEMPLATE_PATH: {os.environ.get('PPT_TEMPLATE_PATH', 'not set')})" if os.environ.get('PPT_TEMPLATE_PATH') else ""
50
- return {
51
- "error": f"Template file not found: {template_path}. Searched in {', '.join(search_dirs)}{env_path_info}"
52
- }
53
-
54
- # Create presentation from template
55
- try:
56
- pres = ppt_utils.create_presentation_from_template(template_path)
57
- except Exception as e:
58
- return {
59
- "error": f"Failed to create presentation from template: {str(e)}"
60
- }
61
-
62
- # Generate an ID if not provided
63
- if id is None:
64
- id = f"presentation_{len(presentations) + 1}"
65
-
66
- # Store the presentation
67
- presentations[id] = pres
68
-
69
- return {
70
- "presentation_id": id,
71
- "message": f"Created new presentation from template '{template_path}' with ID: {id}",
72
- "template_path": template_path,
73
- "slide_count": len(pres.slides),
74
- "layout_count": len(pres.slide_layouts)
75
- }
76
-
77
- @app.tool()
78
- def open_presentation(file_path: str, id: Optional[str] = None) -> Dict:
79
- """Open an existing PowerPoint presentation from a file."""
80
- # Check if file exists
81
- if not os.path.exists(file_path):
82
- return {
83
- "error": f"File not found: {file_path}"
84
- }
85
-
86
- # Open the presentation
87
- try:
88
- pres = ppt_utils.open_presentation(file_path)
89
- except Exception as e:
90
- return {
91
- "error": f"Failed to open presentation: {str(e)}"
92
- }
93
-
94
- # Generate an ID if not provided
95
- if id is None:
96
- id = f"presentation_{len(presentations) + 1}"
97
-
98
- # Store the presentation
99
- presentations[id] = pres
100
-
101
- return {
102
- "presentation_id": id,
103
- "message": f"Opened presentation from {file_path} with ID: {id}",
104
- "slide_count": len(pres.slides)
105
- }
106
-
107
- @app.tool()
108
- def save_presentation(file_path: str, presentation_id: Optional[str] = None) -> Dict:
109
- """Save a presentation to a file."""
110
- # Use the specified presentation or the current one
111
- pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
112
-
113
- if pres_id is None or pres_id not in presentations:
114
- return {
115
- "error": "No presentation is currently loaded or the specified ID is invalid"
116
- }
117
-
118
- # Save the presentation
119
- try:
120
- saved_path = ppt_utils.save_presentation(presentations[pres_id], file_path)
121
- return {
122
- "message": f"Presentation saved to {saved_path}",
123
- "file_path": saved_path
124
- }
125
- except Exception as e:
126
- return {
127
- "error": f"Failed to save presentation: {str(e)}"
128
- }
129
-
130
- @app.tool()
131
- def get_presentation_info(presentation_id: Optional[str] = None) -> Dict:
132
- """Get information about a presentation."""
133
- pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
134
-
135
- if pres_id is None or pres_id not in presentations:
136
- return {
137
- "error": "No presentation is currently loaded or the specified ID is invalid"
138
- }
139
-
140
- pres = presentations[pres_id]
141
-
142
- try:
143
- info = ppt_utils.get_presentation_info(pres)
144
- info["presentation_id"] = pres_id
145
- return info
146
- except Exception as e:
147
- return {
148
- "error": f"Failed to get presentation info: {str(e)}"
149
- }
150
-
151
- @app.tool()
152
- def get_template_file_info(template_path: str) -> Dict:
153
- """Get information about a template file including layouts and properties."""
154
- # Check if template file exists
155
- if not os.path.exists(template_path):
156
- # Try to find the template by searching in configured directories
157
- search_dirs = get_template_search_directories()
158
- template_name = os.path.basename(template_path)
159
-
160
- for directory in search_dirs:
161
- potential_path = os.path.join(directory, template_name)
162
- if os.path.exists(potential_path):
163
- template_path = potential_path
164
- break
165
- else:
166
- return {
167
- "error": f"Template file not found: {template_path}. Searched in {', '.join(search_dirs)}"
168
- }
169
-
170
- try:
171
- return ppt_utils.get_template_info(template_path)
172
- except Exception as e:
173
- return {
174
- "error": f"Failed to get template info: {str(e)}"
175
- }
176
-
177
- @app.tool()
178
- def set_core_properties(
179
- title: Optional[str] = None,
180
- subject: Optional[str] = None,
181
- author: Optional[str] = None,
182
- keywords: Optional[str] = None,
183
- comments: Optional[str] = None,
184
- presentation_id: Optional[str] = None
185
- ) -> Dict:
186
- """Set core document properties."""
187
- pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
188
-
189
- if pres_id is None or pres_id not in presentations:
190
- return {
191
- "error": "No presentation is currently loaded or the specified ID is invalid"
192
- }
193
-
194
- pres = presentations[pres_id]
195
-
196
- try:
197
- ppt_utils.set_core_properties(
198
- pres,
199
- title=title,
200
- subject=subject,
201
- author=author,
202
- keywords=keywords,
203
- comments=comments
204
- )
205
-
206
- return {
207
- "message": "Core properties updated successfully"
208
- }
209
- except Exception as e:
210
- return {
211
- "error": f"Failed to set core properties: {str(e)}"
1
+ """
2
+ Presentation management tools for PowerPoint MCP Server.
3
+ Handles presentation creation, opening, saving, and core properties.
4
+ """
5
+ from typing import Dict, List, Optional, Any
6
+ import os
7
+ from mcp.server.fastmcp import FastMCP
8
+ import utils as ppt_utils
9
+
10
+
11
+ def register_presentation_tools(app: FastMCP, presentations: Dict, get_current_presentation_id, get_template_search_directories):
12
+ """Register presentation management tools with the FastMCP app"""
13
+
14
+ @app.tool()
15
+ def create_presentation(id: Optional[str] = None) -> Dict:
16
+ """Create a new PowerPoint presentation."""
17
+ # Create a new presentation
18
+ pres = ppt_utils.create_presentation()
19
+
20
+ # Generate an ID if not provided
21
+ if id is None:
22
+ id = f"presentation_{len(presentations) + 1}"
23
+
24
+ # Store the presentation
25
+ presentations[id] = pres
26
+ # Set as current presentation (this would need to be handled by caller)
27
+
28
+ return {
29
+ "presentation_id": id,
30
+ "message": f"Created new presentation with ID: {id}",
31
+ "slide_count": len(pres.slides)
32
+ }
33
+
34
+ @app.tool()
35
+ def create_presentation_from_template(template_path: str, id: Optional[str] = None) -> Dict:
36
+ """Create a new PowerPoint presentation from a template file."""
37
+ # Check if template file exists
38
+ if not os.path.exists(template_path):
39
+ # Try to find the template by searching in configured directories
40
+ search_dirs = get_template_search_directories()
41
+ template_name = os.path.basename(template_path)
42
+
43
+ for directory in search_dirs:
44
+ potential_path = os.path.join(directory, template_name)
45
+ if os.path.exists(potential_path):
46
+ template_path = potential_path
47
+ break
48
+ else:
49
+ env_path_info = f" (PPT_TEMPLATE_PATH: {os.environ.get('PPT_TEMPLATE_PATH', 'not set')})" if os.environ.get('PPT_TEMPLATE_PATH') else ""
50
+ return {
51
+ "error": f"Template file not found: {template_path}. Searched in {', '.join(search_dirs)}{env_path_info}"
52
+ }
53
+
54
+ # Create presentation from template
55
+ try:
56
+ pres = ppt_utils.create_presentation_from_template(template_path)
57
+ except Exception as e:
58
+ return {
59
+ "error": f"Failed to create presentation from template: {str(e)}"
60
+ }
61
+
62
+ # Generate an ID if not provided
63
+ if id is None:
64
+ id = f"presentation_{len(presentations) + 1}"
65
+
66
+ # Store the presentation
67
+ presentations[id] = pres
68
+
69
+ return {
70
+ "presentation_id": id,
71
+ "message": f"Created new presentation from template '{template_path}' with ID: {id}",
72
+ "template_path": template_path,
73
+ "slide_count": len(pres.slides),
74
+ "layout_count": len(pres.slide_layouts)
75
+ }
76
+
77
+ @app.tool()
78
+ def open_presentation(file_path: str, id: Optional[str] = None) -> Dict:
79
+ """Open an existing PowerPoint presentation from a file."""
80
+ # Check if file exists
81
+ if not os.path.exists(file_path):
82
+ return {
83
+ "error": f"File not found: {file_path}"
84
+ }
85
+
86
+ # Open the presentation
87
+ try:
88
+ pres = ppt_utils.open_presentation(file_path)
89
+ except Exception as e:
90
+ return {
91
+ "error": f"Failed to open presentation: {str(e)}"
92
+ }
93
+
94
+ # Generate an ID if not provided
95
+ if id is None:
96
+ id = f"presentation_{len(presentations) + 1}"
97
+
98
+ # Store the presentation
99
+ presentations[id] = pres
100
+
101
+ return {
102
+ "presentation_id": id,
103
+ "message": f"Opened presentation from {file_path} with ID: {id}",
104
+ "slide_count": len(pres.slides)
105
+ }
106
+
107
+ @app.tool()
108
+ def save_presentation(file_path: str, presentation_id: Optional[str] = None) -> Dict:
109
+ """Save a presentation to a file."""
110
+ # Use the specified presentation or the current one
111
+ pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
112
+
113
+ if pres_id is None or pres_id not in presentations:
114
+ return {
115
+ "error": "No presentation is currently loaded or the specified ID is invalid"
116
+ }
117
+
118
+ # Save the presentation
119
+ try:
120
+ saved_path = ppt_utils.save_presentation(presentations[pres_id], file_path)
121
+ return {
122
+ "message": f"Presentation saved to {saved_path}",
123
+ "file_path": saved_path
124
+ }
125
+ except Exception as e:
126
+ return {
127
+ "error": f"Failed to save presentation: {str(e)}"
128
+ }
129
+
130
+ @app.tool()
131
+ def get_presentation_info(presentation_id: Optional[str] = None) -> Dict:
132
+ """Get information about a presentation."""
133
+ pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
134
+
135
+ if pres_id is None or pres_id not in presentations:
136
+ return {
137
+ "error": "No presentation is currently loaded or the specified ID is invalid"
138
+ }
139
+
140
+ pres = presentations[pres_id]
141
+
142
+ try:
143
+ info = ppt_utils.get_presentation_info(pres)
144
+ info["presentation_id"] = pres_id
145
+ return info
146
+ except Exception as e:
147
+ return {
148
+ "error": f"Failed to get presentation info: {str(e)}"
149
+ }
150
+
151
+ @app.tool()
152
+ def get_template_file_info(template_path: str) -> Dict:
153
+ """Get information about a template file including layouts and properties."""
154
+ # Check if template file exists
155
+ if not os.path.exists(template_path):
156
+ # Try to find the template by searching in configured directories
157
+ search_dirs = get_template_search_directories()
158
+ template_name = os.path.basename(template_path)
159
+
160
+ for directory in search_dirs:
161
+ potential_path = os.path.join(directory, template_name)
162
+ if os.path.exists(potential_path):
163
+ template_path = potential_path
164
+ break
165
+ else:
166
+ return {
167
+ "error": f"Template file not found: {template_path}. Searched in {', '.join(search_dirs)}"
168
+ }
169
+
170
+ try:
171
+ return ppt_utils.get_template_info(template_path)
172
+ except Exception as e:
173
+ return {
174
+ "error": f"Failed to get template info: {str(e)}"
175
+ }
176
+
177
+ @app.tool()
178
+ def set_core_properties(
179
+ title: Optional[str] = None,
180
+ subject: Optional[str] = None,
181
+ author: Optional[str] = None,
182
+ keywords: Optional[str] = None,
183
+ comments: Optional[str] = None,
184
+ presentation_id: Optional[str] = None
185
+ ) -> Dict:
186
+ """Set core document properties."""
187
+ pres_id = presentation_id if presentation_id is not None else get_current_presentation_id()
188
+
189
+ if pres_id is None or pres_id not in presentations:
190
+ return {
191
+ "error": "No presentation is currently loaded or the specified ID is invalid"
192
+ }
193
+
194
+ pres = presentations[pres_id]
195
+
196
+ try:
197
+ ppt_utils.set_core_properties(
198
+ pres,
199
+ title=title,
200
+ subject=subject,
201
+ author=author,
202
+ keywords=keywords,
203
+ comments=comments
204
+ )
205
+
206
+ return {
207
+ "message": "Core properties updated successfully"
208
+ }
209
+ except Exception as e:
210
+ return {
211
+ "error": f"Failed to set core properties: {str(e)}"
212
212
  }