Connecting AI Agents to TrekMail Drive
Configure scoped tokens and MCP safety gates for Drive file automation.
Article details
Type, difficulty, plans, and last updated info.
▼
Article details
Type, difficulty, plans, and last updated info.
- Type
- Reference
- Difficulty
- Intermediate
- Plans
- Starter · Pro · Agency · + Drive Add-on
- Last updated
- Sep 10, 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-linkscreates public links for approved files.monthly-report-uploaderuploads generated PDFs into Account Drive.mailbox-file-assistantsearches one mailbox Drive.storage-monitorreads 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 in a reviewed cleanup workflow |
| 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
This is a self-hosted MCP safety control, not a Drive feature switch. Keep TREKMAIL_ALLOW_DESTRUCTIVE=false for normal Drive work and 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:
drive_spaces_listdrive_storage_summarydrive_browse_folderforspace="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.