Enable end-user OAuth flows for MCP server connections with delegated access
MCP End-User Authentication allows your agents to access services on behalf of individual users. Instead of using shared integration credentials, each user authenticates with their own account, enabling personalized and secure access.
from xpander_sdk import Backend, UserAuthbackend = Backend()auth = UserAuth(backend)# Check if user has authorizeduser_id = "user-123"is_authorized = auth.is_authorized( user_id=user_id, connector="google-calendar")if not is_authorized: # Get OAuth URL for user auth_url = auth.get_authorization_url( user_id=user_id, connector="google-calendar", redirect_uri="https://myapp.com/callback" ) print(f"User needs to authorize: {auth_url}")
from xpander_sdk import Backendfrom agno.agent import Agentbackend = Backend()# User context automatically appliedagent = Agent( **backend.get_args(), user_id="user-123" # Requests use this user's tokens)# Agent uses user-123's Google Calendar credentialsresponse = agent.run("What meetings do I have today?")
For Slack agents, end-user auth happens automatically:
Copy
Ask AI
from xpander_sdk import Backendbackend = Backend()# Slack user ID extracted from message# Their OAuth tokens used for connected servicestask = backend.get_current_task()slack_user_id = task.metadata.get("slack_user_id")# Connector calls use this user's tokens
from xpander_sdk import UserAuthauth = UserAuth(backend)# List all authorizations for a userauthorizations = auth.list_authorizations(user_id="user-123")for authz in authorizations: print(f"{authz.connector}: {authz.scopes}") print(f" Authorized: {authz.created_at}") print(f" Last used: {authz.last_used_at}")