Update scalekit token-inspection docs to v2 get_access_token()

This commit is contained in:
Jeremiah Lowin 2026-07-05 23:58:31 -04:00
commit 960b7b36dd
No known key found for this signature in database
2 changed files with 14 additions and 28 deletions

View file

@ -134,22 +134,15 @@ logging.basicConfig(level=logging.DEBUG)
You can inspect JWT tokens in your tools to understand the user context:
```python
from fastmcp.server.context import request_ctx
import jwt
from fastmcp.server.dependencies import get_access_token
@mcp.tool
def inspect_token() -> dict:
"""Inspect the current JWT token claims."""
context = request_ctx.get()
token = get_access_token()
if token is None:
return {"error": "No token found"}
# Extract token from Authorization header
if hasattr(context, 'request') and hasattr(context.request, 'headers'):
auth_header = context.request.headers.get('authorization', '')
if auth_header.startswith('Bearer '):
token = auth_header[7:]
# Decode without verification (already verified by provider)
claims = jwt.decode(token, options={"verify_signature": False})
return claims
return {"error": "No token found"}
# Claims were already verified by the auth provider.
return token.claims
```

View file

@ -173,22 +173,15 @@ logging.basicConfig(level=logging.DEBUG)
You can inspect JWT tokens in your tools to understand the user context:
```python
from fastmcp.server.context import request_ctx
import jwt
from fastmcp.server.dependencies import get_access_token
@mcp.tool
def inspect_token() -> dict:
"""Inspect the current JWT token claims."""
context = request_ctx.get()
token = get_access_token()
if token is None:
return {"error": "No token found"}
# Extract token from Authorization header
if hasattr(context, 'request') and hasattr(context.request, 'headers'):
auth_header = context.request.headers.get('authorization', '')
if auth_header.startswith('Bearer '):
token = auth_header[7:]
# Decode without verification (already verified by provider)
claims = jwt.decode(token, options={"verify_signature": False})
return claims
return {"error": "No token found"}
# Claims were already verified by the auth provider.
return token.claims
```