@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,20 @@
1
+ """Google OAuth defaults independent of protocol-level token requirements."""
2
+
3
+ from fastmcp.server.auth.providers.google import GoogleProvider as _GoogleProvider
4
+ from mcp.server.auth.provider import AuthorizationParams
5
+ from mcp.shared.auth import OAuthClientInformationFull
6
+
7
+
8
+ class GoogleProvider(_GoogleProvider):
9
+ async def authorize(
10
+ self, client: OAuthClientInformationFull, params: AuthorizationParams
11
+ ) -> str:
12
+ # FastMCP falls back to required_scopes for scope-less authorization,
13
+ # even when DCR/CIMD defaults advertise the enabled Workspace scopes.
14
+ # Keep bearer validation minimal while requesting the configured defaults.
15
+ # An explicit scope selection must remain the client's choice.
16
+ if not params.scopes:
17
+ params = params.model_copy(
18
+ update={"scopes": self._default_scope_str.split()}
19
+ )
20
+ return await super().authorize(client, params)
@@ -0,0 +1,95 @@
1
+ """
2
+ MCP Session Middleware
3
+
4
+ This middleware intercepts MCP requests and sets the session context
5
+ for use by tool functions.
6
+ """
7
+
8
+ import logging
9
+ from typing import Optional
10
+
11
+ from starlette.requests import Request
12
+ from starlette.types import ASGIApp, Receive, Scope, Send
13
+
14
+ from auth.oauth21_session_store import (
15
+ SessionContext,
16
+ SessionContextManager,
17
+ extract_session_from_headers,
18
+ )
19
+ # OAuth 2.1 is now handled by FastMCP auth
20
+
21
+ logger = logging.getLogger(__name__)
22
+
23
+
24
+ def _build_session_context(request: Request) -> Optional[SessionContext]:
25
+ headers = dict(request.headers)
26
+ session_id = extract_session_from_headers(headers)
27
+
28
+ auth_context = None
29
+ user_email = None
30
+ mcp_session_id = None
31
+ if hasattr(request.state, "auth"):
32
+ auth_context = request.state.auth
33
+ # SECURITY: user_email must come from verified FastMCP auth, never a raw JWT.
34
+ if hasattr(auth_context, "claims") and auth_context.claims:
35
+ user_email = auth_context.claims.get("email")
36
+
37
+ if hasattr(request.state, "session_id"):
38
+ mcp_session_id = request.state.session_id
39
+ logger.debug(f"Found FastMCP session ID: {mcp_session_id}")
40
+
41
+ if not (session_id or auth_context or user_email or mcp_session_id):
42
+ return None
43
+
44
+ # Session ID hierarchy: explicit session_id > Google user session > FastMCP session
45
+ effective_session_id = session_id
46
+ if not effective_session_id and user_email:
47
+ effective_session_id = f"google_{user_email}"
48
+ elif not effective_session_id and mcp_session_id:
49
+ effective_session_id = mcp_session_id
50
+
51
+ session_context = SessionContext(
52
+ session_id=effective_session_id,
53
+ user_id=user_email or (auth_context.user_id if auth_context else None),
54
+ auth_context=auth_context,
55
+ request=request,
56
+ metadata={
57
+ "path": request.url.path,
58
+ "method": request.method,
59
+ "user_email": user_email,
60
+ "mcp_session_id": mcp_session_id,
61
+ },
62
+ )
63
+ logger.debug(
64
+ f"MCP request with session: session_id={session_context.session_id}, "
65
+ f"user_id={session_context.user_id}, path={request.url.path}"
66
+ )
67
+ return session_context
68
+
69
+
70
+ class MCPSessionMiddleware:
71
+ """
72
+ Middleware that extracts session information from requests and makes it
73
+ available to MCP tool functions via context variables.
74
+ """
75
+
76
+ def __init__(self, app: ASGIApp) -> None:
77
+ self.app = app
78
+
79
+ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
80
+ if scope["type"] != "http" or not scope.get("path", "").startswith("/mcp"):
81
+ await self.app(scope, receive, send)
82
+ return
83
+
84
+ try:
85
+ request = Request(scope, receive)
86
+ logger.debug(
87
+ f"MCPSessionMiddleware processing request: {request.method} {request.url.path}"
88
+ )
89
+ session_context = _build_session_context(request)
90
+ except Exception as e:
91
+ logger.error(f"Error in MCP session middleware: {e}")
92
+ session_context = None
93
+
94
+ with SessionContextManager(session_context):
95
+ await self.app(scope, receive, send)