> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gumstack.com/llms.txt
> Use this file to discover all available pages before exploring further.

# get_credentials

> Retrieve user credentials in your tools

`get_credentials()` retrieves the authenticated user's credentials for your tools.

## Signature

The signature depends on your auth type:

```python theme={"dark"}
# 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 type | Returns                             |
| --------- | ----------------------------------- |
| `oauth`   | `{"access_token": "..."}`           |
| `cred`    | Keys from `config.yaml` credentials |
| `none`    | Keys from environment variables     |

## Usage

### OAuth

```python theme={"dark"}
@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

```python theme={"dark"}
# 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

```python theme={"dark"}
# 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`:

```python theme={"dark"}
# 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()
```

```bash theme={"dark"}
# .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.
