Environment Variables¶
Canvas CLI can be configured using environment variables.
Available Variables¶
| Variable | Description | Default |
|---|---|---|
CANVAS_URL |
Canvas instance URL (env auth mode) | From config |
CANVAS_TOKEN |
API access token | From config/keyring |
CANVAS_REQUESTS_PER_SEC |
Request rate limit for env auth mode | 5.0 |
CANVAS_OUTPUT |
Default output format | table |
CANVAS_NO_CACHE |
Disable response caching | false |
Usage¶
Temporary Override¶
Set for a single command:
Session Override¶
Set for the current shell session:
Permanent Configuration¶
Add to your shell profile (~/.bashrc, ~/.zshrc, etc.):
# Canvas CLI configuration
export CANVAS_URL=https://canvas.example.com
export CANVAS_TOKEN=your-api-token
export CANVAS_OUTPUT=json
Variable Details¶
CANVAS_URL¶
The Canvas LMS instance URL.
Priority
When both CANVAS_URL and CANVAS_TOKEN are set, CLI commands use env authentication directly.
In that mode, --instance and default_instance are not used.
CANVAS_TOKEN¶
Canvas API access token. Generate from Canvas Account Settings.
CANVAS_REQUESTS_PER_SEC¶
Request rate limit used when env auth mode is active.
Security
Avoid setting tokens in shared environments. Consider using the config file or keyring instead.
CANVAS_OUTPUT¶
Default output format for commands.
| Value | Description |
|---|---|
table |
Human-readable table (default) |
json |
JSON format |
yaml |
YAML format |
csv |
CSV format |
CANVAS_NO_CACHE¶
Disable API response caching.
When to Disable
Disable caching when you need real-time data or are debugging.
Precedence Order¶
Configuration is applied in this order (highest precedence first):
- If both
CANVAS_URLandCANVAS_TOKENare set, env auth mode is used - Otherwise, command-line flags (
--instance,--output, etc.) - Otherwise, configuration file (
~/.canvas-cli/config.yaml) - Built-in defaults
MCP clients
This same precedence applies to MCP tool calls, because MCP executes the same command logic. Each MCP client runs its own server process and therefore may have different environment variables.
Example Configurations¶
Development Environment¶
# Use sandbox instance
export CANVAS_URL=https://canvas-sandbox.example.com
export CANVAS_TOKEN=sandbox-token
export CANVAS_NO_CACHE=true
CI/CD Pipeline¶
# GitHub Actions example
env:
CANVAS_URL: ${{ secrets.CANVAS_URL }}
CANVAS_TOKEN: ${{ secrets.CANVAS_TOKEN }}
CANVAS_OUTPUT: json
Multi-Instance Setup¶
# Function to switch instances
canvas-prod() {
export CANVAS_URL=https://canvas.example.com
export CANVAS_TOKEN=$CANVAS_PROD_TOKEN
}
canvas-sandbox() {
export CANVAS_URL=https://canvas-sandbox.example.com
export CANVAS_TOKEN=$CANVAS_SANDBOX_TOKEN
}
Troubleshooting¶
Variable Not Working¶
-
Verify the variable is set:
-
Check for typos in variable names
-
Ensure you've sourced your profile:
Token Security¶
If your token is exposed:
- Immediately regenerate it in Canvas Account Settings
- Update your configuration
- Consider using the config file with restrictive permissions: