Documentation Index
Fetch the complete documentation index at: https://docs.mcp-use.com/llms.txt
Use this file to discover all available pages before exploring further.
Context helpers for accessing authentication in tools.
get_access_token
function get_access_token
Get the current authenticated user’s access token.Returns None if the request is not authenticated.Example:from mcp_use.server.auth import get_access_token
@server.tool()
def whoami() -> str:
token = get_access_token()
if not token:
return "Not authenticated"
return f"Hello \{token.claims.get('email')\}"
from mcp_use.server.auth.dependencies import get_access_token
Returns
Signature
require_auth
function require_auth
Get the access token or raise AuthenticationError if not authenticated.Example:from mcp_use.server.auth import require_auth
@server.tool()
def admin_action() -> str:
token = require_auth() # Raises if not authenticated
if "admin" not in token.scopes:
return "Admin scope required"
return "Admin action performed"
from mcp_use.server.auth.dependencies import require_auth
Returns
Signature
set_access_token
function set_access_token
Set the current access token (called by AuthMiddleware).from mcp_use.server.auth.dependencies import set_access_token
Parameters
token
AccessToken | None
required
Parameter value
Signaturedef set_access_token(token: AccessToken | None):