mcpcn-office-powerpoint-mcp-server 2.1.1__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.
tools/hyperlink_tools.py CHANGED
@@ -1,138 +1,138 @@
1
- """
2
- Hyperlink management tools for PowerPoint MCP Server.
3
- Implements hyperlink operations for text shapes and runs.
4
- """
5
-
6
- from typing import Dict, List, Optional, Any
7
-
8
- def register_hyperlink_tools(app, presentations, get_current_presentation_id, validate_parameters,
9
- is_positive, is_non_negative, is_in_range, is_valid_rgb):
10
- """Register hyperlink management tools with the FastMCP app."""
11
-
12
- @app.tool()
13
- def manage_hyperlinks(
14
- operation: str,
15
- slide_index: int,
16
- shape_index: int = None,
17
- text: str = None,
18
- url: str = None,
19
- run_index: int = 0,
20
- presentation_id: str = None
21
- ) -> Dict:
22
- """
23
- Manage hyperlinks in text shapes and runs.
24
-
25
- Args:
26
- operation: Operation type ("add", "remove", "list", "update")
27
- slide_index: Index of the slide (0-based)
28
- shape_index: Index of the shape on the slide (0-based)
29
- text: Text to make into hyperlink (for "add" operation)
30
- url: URL for the hyperlink
31
- run_index: Index of text run within the shape (0-based)
32
- presentation_id: Optional presentation ID (uses current if not provided)
33
-
34
- Returns:
35
- Dictionary with operation results
36
- """
37
- try:
38
- # Get presentation
39
- pres_id = presentation_id or get_current_presentation_id()
40
- if pres_id not in presentations:
41
- return {"error": "Presentation not found"}
42
-
43
- pres = presentations[pres_id]
44
-
45
- # Validate slide index
46
- if not (0 <= slide_index < len(pres.slides)):
47
- return {"error": f"Slide index {slide_index} out of range"}
48
-
49
- slide = pres.slides[slide_index]
50
-
51
- if operation == "list":
52
- # List all hyperlinks in the slide
53
- hyperlinks = []
54
- for shape_idx, shape in enumerate(slide.shapes):
55
- if hasattr(shape, 'text_frame') and shape.text_frame:
56
- for para_idx, paragraph in enumerate(shape.text_frame.paragraphs):
57
- for run_idx, run in enumerate(paragraph.runs):
58
- if run.hyperlink.address:
59
- hyperlinks.append({
60
- "shape_index": shape_idx,
61
- "paragraph_index": para_idx,
62
- "run_index": run_idx,
63
- "text": run.text,
64
- "url": run.hyperlink.address
65
- })
66
-
67
- return {
68
- "message": f"Found {len(hyperlinks)} hyperlinks on slide {slide_index}",
69
- "hyperlinks": hyperlinks
70
- }
71
-
72
- # For other operations, validate shape index
73
- if shape_index is None or not (0 <= shape_index < len(slide.shapes)):
74
- return {"error": f"Shape index {shape_index} out of range"}
75
-
76
- shape = slide.shapes[shape_index]
77
-
78
- # Check if shape has text
79
- if not hasattr(shape, 'text_frame') or not shape.text_frame:
80
- return {"error": "Shape does not contain text"}
81
-
82
- if operation == "add":
83
- if not text or not url:
84
- return {"error": "Both 'text' and 'url' are required for adding hyperlinks"}
85
-
86
- # Add new text run with hyperlink
87
- paragraph = shape.text_frame.paragraphs[0]
88
- run = paragraph.add_run()
89
- run.text = text
90
- run.hyperlink.address = url
91
-
92
- return {
93
- "message": f"Added hyperlink '{text}' -> '{url}' to shape {shape_index}",
94
- "text": text,
95
- "url": url
96
- }
97
-
98
- elif operation == "update":
99
- if not url:
100
- return {"error": "URL is required for updating hyperlinks"}
101
-
102
- # Update existing hyperlink
103
- paragraphs = shape.text_frame.paragraphs
104
- if run_index < len(paragraphs[0].runs):
105
- run = paragraphs[0].runs[run_index]
106
- old_url = run.hyperlink.address
107
- run.hyperlink.address = url
108
-
109
- return {
110
- "message": f"Updated hyperlink from '{old_url}' to '{url}'",
111
- "old_url": old_url,
112
- "new_url": url,
113
- "text": run.text
114
- }
115
- else:
116
- return {"error": f"Run index {run_index} out of range"}
117
-
118
- elif operation == "remove":
119
- # Remove hyperlink from specific run
120
- paragraphs = shape.text_frame.paragraphs
121
- if run_index < len(paragraphs[0].runs):
122
- run = paragraphs[0].runs[run_index]
123
- old_url = run.hyperlink.address
124
- run.hyperlink.address = None
125
-
126
- return {
127
- "message": f"Removed hyperlink '{old_url}' from text '{run.text}'",
128
- "removed_url": old_url,
129
- "text": run.text
130
- }
131
- else:
132
- return {"error": f"Run index {run_index} out of range"}
133
-
134
- else:
135
- return {"error": f"Unsupported operation: {operation}. Use 'add', 'remove', 'list', or 'update'"}
136
-
137
- except Exception as e:
1
+ """
2
+ Hyperlink management tools for PowerPoint MCP Server.
3
+ Implements hyperlink operations for text shapes and runs.
4
+ """
5
+
6
+ from typing import Dict, List, Optional, Any
7
+
8
+ def register_hyperlink_tools(app, presentations, get_current_presentation_id, validate_parameters,
9
+ is_positive, is_non_negative, is_in_range, is_valid_rgb):
10
+ """Register hyperlink management tools with the FastMCP app."""
11
+
12
+ @app.tool()
13
+ def manage_hyperlinks(
14
+ operation: str,
15
+ slide_index: int,
16
+ shape_index: int = None,
17
+ text: str = None,
18
+ url: str = None,
19
+ run_index: int = 0,
20
+ presentation_id: str = None
21
+ ) -> Dict:
22
+ """
23
+ Manage hyperlinks in text shapes and runs.
24
+
25
+ Args:
26
+ operation: Operation type ("add", "remove", "list", "update")
27
+ slide_index: Index of the slide (0-based)
28
+ shape_index: Index of the shape on the slide (0-based)
29
+ text: Text to make into hyperlink (for "add" operation)
30
+ url: URL for the hyperlink
31
+ run_index: Index of text run within the shape (0-based)
32
+ presentation_id: Optional presentation ID (uses current if not provided)
33
+
34
+ Returns:
35
+ Dictionary with operation results
36
+ """
37
+ try:
38
+ # Get presentation
39
+ pres_id = presentation_id or get_current_presentation_id()
40
+ if pres_id not in presentations:
41
+ return {"error": "Presentation not found"}
42
+
43
+ pres = presentations[pres_id]
44
+
45
+ # Validate slide index
46
+ if not (0 <= slide_index < len(pres.slides)):
47
+ return {"error": f"Slide index {slide_index} out of range"}
48
+
49
+ slide = pres.slides[slide_index]
50
+
51
+ if operation == "list":
52
+ # List all hyperlinks in the slide
53
+ hyperlinks = []
54
+ for shape_idx, shape in enumerate(slide.shapes):
55
+ if hasattr(shape, 'text_frame') and shape.text_frame:
56
+ for para_idx, paragraph in enumerate(shape.text_frame.paragraphs):
57
+ for run_idx, run in enumerate(paragraph.runs):
58
+ if run.hyperlink.address:
59
+ hyperlinks.append({
60
+ "shape_index": shape_idx,
61
+ "paragraph_index": para_idx,
62
+ "run_index": run_idx,
63
+ "text": run.text,
64
+ "url": run.hyperlink.address
65
+ })
66
+
67
+ return {
68
+ "message": f"Found {len(hyperlinks)} hyperlinks on slide {slide_index}",
69
+ "hyperlinks": hyperlinks
70
+ }
71
+
72
+ # For other operations, validate shape index
73
+ if shape_index is None or not (0 <= shape_index < len(slide.shapes)):
74
+ return {"error": f"Shape index {shape_index} out of range"}
75
+
76
+ shape = slide.shapes[shape_index]
77
+
78
+ # Check if shape has text
79
+ if not hasattr(shape, 'text_frame') or not shape.text_frame:
80
+ return {"error": "Shape does not contain text"}
81
+
82
+ if operation == "add":
83
+ if not text or not url:
84
+ return {"error": "Both 'text' and 'url' are required for adding hyperlinks"}
85
+
86
+ # Add new text run with hyperlink
87
+ paragraph = shape.text_frame.paragraphs[0]
88
+ run = paragraph.add_run()
89
+ run.text = text
90
+ run.hyperlink.address = url
91
+
92
+ return {
93
+ "message": f"Added hyperlink '{text}' -> '{url}' to shape {shape_index}",
94
+ "text": text,
95
+ "url": url
96
+ }
97
+
98
+ elif operation == "update":
99
+ if not url:
100
+ return {"error": "URL is required for updating hyperlinks"}
101
+
102
+ # Update existing hyperlink
103
+ paragraphs = shape.text_frame.paragraphs
104
+ if run_index < len(paragraphs[0].runs):
105
+ run = paragraphs[0].runs[run_index]
106
+ old_url = run.hyperlink.address
107
+ run.hyperlink.address = url
108
+
109
+ return {
110
+ "message": f"Updated hyperlink from '{old_url}' to '{url}'",
111
+ "old_url": old_url,
112
+ "new_url": url,
113
+ "text": run.text
114
+ }
115
+ else:
116
+ return {"error": f"Run index {run_index} out of range"}
117
+
118
+ elif operation == "remove":
119
+ # Remove hyperlink from specific run
120
+ paragraphs = shape.text_frame.paragraphs
121
+ if run_index < len(paragraphs[0].runs):
122
+ run = paragraphs[0].runs[run_index]
123
+ old_url = run.hyperlink.address
124
+ run.hyperlink.address = None
125
+
126
+ return {
127
+ "message": f"Removed hyperlink '{old_url}' from text '{run.text}'",
128
+ "removed_url": old_url,
129
+ "text": run.text
130
+ }
131
+ else:
132
+ return {"error": f"Run index {run_index} out of range"}
133
+
134
+ else:
135
+ return {"error": f"Unsupported operation: {operation}. Use 'add', 'remove', 'list', or 'update'"}
136
+
137
+ except Exception as e:
138
138
  return {"error": f"Failed to manage hyperlinks: {str(e)}"}
