removes user_google_email argument from tool schema under multi-user mode
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from functools import wraps
|
||||
from typing import Dict, List, Optional, Any, Callable, Union, Tuple
|
||||
|
||||
@@ -237,6 +239,40 @@ async def get_authenticated_google_service_oauth21(
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _remove_user_email_arg_from_docstring(docstring: str) -> str:
|
||||
"""
|
||||
Remove user_google_email parameter documentation from docstring.
|
||||
|
||||
Args:
|
||||
docstring: The original function docstring
|
||||
|
||||
Returns:
|
||||
Modified docstring with user_google_email parameter removed
|
||||
"""
|
||||
if not docstring:
|
||||
return docstring
|
||||
|
||||
# Pattern to match user_google_email parameter documentation
|
||||
# Handles various formats like:
|
||||
# - user_google_email (str): The user's Google email address. Required.
|
||||
# - user_google_email: Description
|
||||
# - user_google_email (str) - Description
|
||||
patterns = [
|
||||
r'^\s*user_google_email\s*\([^)]*\)\s*:\s*[^\n]*\.?\s*(?:Required\.?)?\s*\n',
|
||||
r'^\s*user_google_email\s*:\s*[^\n]*\n',
|
||||
r'^\s*user_google_email\s*\([^)]*\)\s*-\s*[^\n]*\n',
|
||||
]
|
||||
|
||||
modified_docstring = docstring
|
||||
for pattern in patterns:
|
||||
modified_docstring = re.sub(pattern, '', modified_docstring, flags=re.MULTILINE)
|
||||
|
||||
# Clean up any sequence of 3 or more newlines that might have been created
|
||||
modified_docstring = re.sub(r'\n{3,}', '\n\n', modified_docstring)
|
||||
|
||||
return modified_docstring
|
||||
|
||||
# Service configuration mapping
|
||||
SERVICE_CONFIGS = {
|
||||
"gmail": {"service": "gmail", "version": "v1"},
|
||||
@@ -485,6 +521,12 @@ def require_google_service(
|
||||
|
||||
# Set the wrapper's signature to the one without 'service'
|
||||
wrapper.__signature__ = wrapper_sig
|
||||
|
||||
# Conditionally modify docstring to remove user_google_email parameter documentation
|
||||
if os.getenv('MCP_REMOVE_USER_GOOGLE_EMAIL_ARG', False) == '1' and os.getenv('MCP_SINGLE_USER_MODE') != '1':
|
||||
if func.__doc__:
|
||||
wrapper.__doc__ = _remove_user_email_arg_from_docstring(func.__doc__)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
Reference in New Issue
Block a user