@mutallip/google-workspace-mcp 0.0.0-stage → 2.8.0

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.
Files changed (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -2
  3. package/README.npm.md +28 -0
  4. package/auth/__init__.py +1 -0
  5. package/auth/auth_info_middleware.py +419 -0
  6. package/auth/client_secrets.py +76 -0
  7. package/auth/credential_store.py +598 -0
  8. package/auth/external_oauth_provider.py +369 -0
  9. package/auth/gateway_identity.py +164 -0
  10. package/auth/google_auth.py +1550 -0
  11. package/auth/google_oauth_provider.py +20 -0
  12. package/auth/mcp_session_middleware.py +95 -0
  13. package/auth/oauth21_session_store.py +1332 -0
  14. package/auth/oauth_callback_server.py +466 -0
  15. package/auth/oauth_config.py +693 -0
  16. package/auth/oauth_proxy_config.py +122 -0
  17. package/auth/oauth_responses.py +230 -0
  18. package/auth/oauth_types.py +92 -0
  19. package/auth/permissions.py +330 -0
  20. package/auth/port_resolver.py +153 -0
  21. package/auth/request_identity.py +89 -0
  22. package/auth/scopes.py +369 -0
  23. package/auth/service_decorator.py +1109 -0
  24. package/bin/google-workspace-mcp.cjs +123 -0
  25. package/core/__init__.py +1 -0
  26. package/core/api_enablement.py +108 -0
  27. package/core/attachment_storage.py +496 -0
  28. package/core/camel_case_middleware.py +98 -0
  29. package/core/cli.py +161 -0
  30. package/core/comments.py +609 -0
  31. package/core/config.py +57 -0
  32. package/core/context.py +43 -0
  33. package/core/file_limits.py +632 -0
  34. package/core/gcs_attachment_storage.py +253 -0
  35. package/core/http_utils.py +339 -0
  36. package/core/log_formatter.py +270 -0
  37. package/core/portable_schema_middleware.py +67 -0
  38. package/core/server.py +1192 -0
  39. package/core/startup_ui.py +239 -0
  40. package/core/storage.py +23 -0
  41. package/core/telemetry.py +194 -0
  42. package/core/tool_descriptions.py +19 -0
  43. package/core/tool_registry.py +311 -0
  44. package/core/tool_tier_loader.py +197 -0
  45. package/core/tool_tiers.yaml +179 -0
  46. package/core/toolset_header_middleware.py +67 -0
  47. package/core/utils.py +1537 -0
  48. package/core/valkey_storage.py +271 -0
  49. package/core/warning_filters.py +19 -0
  50. package/fastmcp_server.py +198 -0
  51. package/gappsscript/README.md +512 -0
  52. package/gappsscript/TESTING.md +254 -0
  53. package/gappsscript/__init__.py +0 -0
  54. package/gappsscript/apps_script_tools.py +1940 -0
  55. package/gcalendar/__init__.py +1 -0
  56. package/gcalendar/calendar_helpers.py +1323 -0
  57. package/gcalendar/calendar_tools.py +2252 -0
  58. package/gchat/__init__.py +7 -0
  59. package/gchat/chat_helpers.py +410 -0
  60. package/gchat/chat_tools.py +798 -0
  61. package/gcontacts/__init__.py +1 -0
  62. package/gcontacts/contacts_helpers.py +765 -0
  63. package/gcontacts/contacts_tools.py +1685 -0
  64. package/gdocs/__init__.py +0 -0
  65. package/gdocs/docs_anchors.py +163 -0
  66. package/gdocs/docs_comments.py +89 -0
  67. package/gdocs/docs_helpers.py +2201 -0
  68. package/gdocs/docs_links.py +87 -0
  69. package/gdocs/docs_markdown.py +828 -0
  70. package/gdocs/docs_markdown_writer.py +592 -0
  71. package/gdocs/docs_plain_text.py +463 -0
  72. package/gdocs/docs_structure.py +621 -0
  73. package/gdocs/docs_tables.py +425 -0
  74. package/gdocs/docs_tools.py +3300 -0
  75. package/gdocs/managers/__init__.py +18 -0
  76. package/gdocs/managers/batch_operation_manager.py +1694 -0
  77. package/gdocs/managers/header_footer_manager.py +526 -0
  78. package/gdocs/managers/table_operation_manager.py +488 -0
  79. package/gdocs/managers/validation_manager.py +1504 -0
  80. package/gdocs/operation_schemas.py +594 -0
  81. package/gdrive/__init__.py +0 -0
  82. package/gdrive/drive_helpers.py +1738 -0
  83. package/gdrive/drive_tools.py +3085 -0
  84. package/gforms/__init__.py +3 -0
  85. package/gforms/forms_tools.py +575 -0
  86. package/gmail/__init__.py +1 -0
  87. package/gmail/gmail_helpers.py +2107 -0
  88. package/gmail/gmail_tools.py +4895 -0
  89. package/gmail/gmail_web_mime.py +441 -0
  90. package/gsearch/__init__.py +0 -0
  91. package/gsearch/search_tools.py +253 -0
  92. package/gsheets/__init__.py +31 -0
  93. package/gsheets/sheets_helpers.py +2236 -0
  94. package/gsheets/sheets_tools.py +3280 -0
  95. package/gslides/__init__.py +0 -0
  96. package/gslides/slides_digest.py +390 -0
  97. package/gslides/slides_helpers.py +392 -0
  98. package/gslides/slides_markup.py +770 -0
  99. package/gslides/slides_tools.py +376 -0
  100. package/gtasks/__init__.py +5 -0
  101. package/gtasks/tasks_tools.py +936 -0
  102. package/main.py +1170 -0
  103. package/package.json +43 -4
  104. package/pyproject.toml +173 -0
  105. package/uv.lock +2504 -0
@@ -0,0 +1,376 @@
1
+ """
2
+ Google Slides MCP Tools
3
+
4
+ This module provides MCP tools for interacting with Google Slides API.
5
+ """
6
+
7
+ import asyncio
8
+ import logging
9
+ from typing import Any, Dict, List, Optional
10
+
11
+ import httpx
12
+ from fastmcp.tools import ToolResult
13
+ from mcp.types import ImageContent, TextContent, ToolAnnotations
14
+
15
+ from auth.service_decorator import require_google_service
16
+ from core.server import server
17
+ from core.utils import (
18
+ StringList,
19
+ check_path_segment,
20
+ handle_http_errors,
21
+ image_content_from_bytes,
22
+ sniff_inline_image_mime_type,
23
+ )
24
+ from core.comments import create_comment_tools
25
+ from gslides.slides_helpers import (
26
+ read_presentation,
27
+ validate_batch_update_requests,
28
+ validate_insert_text_targets,
29
+ validate_page_image_size,
30
+ )
31
+
32
+ logger = logging.getLogger(__name__)
33
+
34
+
35
+ @server.tool(
36
+ title="Create Presentation",
37
+ annotations=ToolAnnotations(
38
+ readOnlyHint=False,
39
+ destructiveHint=False,
40
+ idempotentHint=False,
41
+ openWorldHint=True,
42
+ ),
43
+ )
44
+ @handle_http_errors("create_presentation", service_type="slides")
45
+ @require_google_service("slides", "slides")
46
+ async def create_presentation(
47
+ service, user_google_email: str, title: str = "Untitled Presentation"
48
+ ) -> str:
49
+ """
50
+ Create a new Google Slides presentation and return its ID and URL.
51
+
52
+ Args:
53
+ user_google_email (str): The user's Google email address. Required.
54
+ title (str): The title for the new presentation. Defaults to "Untitled Presentation".
55
+
56
+ Returns:
57
+ str: Details about the created presentation including ID and URL.
58
+ """
59
+ logger.info(
60
+ f"[create_presentation] Invoked. Email: '{user_google_email}', title_len={len(title)}"
61
+ )
62
+
63
+ body = {"title": title}
64
+
65
+ result = await asyncio.to_thread(service.presentations().create(body=body).execute)
66
+
67
+ presentation_id = result.get("presentationId")
68
+ presentation_url = f"https://docs.google.com/presentation/d/{presentation_id}/edit"
69
+
70
+ confirmation_message = f"""Presentation Created Successfully for {user_google_email}:
71
+ - Title: {title}
72
+ - Presentation ID: {presentation_id}
73
+ - URL: {presentation_url}
74
+ - Slides: {len(result.get("slides", []))} slide(s) created"""
75
+
76
+ logger.info(f"Presentation created successfully for {user_google_email}")
77
+ return confirmation_message
78
+
79
+
80
+ @server.tool(
81
+ title="Get Presentation",
82
+ annotations=ToolAnnotations(
83
+ readOnlyHint=True,
84
+ destructiveHint=False,
85
+ idempotentHint=True,
86
+ openWorldHint=True,
87
+ ),
88
+ )
89
+ @handle_http_errors("get_presentation", is_read_only=True, service_type="slides")
90
+ @require_google_service("slides", "slides_read")
91
+ async def get_presentation(
92
+ service,
93
+ user_google_email: str,
94
+ presentation_id: str,
95
+ action: str = "deck",
96
+ page_id: Optional[str] = None,
97
+ targets: Optional[StringList] = None,
98
+ raw: bool = False,
99
+ offset: int = 0,
100
+ after: Optional[str] = None,
101
+ ) -> str:
102
+ """
103
+ Read a deck: action "deck" (default) lists its slides and layouts, "page" gives one slide's element IDs and all its text (start here for content), "markup" gives one slide's elements as compact JSON with geometry and styles, "layouts" lists every layout.
104
+
105
+ Actions:
106
+ - "deck": Title, URL, revision, and per slide its ID, title, layout,
107
+ element counts and notes length; then the deck's layouts with the
108
+ placeholders each provides. Lists 100 slides per call; a longer deck
109
+ ends with the offset to call again with. Uses offset.
110
+ - "layouts": Every layout, grouped by master, with its placeholders
111
+ and the slides using it. Only needed when "deck" says there are
112
+ more layouts than it lists. Uses after.
113
+ - "page": Every element on one slide with its ID, in z-order, groups
114
+ nested, with all text, table cells, image sources and speaker notes.
115
+ No geometry or styling. Requires page_id.
116
+ - "markup": One slide, or chosen elements, as JSON: boxes in points
117
+ ({"x","y","w","h"}), text as paragraphs and runs, styles in a shared
118
+ "styles" table referenced by "s", only locally set properties.
119
+ A shape with no "shape" key is a TEXT_BOX. Requires page_id; uses
120
+ targets and raw.
121
+
122
+ Args:
123
+ user_google_email (str): The user's Google email address. Required.
124
+ presentation_id (str): The ID of the presentation.
125
+ action (str): "deck" (default): slides and layouts. "page": one
126
+ slide's element IDs and text. "markup": one slide's elements as
127
+ JSON with geometry and styles. "layouts": every layout.
128
+ page_id (Optional[str]): Slide (or any page) object ID, from "deck".
129
+ Required for "page" and "markup".
130
+ targets (Optional[List[str]]): For "markup": element IDs to return
131
+ instead of the whole slide, plus "notes" for the speaker notes.
132
+ A target inside a group comes back with page coordinates and its
133
+ "group" ID; a group comes back with its children.
134
+ raw (bool): For "markup": return the Slides API Page resource itself
135
+ (EMU, transforms, text indices), limited to targets when given,
136
+ for writing raw batch_update_presentation requests. A target in a
137
+ group keeps its group-relative transform. Defaults to False.
138
+ offset (int): For "deck": index of the first slide to list, from the
139
+ note at the end of a previous call. Defaults to 0.
140
+ after (Optional[str]): For "layouts": a slide ID, or "start". Lists
141
+ only the layouts of the master in use at that position, which are
142
+ the only ones a new slide inserted there can use.
143
+
144
+ Returns:
145
+ str: The deck or layout digest, the page digest, or the markup JSON.
146
+ """
147
+ presentation_id = check_path_segment(presentation_id, "presentation_id")
148
+ logger.info(
149
+ f"[get_presentation] Invoked. Email: '{user_google_email}', ID: '{presentation_id}', Action: '{action}'"
150
+ )
151
+ return await read_presentation(
152
+ service,
153
+ presentation_id,
154
+ action,
155
+ page_id=page_id,
156
+ targets=targets,
157
+ raw=raw,
158
+ offset=offset,
159
+ after=after,
160
+ )
161
+
162
+
163
+ @server.tool(
164
+ title="Batch Update Presentation",
165
+ annotations=ToolAnnotations(
166
+ readOnlyHint=False,
167
+ destructiveHint=True,
168
+ idempotentHint=False,
169
+ openWorldHint=True,
170
+ ),
171
+ )
172
+ @handle_http_errors("batch_update_presentation", service_type="slides")
173
+ @require_google_service("slides", "slides")
174
+ async def batch_update_presentation(
175
+ service,
176
+ user_google_email: str,
177
+ presentation_id: str,
178
+ requests: List[Dict[str, Any]],
179
+ ) -> str:
180
+ """
181
+ Apply batch updates to a Google Slides presentation.
182
+
183
+ Important:
184
+ Each request object must contain exactly one supported Slides request
185
+ type, such as createSlide, createShape, insertText, updateTextStyle,
186
+ createImage, or deleteObject.
187
+
188
+ insertText.objectId must be a text-capable shape or table object ID,
189
+ not a slide/page object ID. To add text to a slide, create a text box
190
+ or shape first with createShape, set elementProperties.pageObjectId to
191
+ the slide ID, and then insertText into that shape objectId. To edit
192
+ existing text, call get_presentation with action="page" and use a
193
+ Shape or Table element ID.
194
+
195
+ To write speaker (presenter) notes, call get_presentation with
196
+ action="page" to get the slide's speaker notes shape ID, then target
197
+ that ID: deleteText with textRange {"type": "ALL"} to clear
198
+ the existing notes (omit this when they are already empty, which errors),
199
+ followed by insertText at insertionIndex 0. The notes page ID is not a
200
+ valid target.
201
+
202
+ Args:
203
+ user_google_email (str): The user's Google email address. Required.
204
+ presentation_id (str): The ID of the presentation to update.
205
+ requests (List[Dict[str, Any]]): List of update requests to apply.
206
+
207
+ Returns:
208
+ str: Details about the batch update operation results.
209
+ """
210
+ presentation_id = check_path_segment(presentation_id, "presentation_id")
211
+ logger.info(
212
+ f"[batch_update_presentation] Invoked. Email: '{user_google_email}', ID: '{presentation_id}', Requests: {len(requests)}"
213
+ )
214
+
215
+ validate_batch_update_requests(requests)
216
+ await validate_insert_text_targets(service, presentation_id, requests)
217
+
218
+ body = {"requests": requests}
219
+
220
+ result = await asyncio.to_thread(
221
+ service.presentations()
222
+ .batchUpdate(presentationId=presentation_id, body=body)
223
+ .execute
224
+ )
225
+
226
+ replies = result.get("replies", [])
227
+
228
+ confirmation_message = f"""Batch Update Completed for {user_google_email}:
229
+ - Presentation ID: {presentation_id}
230
+ - URL: https://docs.google.com/presentation/d/{presentation_id}/edit
231
+ - Requests Applied: {len(requests)}
232
+ - Replies Received: {len(replies)}"""
233
+
234
+ if replies:
235
+ confirmation_message += "\n\nUpdate Results:"
236
+ for i, reply in enumerate(replies, 1):
237
+ if "createSlide" in reply:
238
+ slide_id = reply["createSlide"].get("objectId", "Unknown")
239
+ confirmation_message += (
240
+ f"\n Request {i}: Created slide with ID {slide_id}"
241
+ )
242
+ elif "createShape" in reply:
243
+ shape_id = reply["createShape"].get("objectId", "Unknown")
244
+ confirmation_message += (
245
+ f"\n Request {i}: Created shape with ID {shape_id}"
246
+ )
247
+ elif "replaceAllText" in reply:
248
+ count = reply["replaceAllText"].get("occurrencesChanged", 0)
249
+ confirmation_message += (
250
+ f"\n Request {i}: Replaced {count} occurrence(s)"
251
+ )
252
+ else:
253
+ confirmation_message += f"\n Request {i}: Operation completed"
254
+
255
+ logger.info(f"Batch update completed successfully for {user_google_email}")
256
+ return confirmation_message
257
+
258
+
259
+ async def _fetch_page_image(url: str) -> Optional[ImageContent]:
260
+ """Download a rendered page image, or return None if it cannot be retrieved."""
261
+ try:
262
+ async with httpx.AsyncClient(timeout=30, follow_redirects=True) as client:
263
+ response = await client.get(url)
264
+ response.raise_for_status()
265
+ except httpx.HTTPError as exc:
266
+ # The URL grants the requester's access to anyone holding it, so it
267
+ # stays out of the log.
268
+ logger.warning(
269
+ f"[render_page_to_image] Image fetch failed: {type(exc).__name__}"
270
+ )
271
+ return None
272
+ content_type = response.headers.get("content-type", "").lower()
273
+ mime_type = sniff_inline_image_mime_type(response.content)
274
+ if not content_type.startswith("image/") or mime_type is None:
275
+ logger.warning("[render_page_to_image] Image fetch returned a non-image")
276
+ return None
277
+ return image_content_from_bytes(response.content, mime_type)
278
+
279
+
280
+ @server.tool(
281
+ title="Render Page to Image",
282
+ annotations=ToolAnnotations(
283
+ readOnlyHint=True,
284
+ destructiveHint=False,
285
+ idempotentHint=True,
286
+ openWorldHint=True,
287
+ ),
288
+ )
289
+ @handle_http_errors("render_page_to_image", is_read_only=True, service_type="slides")
290
+ @require_google_service("slides", "slides_read")
291
+ async def render_page_to_image(
292
+ service,
293
+ user_google_email: str,
294
+ presentation_id: str,
295
+ page_object_id: str,
296
+ size: str = "MEDIUM",
297
+ ) -> str:
298
+ """
299
+ Render a slide (or any page, including notes pages) to an image and return it as image content, for looking at a slide's layout and visuals.
300
+
301
+ This is the way to see a slide: use it instead of exporting the
302
+ presentation to PPTX or PDF and rendering that.
303
+
304
+ Args:
305
+ user_google_email (str): The user's Google email address. Required.
306
+ presentation_id (str): The ID of the presentation.
307
+ page_object_id (str): The object ID of the page/slide to render.
308
+ size (str): Image width. One of "SMALL" (200px), "MEDIUM" (800px),
309
+ "LARGE" (1600px) or "WIDTH2000_PX" (2000px). Defaults to "MEDIUM".
310
+ Start at MEDIUM: it reads titles and body text. Use LARGE for small
311
+ text such as tables, chart labels and footnotes. WIDTH2000_PX
312
+ rarely reads more than LARGE. SMALL shows layout only; its text is
313
+ unreadable. Token cost and the resolution the model sees depend on
314
+ the model: Claude models with high-resolution vision read MEDIUM at
315
+ ~460 image tokens, LARGE at ~1,850 and WIDTH2000_PX at ~2,900, while
316
+ other models may downscale LARGE and WIDTH2000_PX and count tokens
317
+ differently.
318
+
319
+ Returns:
320
+ A short text block (presentation ID, page ID, size and a temporary
321
+ image URL) followed by the rendered PNG as image content. If the image
322
+ cannot be fetched, only the text block is returned, with a note saying
323
+ so.
324
+ """
325
+ requested_width = validate_page_image_size(size)
326
+ logger.info(
327
+ f"[render_page_to_image] Invoked. Email: '{user_google_email}', Presentation: '{presentation_id}', Page: '{page_object_id}', Size: '{size}'"
328
+ )
329
+
330
+ result = await asyncio.to_thread(
331
+ service.presentations()
332
+ .pages()
333
+ .getThumbnail(
334
+ presentationId=presentation_id,
335
+ pageObjectId=page_object_id,
336
+ thumbnailProperties_thumbnailSize=size,
337
+ thumbnailProperties_mimeType="PNG",
338
+ )
339
+ .execute
340
+ )
341
+
342
+ image_url = result.get("contentUrl", "")
343
+ width = result.get("width", requested_width)
344
+ dimensions = (
345
+ f"{width}x{result['height']}px" if "height" in result else f"{width}px wide"
346
+ )
347
+
348
+ text = f"""Rendered page:
349
+ - Presentation ID: {presentation_id}
350
+ - Page ID: {page_object_id}
351
+ - Size: {size} ({dimensions})
352
+ - Image URL: {image_url or "(none returned)"}
353
+ (expires after about 30 minutes and is tagged with the requesting account;
354
+ anyone holding it can open the image while it lasts)"""
355
+
356
+ image = await _fetch_page_image(image_url) if image_url else None
357
+ if image is None:
358
+ text += "\n\nImage unavailable: the rendered page could not be fetched."
359
+ if image_url:
360
+ text += " Open the image URL above instead, before it expires."
361
+ content: List[TextContent | ImageContent] = [TextContent(type="text", text=text)]
362
+ if image is not None:
363
+ content.append(image)
364
+ logger.info(f"Page rendered for {user_google_email}")
365
+ # structured_content mirrors the text to satisfy the `str` output schema.
366
+ return ToolResult(content=content, structured_content={"result": text})
367
+
368
+
369
+ # Create comment management tools for slides
370
+ _comment_tools = create_comment_tools("presentation", "presentation_id")
371
+ list_presentation_comments = _comment_tools["list_comments"]
372
+ manage_presentation_comment = _comment_tools["manage_comment"]
373
+
374
+ # Aliases for backwards compatibility and intuitive naming
375
+ list_slide_comments = list_presentation_comments
376
+ manage_slide_comment = manage_presentation_comment
@@ -0,0 +1,5 @@
1
+ """
2
+ Google Tasks MCP Integration
3
+
4
+ This module provides MCP tools for interacting with Google Tasks API.
5
+ """