workspace-mcp 1.0.0__py3-none-any.whl → 1.0.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.
- auth/service_decorator.py +31 -32
- core/server.py +3 -10
- core/utils.py +36 -0
- gcalendar/calendar_tools.py +308 -258
- gchat/chat_tools.py +131 -158
- gdocs/docs_tools.py +121 -149
- gdrive/drive_tools.py +168 -171
- gforms/forms_tools.py +118 -157
- gmail/gmail_tools.py +319 -400
- gsheets/sheets_tools.py +144 -197
- gslides/slides_tools.py +113 -157
- main.py +31 -25
- workspace_mcp-1.0.2.dist-info/METADATA +422 -0
- workspace_mcp-1.0.2.dist-info/RECORD +32 -0
- workspace_mcp-1.0.0.dist-info/METADATA +0 -29
- workspace_mcp-1.0.0.dist-info/RECORD +0 -32
- {workspace_mcp-1.0.0.dist-info → workspace_mcp-1.0.2.dist-info}/WHEEL +0 -0
- {workspace_mcp-1.0.0.dist-info → workspace_mcp-1.0.2.dist-info}/entry_points.txt +0 -0
- {workspace_mcp-1.0.0.dist-info → workspace_mcp-1.0.2.dist-info}/licenses/LICENSE +0 -0
- {workspace_mcp-1.0.0.dist-info → workspace_mcp-1.0.2.dist-info}/top_level.txt +0 -0
auth/service_decorator.py
CHANGED
@@ -193,29 +193,37 @@ def require_google_service(
|
|
193
193
|
# Original authentication logic is handled automatically
|
194
194
|
"""
|
195
195
|
def decorator(func: Callable) -> Callable:
|
196
|
+
# Inspect the original function signature
|
197
|
+
original_sig = inspect.signature(func)
|
198
|
+
params = list(original_sig.parameters.values())
|
199
|
+
|
200
|
+
# The decorated function must have 'service' as its first parameter.
|
201
|
+
if not params or params[0].name != 'service':
|
202
|
+
raise TypeError(
|
203
|
+
f"Function '{func.__name__}' decorated with @require_google_service "
|
204
|
+
"must have 'service' as its first parameter."
|
205
|
+
)
|
206
|
+
|
207
|
+
# Create a new signature for the wrapper that excludes the 'service' parameter.
|
208
|
+
# This is the signature that FastMCP will see.
|
209
|
+
wrapper_sig = original_sig.replace(parameters=params[1:])
|
210
|
+
|
196
211
|
@wraps(func)
|
197
212
|
async def wrapper(*args, **kwargs):
|
198
|
-
#
|
199
|
-
|
200
|
-
param_names = list(sig.parameters.keys())
|
213
|
+
# Note: `args` and `kwargs` are now the arguments for the *wrapper*,
|
214
|
+
# which does not include 'service'.
|
201
215
|
|
202
|
-
#
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
else:
|
207
|
-
# Look for user_google_email in positional args
|
208
|
-
try:
|
209
|
-
user_email_index = param_names.index('user_google_email')
|
210
|
-
if user_email_index < len(args):
|
211
|
-
user_google_email = args[user_email_index]
|
212
|
-
except ValueError:
|
213
|
-
pass
|
216
|
+
# Extract user_google_email from the arguments passed to the wrapper
|
217
|
+
bound_args = wrapper_sig.bind(*args, **kwargs)
|
218
|
+
bound_args.apply_defaults()
|
219
|
+
user_google_email = bound_args.arguments.get('user_google_email')
|
214
220
|
|
215
221
|
if not user_google_email:
|
216
|
-
|
222
|
+
# This should ideally not be reached if 'user_google_email' is a required parameter
|
223
|
+
# in the function signature, but it's a good safeguard.
|
224
|
+
raise Exception("'user_google_email' parameter is required but was not found.")
|
217
225
|
|
218
|
-
# Get service configuration
|
226
|
+
# Get service configuration from the decorator's arguments
|
219
227
|
if service_type not in SERVICE_CONFIGS:
|
220
228
|
raise Exception(f"Unknown service type: {service_type}")
|
221
229
|
|
@@ -226,7 +234,7 @@ def require_google_service(
|
|
226
234
|
# Resolve scopes
|
227
235
|
resolved_scopes = _resolve_scopes(scopes)
|
228
236
|
|
229
|
-
#
|
237
|
+
# --- Service Caching and Authentication Logic (largely unchanged) ---
|
230
238
|
service = None
|
231
239
|
actual_user_email = user_google_email
|
232
240
|
|
@@ -236,7 +244,6 @@ def require_google_service(
|
|
236
244
|
if cached_result:
|
237
245
|
service, actual_user_email = cached_result
|
238
246
|
|
239
|
-
# If not cached, authenticate
|
240
247
|
if service is None:
|
241
248
|
try:
|
242
249
|
tool_name = func.__name__
|
@@ -247,30 +254,22 @@ def require_google_service(
|
|
247
254
|
user_google_email=user_google_email,
|
248
255
|
required_scopes=resolved_scopes,
|
249
256
|
)
|
250
|
-
|
251
|
-
# Cache the service if caching is enabled
|
252
257
|
if cache_enabled:
|
253
258
|
cache_key = _get_cache_key(user_google_email, service_name, service_version, resolved_scopes)
|
254
259
|
_cache_service(cache_key, service, actual_user_email)
|
255
|
-
|
256
260
|
except GoogleAuthenticationError as e:
|
257
261
|
raise Exception(str(e))
|
258
262
|
|
259
|
-
#
|
260
|
-
if 'service' in param_names:
|
261
|
-
kwargs['service'] = service
|
262
|
-
else:
|
263
|
-
# Insert service as first positional argument
|
264
|
-
args = (service,) + args
|
265
|
-
|
266
|
-
# Call the original function with refresh error handling
|
263
|
+
# --- Call the original function with the service object injected ---
|
267
264
|
try:
|
268
|
-
|
265
|
+
# Prepend the fetched service object to the original arguments
|
266
|
+
return await func(service, *args, **kwargs)
|
269
267
|
except RefreshError as e:
|
270
|
-
# Handle token refresh errors gracefully
|
271
268
|
error_message = _handle_token_refresh_error(e, actual_user_email, service_name)
|
272
269
|
raise Exception(error_message)
|
273
270
|
|
271
|
+
# Set the wrapper's signature to the one without 'service'
|
272
|
+
wrapper.__signature__ = wrapper_sig
|
274
273
|
return wrapper
|
275
274
|
return decorator
|
276
275
|
|
core/server.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import logging
|
2
2
|
import os
|
3
|
-
from typing import
|
3
|
+
from typing import Optional
|
4
4
|
from importlib import metadata
|
5
5
|
|
6
6
|
from fastapi import Header
|
@@ -86,18 +86,17 @@ async def health_check(request: Request):
|
|
86
86
|
"""Health check endpoint for container orchestration."""
|
87
87
|
from fastapi.responses import JSONResponse
|
88
88
|
try:
|
89
|
-
version = metadata.version("
|
89
|
+
version = metadata.version("workspace-mcp")
|
90
90
|
except metadata.PackageNotFoundError:
|
91
91
|
version = "dev"
|
92
92
|
return JSONResponse({
|
93
93
|
"status": "healthy",
|
94
|
-
"service": "
|
94
|
+
"service": "workspace-mcp",
|
95
95
|
"version": version,
|
96
96
|
"transport": _current_transport_mode
|
97
97
|
})
|
98
98
|
|
99
99
|
|
100
|
-
# Register OAuth callback as a custom route
|
101
100
|
@server.custom_route("/oauth2callback", methods=["GET"])
|
102
101
|
async def oauth2_callback(request: Request) -> HTMLResponse:
|
103
102
|
"""
|
@@ -105,8 +104,6 @@ async def oauth2_callback(request: Request) -> HTMLResponse:
|
|
105
104
|
This endpoint exchanges the authorization code for credentials and saves them.
|
106
105
|
It then displays a success or error page to the user.
|
107
106
|
"""
|
108
|
-
# State is used by google-auth-library for CSRF protection and should be present.
|
109
|
-
# We don't need to track it ourselves in this simplified flow.
|
110
107
|
state = request.query_params.get("state")
|
111
108
|
code = request.query_params.get("code")
|
112
109
|
error = request.query_params.get("error")
|
@@ -122,7 +119,6 @@ async def oauth2_callback(request: Request) -> HTMLResponse:
|
|
122
119
|
return create_error_response(error_message)
|
123
120
|
|
124
121
|
try:
|
125
|
-
# Use the centralized CONFIG_CLIENT_SECRETS_PATH
|
126
122
|
client_secrets_path = CONFIG_CLIENT_SECRETS_PATH
|
127
123
|
if not os.path.exists(client_secrets_path):
|
128
124
|
logger.error(f"OAuth client secrets file not found at {client_secrets_path}")
|
@@ -207,13 +203,10 @@ async def start_google_auth(
|
|
207
203
|
if not ensure_oauth_callback_available(_current_transport_mode, WORKSPACE_MCP_PORT, WORKSPACE_MCP_BASE_URI):
|
208
204
|
raise Exception("Failed to start OAuth callback server. Please try again.")
|
209
205
|
|
210
|
-
# Use the centralized start_auth_flow from auth.google_auth
|
211
206
|
auth_result = await start_auth_flow(
|
212
207
|
mcp_session_id=mcp_session_id,
|
213
208
|
user_google_email=user_google_email,
|
214
209
|
service_name=service_name,
|
215
210
|
redirect_uri=redirect_uri
|
216
211
|
)
|
217
|
-
|
218
|
-
# auth_result is now a plain string, not a CallToolResult
|
219
212
|
return auth_result
|
core/utils.py
CHANGED
@@ -160,3 +160,39 @@ def extract_office_xml_text(file_bytes: bytes, mime_type: str) -> Optional[str]:
|
|
160
160
|
except Exception as e:
|
161
161
|
logger.error(f"Failed to extract office XML text for {mime_type}: {e}", exc_info=True)
|
162
162
|
return None
|
163
|
+
|
164
|
+
import functools
|
165
|
+
from googleapiclient.errors import HttpError
|
166
|
+
|
167
|
+
def handle_http_errors(tool_name: str):
|
168
|
+
"""
|
169
|
+
A decorator to handle Google API HttpErrors in a standardized way.
|
170
|
+
|
171
|
+
It wraps a tool function, catches HttpError, logs a detailed error message,
|
172
|
+
and raises a generic Exception with a user-friendly message.
|
173
|
+
|
174
|
+
Args:
|
175
|
+
tool_name (str): The name of the tool being decorated (e.g., 'list_calendars').
|
176
|
+
This is used for logging purposes.
|
177
|
+
"""
|
178
|
+
def decorator(func):
|
179
|
+
@functools.wraps(func)
|
180
|
+
async def wrapper(*args, **kwargs):
|
181
|
+
try:
|
182
|
+
return await func(*args, **kwargs)
|
183
|
+
except HttpError as error:
|
184
|
+
user_google_email = kwargs.get('user_google_email', 'N/A')
|
185
|
+
message = (
|
186
|
+
f"API error in {tool_name}: {error}. "
|
187
|
+
f"You might need to re-authenticate for user '{user_google_email}'. "
|
188
|
+
f"LLM: Try 'start_google_auth' with the user's email and the appropriate service_name."
|
189
|
+
)
|
190
|
+
logger.error(message, exc_info=True)
|
191
|
+
raise Exception(message)
|
192
|
+
except Exception as e:
|
193
|
+
# Catch any other unexpected errors
|
194
|
+
message = f"An unexpected error occurred in {tool_name}: {e}"
|
195
|
+
logger.exception(message)
|
196
|
+
raise Exception(message)
|
197
|
+
return wrapper
|
198
|
+
return decorator
|