tools/master_tools.py CHANGED
@@ -1,114 +1,114 @@
1
- """
2
- Slide master management tools for PowerPoint MCP Server.
3
- Implements slide master and layout access capabilities.
4
- """
5
-
6
- from typing import Dict, List, Optional, Any
7
-
8
- def register_master_tools(app, presentations, get_current_presentation_id, validate_parameters,
9
- is_positive, is_non_negative, is_in_range, is_valid_rgb):
10
- """Register slide master management tools with the FastMCP app."""
11
-
12
- @app.tool()
13
- def manage_slide_masters(
14
- operation: str,
15
- master_index: int = 0,
16
- layout_index: int = None,
17
- presentation_id: str = None
18
- ) -> Dict:
19
- """
20
- Access and manage slide master properties and layouts.
21
-
22
- Args:
23
- operation: Operation type ("list", "get_layouts", "get_info")
24
- master_index: Index of the slide master (0-based)
25
- layout_index: Index of specific layout within master (0-based)
26
- presentation_id: Optional presentation ID (uses current if not provided)
27
-
28
- Returns:
29
- Dictionary with slide master information
30
- """
31
- try:
32
- # Get presentation
33
- pres_id = presentation_id or get_current_presentation_id()
34
- if pres_id not in presentations:
35
- return {"error": "Presentation not found"}
36
-
37
- pres = presentations[pres_id]
38
-
39
- if operation == "list":
40
- # List all slide masters
41
- masters_info = []
42
- for idx, master in enumerate(pres.slide_masters):
43
- masters_info.append({
44
- "index": idx,
45
- "layout_count": len(master.slide_layouts),
46
- "name": getattr(master, 'name', f"Master {idx}")
47
- })
48
-
49
- return {
50
- "message": f"Found {len(masters_info)} slide masters",
51
- "masters": masters_info,
52
- "total_masters": len(pres.slide_masters)
53
- }
54
-
55
- # Validate master index
56
- if not (0 <= master_index < len(pres.slide_masters)):
57
- return {"error": f"Master index {master_index} out of range"}
58
-
59
- master = pres.slide_masters[master_index]
60
-
61
- if operation == "get_layouts":
62
- # Get all layouts for a specific master
63
- layouts_info = []
64
- for idx, layout in enumerate(master.slide_layouts):
65
- layouts_info.append({
66
- "index": idx,
67
- "name": layout.name,
68
- "placeholder_count": len(layout.placeholders) if hasattr(layout, 'placeholders') else 0
69
- })
70
-
71
- return {
72
- "message": f"Master {master_index} has {len(layouts_info)} layouts",
73
- "master_index": master_index,
74
- "layouts": layouts_info
75
- }
76
-
77
- elif operation == "get_info":
78
- # Get detailed info about master or specific layout
79
- if layout_index is not None:
80
- if not (0 <= layout_index < len(master.slide_layouts)):
81
- return {"error": f"Layout index {layout_index} out of range"}
82
-
83
- layout = master.slide_layouts[layout_index]
84
- placeholders_info = []
85
-
86
- if hasattr(layout, 'placeholders'):
87
- for placeholder in layout.placeholders:
88
- placeholders_info.append({
89
- "idx": placeholder.placeholder_format.idx,
90
- "type": str(placeholder.placeholder_format.type),
91
- "name": getattr(placeholder, 'name', 'Unnamed')
92
- })
93
-
94
- return {
95
- "message": f"Layout info for master {master_index}, layout {layout_index}",
96
- "master_index": master_index,
97
- "layout_index": layout_index,
98
- "layout_name": layout.name,
99
- "placeholders": placeholders_info
100
- }
101
- else:
102
- # Master info
103
- return {
104
- "message": f"Master {master_index} information",
105
- "master_index": master_index,
106
- "layout_count": len(master.slide_layouts),
107
- "name": getattr(master, 'name', f"Master {master_index}")
108
- }
109
-
110
- else:
111
- return {"error": f"Unsupported operation: {operation}. Use 'list', 'get_layouts', or 'get_info'"}
112
-
113
- except Exception as e:
1
+ """
2
+ Slide master management tools for PowerPoint MCP Server.
3
+ Implements slide master and layout access capabilities.
4
+ """
5
+
6
+ from typing import Dict, List, Optional, Any
7
+
8
+ def register_master_tools(app, presentations, get_current_presentation_id, validate_parameters,
9
+ is_positive, is_non_negative, is_in_range, is_valid_rgb):
10
+ """Register slide master management tools with the FastMCP app."""
11
+
12
+ @app.tool()
13
+ def manage_slide_masters(
14
+ operation: str,
15
+ master_index: int = 0,
16
+ layout_index: int = None,
17
+ presentation_id: str = None
18
+ ) -> Dict:
19
+ """
20
+ Access and manage slide master properties and layouts.
21
+
22
+ Args:
23
+ operation: Operation type ("list", "get_layouts", "get_info")
24
+ master_index: Index of the slide master (0-based)
25
+ layout_index: Index of specific layout within master (0-based)
26
+ presentation_id: Optional presentation ID (uses current if not provided)
27
+
28
+ Returns:
29
+ Dictionary with slide master information
30
+ """
31
+ try:
32
+ # Get presentation
33
+ pres_id = presentation_id or get_current_presentation_id()
34
+ if pres_id not in presentations:
35
+ return {"error": "Presentation not found"}
36
+
37
+ pres = presentations[pres_id]
38
+
39
+ if operation == "list":
40
+ # List all slide masters
41
+ masters_info = []
42
+ for idx, master in enumerate(pres.slide_masters):
43
+ masters_info.append({
44
+ "index": idx,
45
+ "layout_count": len(master.slide_layouts),
46
+ "name": getattr(master, 'name', f"Master {idx}")
47
+ })
48
+
49
+ return {
50
+ "message": f"Found {len(masters_info)} slide masters",
51
+ "masters": masters_info,
52
+ "total_masters": len(pres.slide_masters)
53
+ }
54
+
55
+ # Validate master index
56
+ if not (0 <= master_index < len(pres.slide_masters)):
57
+ return {"error": f"Master index {master_index} out of range"}
58
+
59
+ master = pres.slide_masters[master_index]
60
+
61
+ if operation == "get_layouts":
62
+ # Get all layouts for a specific master
63
+ layouts_info = []
64
+ for idx, layout in enumerate(master.slide_layouts):
65
+ layouts_info.append({
66
+ "index": idx,
67
+ "name": layout.name,
68
+ "placeholder_count": len(layout.placeholders) if hasattr(layout, 'placeholders') else 0
69
+ })
70
+
71
+ return {
72
+ "message": f"Master {master_index} has {len(layouts_info)} layouts",
73
+ "master_index": master_index,
74
+ "layouts": layouts_info
75
+ }
76
+
77
+ elif operation == "get_info":
78
+ # Get detailed info about master or specific layout
79
+ if layout_index is not None:
80
+ if not (0 <= layout_index < len(master.slide_layouts)):
81
+ return {"error": f"Layout index {layout_index} out of range"}
82
+
83
+ layout = master.slide_layouts[layout_index]
84
+ placeholders_info = []
85
+
86
+ if hasattr(layout, 'placeholders'):
87
+ for placeholder in layout.placeholders:
88
+ placeholders_info.append({
89
+ "idx": placeholder.placeholder_format.idx,
90
+ "type": str(placeholder.placeholder_format.type),
91
+ "name": getattr(placeholder, 'name', 'Unnamed')
92
+ })
93
+
94
+ return {
95
+ "message": f"Layout info for master {master_index}, layout {layout_index}",
96
+ "master_index": master_index,
97
+ "layout_index": layout_index,
98
+ "layout_name": layout.name,
99
+ "placeholders": placeholders_info
100
+ }
101
+ else:
102
+ # Master info
103
+ return {
104
+ "message": f"Master {master_index} information",
105
+ "master_index": master_index,
106
+ "layout_count": len(master.slide_layouts),
107
+ "name": getattr(master, 'name', f"Master {master_index}")
108
+ }
109
+
110
+ else:
111
+ return {"error": f"Unsupported operation: {operation}. Use 'list', 'get_layouts', or 'get_info'"}
112
+
113
+ except Exception as e:
114
114
  return {"error": f"Failed to manage slide masters: {str(e)}"}