This guide is for autonomous AI agents that need direct access to email, calendar, and contacts through shell commands. Follow the steps below — do as much as you can yourself, and only ask the user when you hit a step that requires a browser.
If you are a coding agent helping a developer build a SaaS application, see Quickstart: Coding agents instead.
Rules for agents
Section titled “Rules for agents”- Always pass
--jsonto get structured output you can parse. Without it, the CLI returns human-formatted text. - Always pass
--yeswhen sending email or deleting anything. Without it, the CLI blocks waiting for confirmation. - Always pass
--limiton list commands to control token consumption. Start with 5, increase if needed. - Prefer the CLI over raw API calls. The CLI handles OAuth token refresh, provider normalization, and pagination for you.
- Do not hardcode grant IDs. Run
nylas auth whoami --jsonto discover the active grant at runtime, or set theNYLAS_GRANT_IDenvironment variable.
Step 1: Check if already set up
Section titled “Step 1: Check if already set up”Before installing anything, check if the CLI is already configured:
nylas auth whoami --jsonIf this returns JSON with email, provider, grant_id, and status, you’re ready. Skip to Step 4.
If the command fails (command not found), continue to Step 2.
If the command runs but returns an error (no active grant), skip to Step 3.
Step 2: Install the CLI
Section titled “Step 2: Install the CLI”Install the CLI yourself:
brew install nylas/nylas-cli/nylasIf Homebrew is not available:
curl -fsSL https://cli.nylas.com/install.sh | bashVerify the install worked:
nylas demo email listThis returns sample data with no credentials required, confirming the binary is working.
Step 3: Set up credentials
Section titled “Step 3: Set up credentials”This is the one step that may need user involvement. Ask the user: “Do you have an existing Nylas API key?”
If yes, do the setup yourself:
nylas init --api-key <NYLAS_API_KEY>For EU data residency:
nylas init --api-key <NYLAS_API_KEY> --region euIf no (or they’re not sure), ask them to run one command. This opens a browser for account creation and SSO login — the only step that requires a human:
Run
nylas initin your terminal. It will open a browser to sign in. Once you’re done, I’ll take it from here.
After either path, verify credentials are working:
nylas auth whoami --jsonExpected output:
{ "provider": "google", "grant_id": "d3f4a5b6-c7d8-9e0f-a1b2-c3d4e5f6g7h8", "status": "valid"}If you need the raw API key for any reason:
nylas auth tokenThis prints the API key as a plain string, nothing else.
Step 4: Verify and start using
Section titled “Step 4: Verify and start using”Run a quick test to confirm everything works:
nylas email list --limit 3 --jsonExpected output (a flat JSON array):
[ { "id": "msg_abc123", "subject": "Learn how to Send Email with Nylas APIs", "snippet": "Send Email with Nylas APIs", "date": 1706811644, "unread": true, "folders": ["INBOX", "UNREAD"] }]If this returns an error, check error.type:
{ "request_id": "5fa64c92-e840-4357-86b9-2aa364d35b88", "error": { "type": "unauthorized", "message": "Unauthorized" }}Common error types: unauthorized (bad/expired key — run nylas dashboard apps apikeys create), not_found_error (invalid grant — run nylas auth login), rate_limit_error (slow down and retry).
You’re now set up. Use the commands below.
Step 5: MCP or CLI commands
Section titled “Step 5: MCP or CLI commands”If your agent supports MCP
Section titled “If your agent supports MCP”For agents that support Model Context Protocol (Claude Code, Claude Desktop, Cursor, Windsurf, VS Code), register the CLI as an MCP server. This gives you 16 email, calendar, and contacts tools without subprocess calls:
nylas mcp install --assistant claude-codenylas mcp install --assistant cursornylas mcp install --assistant windsurfnylas mcp install --assistant vscodenylas mcp install --all # installs for all detected assistantsVerify with nylas mcp status. With MCP active, you don’t need the commands below — the MCP server handles everything.
Email commands
Section titled “Email commands”# List recent emailsnylas email list --limit 5 --json
# List unread emails onlynylas email list --unread --limit 10 --json
# Search for specific emailsnylas email search "meeting agenda" --limit 5 --json
# Read a specific message by IDnylas email read <MESSAGE_ID> --json
# Send an emailnylas email send \ --subject "Meeting follow-up" \ --body "Thanks for the meeting. Here are the action items we discussed." \ --yes
# Send with CC, BCC, or scheduled deliverynylas email send \ --subject "Project update" \ --body "Status report attached." \ --schedule "tomorrow 9am" \ --yesCalendar commands
Section titled “Calendar commands”# List upcoming eventsnylas calendar events list --days 7 --json
# Create an eventnylas calendar events create \ --title "Sync meeting" \ --start "2026-04-10T10:00:00" \ --end "2026-04-10T10:30:00"
# Find a time that works for multiple peoplenylas calendar find-time \ --duration 30m \ --json
# Natural language schedulingnylas calendar schedule ai "Find 30 minutes with Alice next week"Contacts commands
Section titled “Contacts commands”nylas contacts list --limit 10 --jsonnylas contacts search --query "Alice" --jsonAccount commands
Section titled “Account commands”# See which mailbox you're operating onnylas auth whoami --json
# List all connected mailboxesnylas auth list
# Switch to a different mailboxnylas auth switch
# Connect another email account (requires user -- opens browser)nylas auth loginTroubleshooting
Section titled “Troubleshooting”| Symptom | Fix |
|---|---|
nylas: command not found | Run the install command again, or use the full path (/opt/homebrew/bin/nylas) |
nylas auth whoami returns an error | Ask the user to run nylas init (requires browser) |
error.type: "unauthorized" | Run nylas dashboard apps apikeys create to generate a new API key |
No active application | Ask the user to run nylas init (requires browser) |
| Commands hang | Add --yes to skip confirmation prompts |
| Empty results | Run nylas auth list to check accounts, nylas auth switch to change |
Go deeper
Section titled “Go deeper”When you need to look up API details, endpoints, or provider-specific behavior:
# Curated sitemap for agents (start here)curl https://developer.nylas.com/llms.txt
# Full documentation in one filecurl https://developer.nylas.com/llms-full.txt
# Any single page as clean markdowncurl -H "Accept: text/markdown" https://developer.nylas.com/docs/v3/email/- Nylas CLI on GitHub — source code, issues, and releases
- CLI command reference — every command and flag documented
- CLI guides — 85+ step-by-step guides for email, calendar, MCP, and more
- Build an LLM agent with email tools — wire CLI commands into an agent loop with OpenAI-compatible tool definitions
- Give agents email via MCP — full MCP setup guide
- Audit agent activity — track actions with source detection and compliance exports