View the source code for this module on GitHub: https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/server/auth/dependencies.py
Context helpers for accessing authentication in tools API Documentation
function get_access_tokenfrom 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
Signature
def get_access_token():
function require_authfrom 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
Signature
def require_auth():
Was this page helpful?