stateless mode for fastmcp entrypoint

This commit is contained in:
Taylor Wilsdon
2025-08-23 11:19:46 -04:00
parent 8f9a46e55b
commit 3280a76a65
2 changed files with 35 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
import inspect
import logging
import re
from functools import wraps
from typing import Dict, List, Optional, Any, Callable, Union, Tuple
@@ -38,9 +39,7 @@ from auth.scopes import (
CUSTOM_SEARCH_SCOPE,
)
# OAuth 2.1 integration is now handled by FastMCP auth
OAUTH21_INTEGRATION_AVAILABLE = True
logger = logging.getLogger(__name__)
# Authentication helper functions
def _get_auth_context(
@@ -236,9 +235,6 @@ async def get_authenticated_google_service_oauth21(
return service, user_google_email
logger = logging.getLogger(__name__)
def _remove_user_email_arg_from_docstring(docstring: str) -> str:
"""
Remove user_google_email parameter documentation from docstring.

View File

@@ -33,6 +33,9 @@ logging.basicConfig(
)
logger = logging.getLogger(__name__)
# Skip file logging in stateless mode
stateless_mode = os.getenv("WORKSPACE_MCP_STATELESS_MODE", "false").lower() == "true"
if not stateless_mode:
# Configure file logging
try:
root_logger = logging.getLogger()
@@ -52,6 +55,8 @@ try:
logger.debug(f"Detailed file logging configured to: {log_file_path}")
except Exception as e:
sys.stderr.write(f"CRITICAL: Failed to set up file logging to '{log_file_path}': {e}\n")
else:
logger.debug("File logging disabled in stateless mode")
def configure_safe_logging():
"""Configure safe Unicode handling for logging."""
@@ -76,7 +81,8 @@ def configure_safe_logging():
# Configure safe logging
configure_safe_logging()
# Check credentials directory permissions
# Check credentials directory permissions (skip in stateless mode)
if not stateless_mode:
try:
logger.info("🔍 Checking credentials directory permissions...")
check_credentials_directory_permissions()
@@ -85,6 +91,8 @@ except (PermissionError, OSError) as e:
logger.error(f"❌ Credentials directory permission check failed: {e}")
logger.error(" Please ensure the service has write permissions to create/access the credentials directory")
sys.exit(1)
else:
logger.info("🔍 Skipping credentials directory check (stateless mode)")
# Set transport mode for HTTP (FastMCP CLI defaults to streamable-http)
set_transport_mode('streamable-http')