Skip to main content
get_credentials() retrieves the authenticated user’s credentials for your tools.

Signature

The signature depends on your auth type:
# For oauth or cred auth types (async)
async def get_credentials() -> dict[str, str]

# For none auth type (sync)
def get_credentials() -> dict[str, str]

Return value

Auth typeReturns
oauth{"access_token": "..."}
credKeys from config.yaml credentials
noneKeys from environment variables

Usage

OAuth

@mcp.tool()
async def list_issues() -> list[Issue]:
    creds = await get_credentials()
    token = creds["access_token"]
    
    async with httpx.AsyncClient() as client:
        resp = await client.get(
            "https://api.linear.app/issues",
            headers={"Authorization": f"Bearer {token}"}
        )
        return resp.json()

User credentials

# config.yaml
# auth:
#   type: cred
#   credentials:
#     - name: "api_key"
#       label: "API Key"

@mcp.tool()
async def generate(prompt: str) -> str:
    creds = await get_credentials()
    api_key = creds["api_key"]
    # Use api_key

Environment variables

# config.yaml
# auth:
#   type: none

@mcp.tool()
def get_weather(city: str) -> Weather:
    creds = get_credentials()  # Note: sync, not async
    api_key = creds["api_key"]
    # Use api_key from env var

Local development

For local testing, get_credentials() reads from LOCAL_* environment variables when ENVIRONMENT=local:
# src/utils/auth.py
async def get_credentials() -> dict[str, str]:
    if os.environ.get("ENVIRONMENT") == "local":
        return {
            "api_key": os.environ.get("LOCAL_API_KEY", ""),
        }
    
    from mcp.gumstack import get_credentials as gumstack_get_credentials
    return await gumstack_get_credentials()
# .env
ENVIRONMENT=local
LOCAL_API_KEY=test-key-for-development

Errors

No authentication context

GumstackError: No authentication context available
The request wasn’t authenticated. This happens if:
  • Token validation failed
  • Middleware not configured correctly

Credentials not found

GumstackError: Credentials not found for provider 'linear'
The user hasn’t connected their account. For OAuth, they need to authorize via the Gumstack UI first.