remove mcp session id

This commit is contained in:
Taylor Wilsdon
2025-07-26 12:05:22 -04:00
parent 0aeed0cc16
commit f0976514e2
4 changed files with 13 additions and 44 deletions

View File

@@ -16,7 +16,6 @@ from auth.oauth_responses import create_error_response, create_success_response,
# Import shared configuration
from auth.scopes import (
OAUTH_STATE_TO_SESSION_ID_MAP,
SCOPES,
USERINFO_EMAIL_SCOPE, # noqa: F401
OPENID_SCOPE, # noqa: F401
@@ -129,11 +128,7 @@ async def oauth2_callback(request: Request) -> HTMLResponse:
logger.info(f"OAuth callback: Received code (state: {state}). Attempting to exchange for tokens.")
mcp_session_id: Optional[str] = OAUTH_STATE_TO_SESSION_ID_MAP.pop(state, None)
if mcp_session_id:
logger.info(f"OAuth callback: Retrieved MCP session ID '{mcp_session_id}' for state '{state}'.")
else:
logger.warning(f"OAuth callback: No MCP session ID found for state '{state}'. Auth will not be tied to a specific session directly via this callback.")
# Session ID tracking removed - not needed
# Exchange code for credentials. handle_auth_callback will save them.
# The user_id returned here is the Google-verified email.
@@ -141,11 +136,10 @@ async def oauth2_callback(request: Request) -> HTMLResponse:
scopes=SCOPES, # Ensure all necessary scopes are requested
authorization_response=str(request.url),
redirect_uri=get_oauth_redirect_uri_for_current_mode(),
session_id=mcp_session_id # Pass session_id if available
session_id=None # Session ID tracking removed
)
log_session_part = f" (linked to session: {mcp_session_id})" if mcp_session_id else ""
logger.info(f"OAuth callback: Successfully authenticated user: {verified_user_id} (state: {state}){log_session_part}.")
logger.info(f"OAuth callback: Successfully authenticated user: {verified_user_id} (state: {state}).")
# Return success page using shared template
return create_success_response(verified_user_id)
@@ -159,14 +153,13 @@ async def oauth2_callback(request: Request) -> HTMLResponse:
@server.tool()
async def start_google_auth(
service_name: str,
user_google_email: str = USER_GOOGLE_EMAIL,
mcp_session_id: Optional[str] = Header(None, alias="mcp-session-id")
user_google_email: str = USER_GOOGLE_EMAIL
) -> str:
"""
Initiates the Google OAuth 2.0 authentication flow for the specified user email and service.
This is the primary method to establish credentials when no valid session exists or when targeting a specific account for a particular service.
It generates an authorization URL that the LLM must present to the user.
The authentication attempt is linked to the current MCP session via `mcp_session_id`.
This initiates a new authentication flow for the specified user and service.
LLM Guidance:
- Use this tool when you need to authenticate a user for a specific Google service (e.g., "Google Calendar", "Google Docs", "Gmail", "Google Drive")
@@ -182,7 +175,6 @@ async def start_google_auth(
Args:
user_google_email (str): The user's full Google email address (e.g., 'example@gmail.com'). This is REQUIRED.
service_name (str): The name of the Google service for which authentication is being requested (e.g., "Google Calendar", "Google Docs"). This is REQUIRED.
mcp_session_id (Optional[str]): The active MCP session ID (automatically injected by FastMCP from the mcp-session-id header). Links the OAuth flow state to the session.
Returns:
str: A detailed message for the LLM with the authorization URL and instructions to guide the user through the authentication process.
@@ -197,7 +189,7 @@ async def start_google_auth(
logger.error(f"[start_google_auth] {error_msg}")
raise Exception(error_msg)
logger.info(f"Tool 'start_google_auth' invoked for user_google_email: '{user_google_email}', service: '{service_name}', session: '{mcp_session_id}'.")
logger.info(f"Tool 'start_google_auth' invoked for user_google_email: '{user_google_email}', service: '{service_name}'.")
# Ensure OAuth callback is available for current transport mode
redirect_uri = get_oauth_redirect_uri_for_current_mode()
@@ -205,7 +197,6 @@ async def start_google_auth(
raise Exception("Failed to start OAuth callback server. Please try again.")
auth_result = await start_auth_flow(
mcp_session_id=mcp_session_id,
user_google_email=user_google_email,
service_name=service_name,
redirect_uri=redirect_uri