TrekMail TrekMail

Connecting AI Agents to TrekMail Drive

This guide explains Configure scoped tokens and MCP safety gates for Drive file automation. so you can complete the TrekMail task with confidence.

Article details

Type, difficulty, plans, and last updated info.

Type
Reference
Difficulty
Intermediate
Plans
Starter · Pro · Agency · + Drive Add-on
Last updated
May 9, 2026

An AI agent can manage Drive files safely when you give it a narrow token and clear rules. This guide focuses on Drive-specific setup for MCP-compatible agents. For general MCP installation, see Connecting AI Agents (MCP).

Choose the agent's job

Start by naming the workflow, not the tool. Good examples:

  • client-delivery-links creates public links for approved files.
  • monthly-report-uploader uploads generated PDFs into Account Drive.
  • mailbox-file-assistant searches one mailbox Drive.
  • storage-monitor reads usage and add-on status.

A focused name makes token review and audit logs much easier later.

Create a scoped token

Open AI Agents & API → Tokens → Create token. For a Drive-only agent, select only Drive scopes. Most agents do not need purge.

Examples:

Agent job Scopes Notes
Upload reports drive:account:read, drive:account:write Can create folders and upload files
Share delivery files drive:account:read, drive:account:share Can create and revoke public links
Mailbox assistant drive:mailbox:read Add mailbox constraints
Cleanup job read/write plus specific purge scope Use only with destructive gate enabled
Storage monitor drive:addon:read, drive:account:read Read-only

Copy the token once. TrekMail will not show it again.

Configure MCP

Set the ops token in your MCP environment:

TREKMAIL_BASE_URL=https://trekmail.net
TREKMAIL_API_TOKEN=tm_live_your_token
TREKMAIL_ALLOW_DESTRUCTIVE=false

Keep TREKMAIL_ALLOW_DESTRUCTIVE=false for normal Drive work. Turn it on only for a reviewed cleanup run that needs purge tools.

If the same agent also reads or sends email, add a message token separately:

TREKMAIL_MESSAGE_TOKEN=tm_msg_your_message_token

Drive tools do not use message tokens. Message tools do not use Drive scopes.

Test with harmless tools first

Ask the agent to call:

  1. drive_spaces_list
  2. drive_storage_summary
  3. drive_browse_folder for space="account"

These calls confirm the token works without changing data. Then test a small upload in a temporary folder.

Give the agent safe operating rules

A practical system prompt for a Drive agent should include:

  • Never purge files unless the user explicitly asks.
  • Prefer Trash over permanent delete.
  • Add expiry and download limits to public links.
  • Return created share URLs immediately.
  • Use Account Drive for team files and mailbox Drive only when the task names a mailbox.
  • Check storage usage before uploading large files.

Audit after setup

Open AI Agents & API → Audit Log and filter by token name. Verify that the agent only called the expected Drive tools. If a token has too many scopes, revoke it and create a narrower replacement.

Related articles

Jump to nearby guides that continue the workflow.

We use cookies for essential functionality. No ads, no ad tracking.

or
or

Reset email sent

If an account exists for this email, we've sent password reset instructions.

By continuing, you agree to TrekMail's Terms and Privacy Policy.