@mutallip/google-workspace-mcp 0.0.0-stage → 2.8.1
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.
- package/LICENSE +21 -0
- package/README.md +353 -2
- package/README.npm.md +34 -0
- package/auth/__init__.py +1 -0
- package/auth/auth_info_middleware.py +419 -0
- package/auth/client_secrets.py +76 -0
- package/auth/credential_store.py +598 -0
- package/auth/external_oauth_provider.py +369 -0
- package/auth/gateway_identity.py +164 -0
- package/auth/google_auth.py +1550 -0
- package/auth/google_oauth_provider.py +20 -0
- package/auth/mcp_session_middleware.py +95 -0
- package/auth/oauth21_session_store.py +1332 -0
- package/auth/oauth_callback_server.py +466 -0
- package/auth/oauth_config.py +693 -0
- package/auth/oauth_proxy_config.py +122 -0
- package/auth/oauth_responses.py +230 -0
- package/auth/oauth_types.py +92 -0
- package/auth/permissions.py +330 -0
- package/auth/port_resolver.py +153 -0
- package/auth/request_identity.py +89 -0
- package/auth/scopes.py +369 -0
- package/auth/service_decorator.py +1109 -0
- package/bin/google-workspace-mcp.cjs +123 -0
- package/core/__init__.py +1 -0
- package/core/api_enablement.py +108 -0
- package/core/attachment_storage.py +496 -0
- package/core/camel_case_middleware.py +98 -0
- package/core/cli.py +161 -0
- package/core/comments.py +609 -0
- package/core/config.py +57 -0
- package/core/context.py +43 -0
- package/core/file_limits.py +632 -0
- package/core/gcs_attachment_storage.py +253 -0
- package/core/http_utils.py +339 -0
- package/core/log_formatter.py +270 -0
- package/core/portable_schema_middleware.py +67 -0
- package/core/server.py +1192 -0
- package/core/startup_ui.py +239 -0
- package/core/storage.py +23 -0
- package/core/telemetry.py +194 -0
- package/core/tool_descriptions.py +19 -0
- package/core/tool_registry.py +311 -0
- package/core/tool_tier_loader.py +197 -0
- package/core/tool_tiers.yaml +179 -0
- package/core/toolset_header_middleware.py +67 -0
- package/core/utils.py +1537 -0
- package/core/valkey_storage.py +271 -0
- package/core/warning_filters.py +19 -0
- package/fastmcp_server.py +198 -0
- package/gappsscript/README.md +512 -0
- package/gappsscript/TESTING.md +254 -0
- package/gappsscript/__init__.py +0 -0
- package/gappsscript/apps_script_tools.py +1940 -0
- package/gcalendar/__init__.py +1 -0
- package/gcalendar/calendar_helpers.py +1323 -0
- package/gcalendar/calendar_tools.py +2252 -0
- package/gchat/__init__.py +7 -0
- package/gchat/chat_helpers.py +410 -0
- package/gchat/chat_tools.py +798 -0
- package/gcontacts/__init__.py +1 -0
- package/gcontacts/contacts_helpers.py +765 -0
- package/gcontacts/contacts_tools.py +1685 -0
- package/gdocs/__init__.py +0 -0
- package/gdocs/docs_anchors.py +163 -0
- package/gdocs/docs_comments.py +89 -0
- package/gdocs/docs_helpers.py +2201 -0
- package/gdocs/docs_links.py +87 -0
- package/gdocs/docs_markdown.py +828 -0
- package/gdocs/docs_markdown_writer.py +592 -0
- package/gdocs/docs_plain_text.py +463 -0
- package/gdocs/docs_structure.py +621 -0
- package/gdocs/docs_tables.py +425 -0
- package/gdocs/docs_tools.py +3300 -0
- package/gdocs/managers/__init__.py +18 -0
- package/gdocs/managers/batch_operation_manager.py +1694 -0
- package/gdocs/managers/header_footer_manager.py +526 -0
- package/gdocs/managers/table_operation_manager.py +488 -0
- package/gdocs/managers/validation_manager.py +1504 -0
- package/gdocs/operation_schemas.py +594 -0
- package/gdrive/__init__.py +0 -0
- package/gdrive/drive_helpers.py +1738 -0
- package/gdrive/drive_tools.py +3085 -0
- package/gforms/__init__.py +3 -0
- package/gforms/forms_tools.py +575 -0
- package/gmail/__init__.py +1 -0
- package/gmail/gmail_helpers.py +2107 -0
- package/gmail/gmail_tools.py +4895 -0
- package/gmail/gmail_web_mime.py +441 -0
- package/gsearch/__init__.py +0 -0
- package/gsearch/search_tools.py +253 -0
- package/gsheets/__init__.py +31 -0
- package/gsheets/sheets_helpers.py +2236 -0
- package/gsheets/sheets_tools.py +3280 -0
- package/gslides/__init__.py +0 -0
- package/gslides/slides_digest.py +390 -0
- package/gslides/slides_helpers.py +392 -0
- package/gslides/slides_markup.py +770 -0
- package/gslides/slides_tools.py +376 -0
- package/gtasks/__init__.py +5 -0
- package/gtasks/tasks_tools.py +936 -0
- package/main.py +1170 -0
- package/package.json +43 -4
- package/pyproject.toml +173 -0
- package/uv.lock +2504 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Environment-backed configuration for FastMCP's OAuth proxy."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
OAUTH_TOKEN_EXPIRY_THRESHOLD_ENV = (
|
|
11
|
+
"WORKSPACE_MCP_OAUTH_PROXY_TOKEN_EXPIRY_THRESHOLD_SECONDS"
|
|
12
|
+
)
|
|
13
|
+
OAUTH_ACCESS_TOKEN_EXPIRY_ENV = "WORKSPACE_MCP_OAUTH_PROXY_ACCESS_TOKEN_EXPIRY_SECONDS"
|
|
14
|
+
OAUTH_REFRESH_TOKEN_EXPIRY_ENV = (
|
|
15
|
+
"WORKSPACE_MCP_OAUTH_PROXY_REFRESH_TOKEN_EXPIRY_SECONDS"
|
|
16
|
+
)
|
|
17
|
+
OAUTH_REQUIRE_CONSENT_ENV = "WORKSPACE_MCP_OAUTH_PROXY_REQUIRE_CONSENT"
|
|
18
|
+
OAUTH_GOOGLE_PROMPT_ENV = "WORKSPACE_MCP_OAUTH_PROXY_GOOGLE_PROMPT"
|
|
19
|
+
MAX_OAUTH_TOKEN_EXPIRY_THRESHOLD_SECONDS = 5 * 60
|
|
20
|
+
MAX_OAUTH_ACCESS_TOKEN_EXPIRY_SECONDS = 30 * 24 * 60 * 60
|
|
21
|
+
MAX_OAUTH_REFRESH_TOKEN_EXPIRY_SECONDS = 365 * 24 * 60 * 60
|
|
22
|
+
|
|
23
|
+
_CONSENT_MODES: dict[str, bool | str] = {"always": True, "remember": "remember"}
|
|
24
|
+
_GOOGLE_PROMPTS = ("consent", "select_account consent")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _parse_expiry_seconds_env(
|
|
28
|
+
name: str, *, minimum: int, maximum: int
|
|
29
|
+
) -> Optional[int]:
|
|
30
|
+
"""Read a bounded integer of seconds from the environment."""
|
|
31
|
+
raw = os.getenv(name, "").strip()
|
|
32
|
+
if not raw:
|
|
33
|
+
return None
|
|
34
|
+
try:
|
|
35
|
+
seconds = int(raw)
|
|
36
|
+
except ValueError:
|
|
37
|
+
logger.warning("Ignoring %s: %r is not an integer", name, raw)
|
|
38
|
+
return None
|
|
39
|
+
if not minimum <= seconds <= maximum:
|
|
40
|
+
logger.warning(
|
|
41
|
+
"Ignoring %s: %d is outside the supported range %d-%d seconds",
|
|
42
|
+
name,
|
|
43
|
+
seconds,
|
|
44
|
+
minimum,
|
|
45
|
+
maximum,
|
|
46
|
+
)
|
|
47
|
+
return None
|
|
48
|
+
return seconds
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_oauth_proxy_expiry_kwargs() -> dict[str, int]:
|
|
52
|
+
"""Return configured token-expiry keyword arguments for GoogleProvider.
|
|
53
|
+
|
|
54
|
+
Invalid or unset values are omitted so FastMCP retains ownership of its
|
|
55
|
+
defaults and future compatibility.
|
|
56
|
+
"""
|
|
57
|
+
token_expiry_threshold_seconds = _parse_expiry_seconds_env(
|
|
58
|
+
OAUTH_TOKEN_EXPIRY_THRESHOLD_ENV,
|
|
59
|
+
minimum=0,
|
|
60
|
+
maximum=MAX_OAUTH_TOKEN_EXPIRY_THRESHOLD_SECONDS,
|
|
61
|
+
)
|
|
62
|
+
fastmcp_access_token_expiry_seconds = _parse_expiry_seconds_env(
|
|
63
|
+
OAUTH_ACCESS_TOKEN_EXPIRY_ENV,
|
|
64
|
+
minimum=1,
|
|
65
|
+
maximum=MAX_OAUTH_ACCESS_TOKEN_EXPIRY_SECONDS,
|
|
66
|
+
)
|
|
67
|
+
fallback_refresh_token_expiry_seconds = _parse_expiry_seconds_env(
|
|
68
|
+
OAUTH_REFRESH_TOKEN_EXPIRY_ENV,
|
|
69
|
+
minimum=1,
|
|
70
|
+
maximum=MAX_OAUTH_REFRESH_TOKEN_EXPIRY_SECONDS,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
expiry_kwargs: dict[str, int] = {}
|
|
74
|
+
if token_expiry_threshold_seconds is not None:
|
|
75
|
+
logger.info(
|
|
76
|
+
"OAuth 2.1: refreshing upstream tokens %ds before expiry",
|
|
77
|
+
token_expiry_threshold_seconds,
|
|
78
|
+
)
|
|
79
|
+
expiry_kwargs["token_expiry_threshold_seconds"] = token_expiry_threshold_seconds
|
|
80
|
+
if fastmcp_access_token_expiry_seconds is not None:
|
|
81
|
+
logger.info(
|
|
82
|
+
"OAuth 2.1: issuing FastMCP access tokens with a %ds lifetime",
|
|
83
|
+
fastmcp_access_token_expiry_seconds,
|
|
84
|
+
)
|
|
85
|
+
expiry_kwargs["fastmcp_access_token_expiry_seconds"] = (
|
|
86
|
+
fastmcp_access_token_expiry_seconds
|
|
87
|
+
)
|
|
88
|
+
if fallback_refresh_token_expiry_seconds is not None:
|
|
89
|
+
logger.info(
|
|
90
|
+
"OAuth 2.1: issuing FastMCP refresh tokens with a %ds lifetime",
|
|
91
|
+
fallback_refresh_token_expiry_seconds,
|
|
92
|
+
)
|
|
93
|
+
expiry_kwargs["fallback_refresh_token_expiry_seconds"] = (
|
|
94
|
+
fallback_refresh_token_expiry_seconds
|
|
95
|
+
)
|
|
96
|
+
return expiry_kwargs
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def get_oauth_proxy_consent_kwargs() -> dict[str, bool | str]:
|
|
100
|
+
"""Return GoogleProvider's consent-screen kwarg, empty when unset."""
|
|
101
|
+
raw = os.getenv(OAUTH_REQUIRE_CONSENT_ENV, "").strip().lower()
|
|
102
|
+
if not raw:
|
|
103
|
+
return {}
|
|
104
|
+
if raw not in _CONSENT_MODES:
|
|
105
|
+
raise ValueError(
|
|
106
|
+
f"{OAUTH_REQUIRE_CONSENT_ENV} must be one of "
|
|
107
|
+
f"{', '.join(_CONSENT_MODES)}, got {raw!r}"
|
|
108
|
+
)
|
|
109
|
+
return {"require_authorization_consent": _CONSENT_MODES[raw]}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def get_oauth_proxy_google_prompt_kwargs() -> dict[str, dict[str, str]]:
|
|
113
|
+
"""Return GoogleProvider's upstream ``prompt`` kwarg, empty when unset."""
|
|
114
|
+
raw = " ".join(os.getenv(OAUTH_GOOGLE_PROMPT_ENV, "").lower().split())
|
|
115
|
+
if not raw:
|
|
116
|
+
return {}
|
|
117
|
+
if raw not in _GOOGLE_PROMPTS:
|
|
118
|
+
raise ValueError(
|
|
119
|
+
f"{OAUTH_GOOGLE_PROMPT_ENV} must be one of "
|
|
120
|
+
f"{', '.join(repr(p) for p in _GOOGLE_PROMPTS)}, got {raw!r}"
|
|
121
|
+
)
|
|
122
|
+
return {"extra_authorize_params": {"prompt": raw}}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Shared OAuth callback response templates.
|
|
3
|
+
|
|
4
|
+
Provides reusable HTML response templates for OAuth authentication flows
|
|
5
|
+
to eliminate duplication between server.py and oauth_callback_server.py.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from html import escape as html_escape
|
|
9
|
+
from fastapi.responses import HTMLResponse
|
|
10
|
+
from typing import Optional
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def create_error_response(error_message: str, status_code: int = 400) -> HTMLResponse:
|
|
14
|
+
"""
|
|
15
|
+
Create a standardized error response for OAuth failures.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
error_message: The error message to display
|
|
19
|
+
status_code: HTTP status code (default 400)
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
HTMLResponse with error page
|
|
23
|
+
"""
|
|
24
|
+
content = f"""
|
|
25
|
+
<html>
|
|
26
|
+
<head><title>Authentication Error</title></head>
|
|
27
|
+
<body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 600px; margin: 40px auto; padding: 20px; text-align: center;">
|
|
28
|
+
<h2 style="color: #d32f2f;">Authentication Error</h2>
|
|
29
|
+
<p>{html_escape(error_message)}</p>
|
|
30
|
+
<p>Please ensure you grant the requested permissions. You can close this tab and try again.</p>
|
|
31
|
+
</body>
|
|
32
|
+
</html>
|
|
33
|
+
"""
|
|
34
|
+
return HTMLResponse(content=content, status_code=status_code)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def create_success_response(verified_user_id: Optional[str] = None) -> HTMLResponse:
|
|
38
|
+
"""
|
|
39
|
+
Create a standardized success response for OAuth authentication.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
verified_user_id: The authenticated user's email (optional)
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
HTMLResponse with success page
|
|
46
|
+
"""
|
|
47
|
+
# Handle the case where no user ID is provided
|
|
48
|
+
user_display = verified_user_id if verified_user_id else "Google User"
|
|
49
|
+
|
|
50
|
+
content = f"""<html>
|
|
51
|
+
<head>
|
|
52
|
+
<title>Authentication Successful</title>
|
|
53
|
+
<style>
|
|
54
|
+
* {{
|
|
55
|
+
margin: 0;
|
|
56
|
+
padding: 0;
|
|
57
|
+
box-sizing: border-box;
|
|
58
|
+
}}
|
|
59
|
+
|
|
60
|
+
body {{
|
|
61
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
62
|
+
background: linear-gradient(135deg,#0f172a,#1e293b,#334155);
|
|
63
|
+
min-height: 100vh;
|
|
64
|
+
display: flex;
|
|
65
|
+
align-items: center;
|
|
66
|
+
justify-content: center;
|
|
67
|
+
color: #1a1a1a;
|
|
68
|
+
-webkit-font-smoothing: antialiased;
|
|
69
|
+
-moz-osx-font-smoothing: grayscale;
|
|
70
|
+
}}
|
|
71
|
+
|
|
72
|
+
.container {{
|
|
73
|
+
background: rgba(255, 255, 255, 0.95);
|
|
74
|
+
backdrop-filter: blur(10px);
|
|
75
|
+
padding: 60px;
|
|
76
|
+
border-radius: 20px;
|
|
77
|
+
box-shadow: 0 30px 60px rgba(0, 0, 0, 0.12);
|
|
78
|
+
text-align: center;
|
|
79
|
+
max-width: 480px;
|
|
80
|
+
width: 90%;
|
|
81
|
+
transform: translateY(-20px);
|
|
82
|
+
animation: slideUp 0.6s ease-out;
|
|
83
|
+
}}
|
|
84
|
+
|
|
85
|
+
@keyframes slideUp {{
|
|
86
|
+
from {{
|
|
87
|
+
opacity: 0;
|
|
88
|
+
transform: translateY(0);
|
|
89
|
+
}}
|
|
90
|
+
to {{
|
|
91
|
+
opacity: 1;
|
|
92
|
+
transform: translateY(-20px);
|
|
93
|
+
}}
|
|
94
|
+
}}
|
|
95
|
+
|
|
96
|
+
.icon {{
|
|
97
|
+
width: 80px;
|
|
98
|
+
height: 80px;
|
|
99
|
+
margin: 0 auto 30px;
|
|
100
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
101
|
+
border-radius: 50%;
|
|
102
|
+
display: flex;
|
|
103
|
+
align-items: center;
|
|
104
|
+
justify-content: center;
|
|
105
|
+
font-size: 40px;
|
|
106
|
+
color: white;
|
|
107
|
+
animation: pulse 2s ease-in-out infinite;
|
|
108
|
+
}}
|
|
109
|
+
|
|
110
|
+
@keyframes pulse {{
|
|
111
|
+
0%, 100% {{
|
|
112
|
+
transform: scale(1);
|
|
113
|
+
}}
|
|
114
|
+
50% {{
|
|
115
|
+
transform: scale(1.05);
|
|
116
|
+
}}
|
|
117
|
+
}}
|
|
118
|
+
|
|
119
|
+
h1 {{
|
|
120
|
+
font-size: 28px;
|
|
121
|
+
font-weight: 600;
|
|
122
|
+
margin-bottom: 20px;
|
|
123
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
124
|
+
-webkit-background-clip: text;
|
|
125
|
+
-webkit-text-fill-color: transparent;
|
|
126
|
+
background-clip: text;
|
|
127
|
+
}}
|
|
128
|
+
|
|
129
|
+
.message {{
|
|
130
|
+
font-size: 16px;
|
|
131
|
+
line-height: 1.6;
|
|
132
|
+
color: #4a5568;
|
|
133
|
+
margin-bottom: 20px;
|
|
134
|
+
}}
|
|
135
|
+
|
|
136
|
+
.user-id {{
|
|
137
|
+
font-weight: 600;
|
|
138
|
+
color: #667eea;
|
|
139
|
+
padding: 4px 12px;
|
|
140
|
+
background: rgba(102, 126, 234, 0.1);
|
|
141
|
+
border-radius: 6px;
|
|
142
|
+
display: inline-block;
|
|
143
|
+
margin: 0 4px;
|
|
144
|
+
}}
|
|
145
|
+
|
|
146
|
+
.button {{
|
|
147
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
148
|
+
color: white;
|
|
149
|
+
padding: 16px 40px;
|
|
150
|
+
border: none;
|
|
151
|
+
border-radius: 30px;
|
|
152
|
+
font-size: 16px;
|
|
153
|
+
font-weight: 500;
|
|
154
|
+
cursor: pointer;
|
|
155
|
+
transition: all 0.3s ease;
|
|
156
|
+
margin-top: 30px;
|
|
157
|
+
display: inline-block;
|
|
158
|
+
text-decoration: none;
|
|
159
|
+
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
|
|
160
|
+
}}
|
|
161
|
+
|
|
162
|
+
.button:hover {{
|
|
163
|
+
transform: translateY(-2px);
|
|
164
|
+
box-shadow: 0 7px 20px rgba(102, 126, 234, 0.4);
|
|
165
|
+
}}
|
|
166
|
+
|
|
167
|
+
.button:active {{
|
|
168
|
+
transform: translateY(0);
|
|
169
|
+
}}
|
|
170
|
+
|
|
171
|
+
.auto-close {{
|
|
172
|
+
font-size: 13px;
|
|
173
|
+
color: #a0aec0;
|
|
174
|
+
margin-top: 30px;
|
|
175
|
+
opacity: 0.8;
|
|
176
|
+
}}
|
|
177
|
+
</style>
|
|
178
|
+
<script>
|
|
179
|
+
function tryClose() {{
|
|
180
|
+
window.close();
|
|
181
|
+
// If window.close() was blocked by the browser, update the UI
|
|
182
|
+
setTimeout(function() {{
|
|
183
|
+
var btn = document.querySelector('.button');
|
|
184
|
+
if (btn) btn.textContent = 'You can close this tab manually';
|
|
185
|
+
var ac = document.querySelector('.auto-close');
|
|
186
|
+
if (ac) ac.style.display = 'none';
|
|
187
|
+
}}, 500);
|
|
188
|
+
}}
|
|
189
|
+
setTimeout(tryClose, 10000);
|
|
190
|
+
</script>
|
|
191
|
+
</head>
|
|
192
|
+
<body>
|
|
193
|
+
<div class="container">
|
|
194
|
+
<div class="icon">✓</div>
|
|
195
|
+
<h1>Authentication Successful</h1>
|
|
196
|
+
<div class="message">
|
|
197
|
+
You've been authenticated as <span class="user-id">{html_escape(user_display)}</span>
|
|
198
|
+
</div>
|
|
199
|
+
<div class="message">
|
|
200
|
+
Your credentials have been securely saved. You can now close this tab and retry your original command.
|
|
201
|
+
</div>
|
|
202
|
+
<button class="button" onclick="tryClose()">Close Tab</button>
|
|
203
|
+
<div class="auto-close">This tab will close automatically in 10 seconds</div>
|
|
204
|
+
</div>
|
|
205
|
+
</body>
|
|
206
|
+
</html>"""
|
|
207
|
+
return HTMLResponse(content=content)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def create_server_error_response(error_detail: str) -> HTMLResponse:
|
|
211
|
+
"""
|
|
212
|
+
Create a standardized server error response for OAuth processing failures.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
error_detail: The detailed error message
|
|
216
|
+
|
|
217
|
+
Returns:
|
|
218
|
+
HTMLResponse with server error page
|
|
219
|
+
"""
|
|
220
|
+
content = f"""
|
|
221
|
+
<html>
|
|
222
|
+
<head><title>Authentication Processing Error</title></head>
|
|
223
|
+
<body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 600px; margin: 40px auto; padding: 20px; text-align: center;">
|
|
224
|
+
<h2 style="color: #d32f2f;">Authentication Processing Error</h2>
|
|
225
|
+
<p>An unexpected error occurred while processing your authentication: {html_escape(error_detail)}</p>
|
|
226
|
+
<p>Please try again. You can close this tab.</p>
|
|
227
|
+
</body>
|
|
228
|
+
</html>
|
|
229
|
+
"""
|
|
230
|
+
return HTMLResponse(content=content, status_code=500)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Type definitions for OAuth authentication.
|
|
3
|
+
|
|
4
|
+
This module provides structured types for OAuth-related parameters,
|
|
5
|
+
improving code maintainability and type safety.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import Optional, List, Dict, Any
|
|
10
|
+
|
|
11
|
+
from fastmcp.server.auth import AccessToken
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class WorkspaceAccessToken(AccessToken):
|
|
15
|
+
"""AccessToken extended with workspace-specific fields."""
|
|
16
|
+
|
|
17
|
+
session_id: Optional[str] = None
|
|
18
|
+
sub: Optional[str] = None
|
|
19
|
+
email: Optional[str] = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class OAuth21ServiceRequest:
|
|
24
|
+
"""
|
|
25
|
+
Encapsulates parameters for OAuth 2.1 service authentication requests.
|
|
26
|
+
|
|
27
|
+
This parameter object pattern reduces function complexity and makes
|
|
28
|
+
it easier to extend authentication parameters in the future.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
service_name: str
|
|
32
|
+
version: str
|
|
33
|
+
tool_name: str
|
|
34
|
+
user_google_email: str
|
|
35
|
+
required_scopes: List[str]
|
|
36
|
+
session_id: Optional[str] = None
|
|
37
|
+
auth_token_email: Optional[str] = None
|
|
38
|
+
allow_recent_auth: bool = False
|
|
39
|
+
context: Optional[Dict[str, Any]] = None
|
|
40
|
+
|
|
41
|
+
def to_legacy_params(self) -> dict:
|
|
42
|
+
"""Convert to legacy parameter format for backward compatibility."""
|
|
43
|
+
return {
|
|
44
|
+
"service_name": self.service_name,
|
|
45
|
+
"version": self.version,
|
|
46
|
+
"tool_name": self.tool_name,
|
|
47
|
+
"user_google_email": self.user_google_email,
|
|
48
|
+
"required_scopes": self.required_scopes,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class OAuthVersionDetectionParams:
|
|
54
|
+
"""
|
|
55
|
+
Parameters used for OAuth version detection.
|
|
56
|
+
|
|
57
|
+
Encapsulates the various signals we use to determine
|
|
58
|
+
whether a client supports OAuth 2.1 or needs OAuth 2.0.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
client_id: Optional[str] = None
|
|
62
|
+
client_secret: Optional[str] = None
|
|
63
|
+
code_challenge: Optional[str] = None
|
|
64
|
+
code_challenge_method: Optional[str] = None
|
|
65
|
+
code_verifier: Optional[str] = None
|
|
66
|
+
authenticated_user: Optional[str] = None
|
|
67
|
+
session_id: Optional[str] = None
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
def from_request(
|
|
71
|
+
cls, request_params: Dict[str, Any]
|
|
72
|
+
) -> "OAuthVersionDetectionParams":
|
|
73
|
+
"""Create from raw request parameters."""
|
|
74
|
+
return cls(
|
|
75
|
+
client_id=request_params.get("client_id"),
|
|
76
|
+
client_secret=request_params.get("client_secret"),
|
|
77
|
+
code_challenge=request_params.get("code_challenge"),
|
|
78
|
+
code_challenge_method=request_params.get("code_challenge_method"),
|
|
79
|
+
code_verifier=request_params.get("code_verifier"),
|
|
80
|
+
authenticated_user=request_params.get("authenticated_user"),
|
|
81
|
+
session_id=request_params.get("session_id"),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def has_pkce(self) -> bool:
|
|
86
|
+
"""Check if PKCE parameters are present."""
|
|
87
|
+
return bool(self.code_challenge or self.code_verifier)
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def is_public_client(self) -> bool:
|
|
91
|
+
"""Check if this appears to be a public client (no secret)."""
|
|
92
|
+
return bool(self.client_id and not self.client_secret)
|