Secure Muse Code Gmail Connection with PortEden
This guide gives Meta's Muse Code coding agent scoped Gmail access with PortEden as the data firewall. You add one MCP server entry to ~/.config/muse/settings.json, sign in, and Muse Code can read and act on Gmail through scoped permissions, with PII redacted before content reaches Meta's model and every tool call recorded in the PortEden audit log. No prior PortEden signup needed.
Image needed
Diagram showing Gmail connecting to PortEden, with PortEden labeled REDACT AUDIT SCOPE, then forwarding to Muse Code in a terminal window
- File:
- public/images/guides/muse-code/muse-code-gmail-cover.png
- Spec:
- 1200x630. Gmail icon on the left, PortEden shield in the middle labeled REDACT / AUDIT / SCOPE, terminal window with the Muse Code prompt on the right, arrows left to right.
- Used as:
- Guide cover + OpenGraph image
In short
- Add one MCP server to
~/.config/muse/settings.json: transportstreamable_http, URLhttps://mcp.porteden.com/email - Restart Muse Code. Authenticate to PortEden on the first email tool call. Sign up in the same flow if you have no account.
- If Gmail is already connected to your PortEden account, the Gmail authorization step is skipped automatically.
- Verify with a read prompt. Tighten permissions, redaction, and contact rules later from my.porteden.com. Every sub-agent inherits the same scope.
What you get
When the connection is live, Muse Code can search, read, summarize, and draft through Gmail using natural language, right in the middle of a coding session: bug reports into test cases, release threads into changelogs. Every tool call, from the lead agent or any parallel sub-agent, routes through PortEden, which applies:
Real-time redaction
Names, emails, phone numbers, account IDs, and 50+ other identifier types are stripped or tokenized before content reaches Meta's model, on any pricing tier.
Per-action permissions
Grant read, draft, send, archive, delete, or label as separate scopes. A read-only token literally cannot send a message, no matter which sub-agent asks.
Contact and time rules
Block or allow specific senders, restrict access to recent mail, exclude entire labels, or hide content older than a date. The coding agent sees the engineering slice of the inbox.
Audit trail
Every tool call from Muse Code is logged centrally: the requested action, the decision (allow, redact, or block), and the response shape returned. SIEM-exportable, unlike per-laptop session logs.
Prerequisites
- Muse Code (beta) installed and authenticated:
curl -fsSL https://dev.meta.ai/install.sh | bash, thenmuse login. Muse Code runs on macOS and Linux; on Windows use WSL2. - A Gmail account you want Muse Code to use. You will authorize it during the flow if your PortEden account does not already have Gmail connected.
No PortEden account yet? That is fine.
Step 1: Add the PortEden MCP server to settings.json
Muse Code configures MCP servers in its user settings file. PortEden runs a hosted MCP server you connect with one URL over the streamable_http transport. Nothing to install, nothing to host.
mkdir -p ~/.config/muse $EDITOR ~/.config/muse/settings.json { "schema_version": 1, "mcp_servers": { "gmail": { "transport": "streamable_http", "url": "https://mcp.porteden.com/email", "mode": "optional" } } } schema_version is mandatory
"schema_version": 1 is missing. "mode": "optional" is recommended so an unreachable server logs a warning instead of aborting your coding run (the default, required, aborts).Want more than email later?
Each PortEden capability has its own MCP URL. Add them as additional entries under mcp_servers the same way, each with its own scoped token:
{ "gmail": "https://mcp.porteden.com/email", "calendar": "https://mcp.porteden.com/calendar", "drive": "https://mcp.porteden.com/drive", "google-docs": "https://mcp.porteden.com/google-docs", "google-sheets": "https://mcp.porteden.com/google-sheets", "tasks": "https://mcp.porteden.com/tasks" } Step 2: Sign in to PortEden
The first time Muse Code calls an email tool, the PortEden server requires authentication. This is the single setup screen you will see. There is nothing to do in advance.
Beta build not opening a sign-in?
"headers": { "Authorization": "Bearer pe_your_token" }. Scoping, redaction, and audit behave identically.What the token looks like
Step 3: Connect Gmail (first-time only)
This step runs only if your PortEden account does not already have Gmail connected. If it does, PortEden reuses the existing Gmail connection and you can jump straight to Step 4.
If Gmail is not connected yet
If Gmail is already connected to PortEden
You will not see a Gmail authorization prompt at all. PortEden detects the existing connection, attaches it to the new Muse Code token, and the next tool call just works. This is the most common path for existing PortEden users.
Workspace accounts
gmail.readonly, plus gmail.send and gmail.modify if Muse Code will draft, send, or label. See the Google OAuth Setup guide if you need a custom OAuth app.Step 4: Verify the connection
In a Muse Code session, run a low-risk read prompt. Then check the PortEden audit log to confirm the request shows up.
Try one of these
What to confirm
- Muse Code returns real data from your Gmail, not a refusal or an error.
- Sensitive identifiers (full email addresses, phone numbers) appear redacted or tokenized if you left redaction enabled.
- The PortEden audit log at my.porteden.com shows the request with a green allow decision.
No data yet? Ask Muse Code to introspect
search_emails, get_email, and list_threads.Step 5: Tighten what Muse Code can do (optional)
The token PortEden created in Step 2 already uses conservative defaults: email scope only, redaction on, and confirm-before-write for send and delete. Once the connection works end-to-end, tighten or relax it from my.porteden.com under Access Tokens. Remember that every sub-agent Muse Code spawns uses this same token, so its scope is the boundary for the whole fleet.
Permission presets for a coding agent
Pick the action set that matches what you want Muse Code to do
| Preset | What Muse Code can do | What it cannot do |
|---|---|---|
| read_only (recommended) | Search, read, summarize, and quote messages | Send, draft, label, archive, delete |
| read_and_draft | Read plus create drafts in the Drafts folder | Send anything outside of drafts |
| read_send | Read plus send replies and new messages | Delete or modify labels |
| full_email | All email actions including label and archive | Touch other PortEden capabilities (calendar, drive) |
Recommended rules for a Muse Code token
- Start read-only: Coding workflows rarely need to send. Grant write actions only when a workflow proves it needs them.
- Redaction: Leave on. What the model never receives cannot be retained or trained on, whatever Meta tier the session runs on.
- Contact blocklist: Add HR, legal, and personal aliases (or whole domains) you do not want a coding agent touching.
- Time window: Restrict to messages from the last 90 days unless a workflow needs history.
- Label exclusions: Block
Confidential,Legal, and any client-specific labels under NDA. - Confirm before write: Keep on for send and delete so a preview surfaces before any outbound action.
Changes apply immediately
Suggested prompts for everyday use
Once the connection is verified, these prompts are good starting points for a coding session. Each maps to a small number of PortEden tool calls, so behavior is predictable and the audit log stays clean.
"Find bug reports emailed to support this week and turn each into a numbered repro checklist."
"Read the thread with subject "v2.4 release" and draft changelog entries for the changes discussed."
"Find every email from ci@ or alerts@ in the last 7 days and group the failures by test suite."
"Summarize what the customer in the "API timeout" thread actually reported, steps and environment only."
"Draft a reply to the latest message in the "staging access" thread saying the fix ships Thursday. Do not send."
"List threads where I was asked a technical question more than three days ago and have not replied."
Troubleshooting and error handling
PortEden returns structured errors that Muse Code surfaces in its replies, and Muse Code adds its own settings validation at startup. Match the message you see to the entries below, then jump to the matching debug prompt in the next section.
Muse Code fails at startup after editing settings.json
Symptoms
- Every muse command fails with "malformed settings file" or "unsupported settings schema version".
Checks
- Validate the JSON: jq . ~/.config/muse/settings.json
- Confirm "schema_version": 1 is present at the top level of the file.
- Confirm the server entry uses only url and headers for streamable_http (command/args belong to stdio; framing fails validation on this transport).
Debug prompt for Muse Code
Muse Code cannot reach the PortEden MCP server
Symptoms
- Muse Code reports the gmail server as unavailable, or the run aborts before starting.
- No request appears in the PortEden audit log.
Checks
- Confirm the URL is exactly https://mcp.porteden.com/email (no trailing slash, no typos).
- Set "mode": "optional" on the server so an unreachable server warns instead of aborting the run (the default is required).
- Check your network can reach mcp.porteden.com: curl -sI https://mcp.porteden.com/email
Debug prompt for Muse Code
No PortEden sign-in ever appears
Symptoms
- Tool calls fail with 401 Unauthorized and no browser window opens.
Checks
- Muse Code is a young beta; some builds may not drive a browser sign-in for remote MCP servers.
- Fallback: create an Access Token at my.porteden.com scoped to email, then add "headers": { "Authorization": "Bearer pe_your_token" } to the server entry and restart.
- Keep the token scoped to email only; create separate tokens for other capabilities.
Debug prompt for Muse Code
401 Unauthorized after the connection was working
Symptoms
- Calls used to work but now all email tool calls fail immediately.
- Audit log shows an auth_failed or token_revoked entry.
Checks
- Open my.porteden.com, go to Access Tokens, and check the token tied to this connection. It may have been revoked, expired, or rotated.
- Re-authenticate on the next tool call, or paste the replacement token into the headers field if you used one.
Debug prompt for Muse Code
403 Permission denied on a specific action
Symptoms
- Muse Code says it lacks permission, or returns an accessInfo string explaining the rejection.
- Audit log shows a block decision with a rule name.
Checks
- Open the Access Token in PortEden and read the permission set. The action attempted may not be enabled (a read_only token cannot send).
- Check the contact and label rules. A blocked sender or excluded label will deny matching messages.
- Look at the time window. Requests outside the allowed window are blocked.
- Adjust the token, save, then retry. The new policy applies on the next request.
Debug prompt for Muse Code
429 Too Many Requests or quota exceeded
Symptoms
- Bursts of tool calls start failing after the first few succeed, especially during sub-agent fan-out.
- Audit log shows rate_limited or quota_exceeded entries.
Checks
- Sub-agent fan-out can multiply call volume; ask Muse Code to batch reads (one search returning 20 messages beats 20 single fetches).
- Check your PortEden plan limits at my.porteden.com on the Billing page.
- If you keep hitting the cap, upgrade the plan or reduce concurrency for mail-heavy tasks.
Debug prompt for Muse Code
Muse Code complains it lost the context
Symptoms
- Responses mention placeholders such as [REDACTED_EMAIL] or [PERSON_1] and the agent asks for more context.
- Drafted replies refer to anonymized names instead of real ones.
Checks
- Decide whether the redacted fields are required for the task. PortEden defaults are conservative, and for most coding workflows placeholders are fine.
- If a workflow genuinely needs internal contact names, open the Access Token and allowlist those contacts or disable name redaction for it.
Debug prompt for Muse Code
Gmail returned reauth required
Symptoms
- Calls were working, then all email tools start failing.
- Audit log shows a provider_reauth_required entry.
Checks
- Open Connections in PortEden. Gmail will show a yellow Needs reauth badge.
- Click Reconnect and complete the Google OAuth flow again. This usually happens after a password change or a Google security event.
Debug prompt for Muse Code
Debug prompts for Muse Code
When something is wrong but the error message is vague, paste one of these prompts into Muse Code. They make the agent self-report the structured response from PortEden so you can pinpoint the cause without leaving the terminal.
Pair every debug prompt with the audit log
Security best practices
Remember the fleet. Muse Code fans out to parallel sub-agents that all use this connection. Scope the token for the widest thing the session might do, not the narrow thing you asked first.
Keep coding-agent tokens read-only. It is easier to grant send later than to clean up after an unexpected outbound email.
One token per AI client. Do not reuse a token across Muse Code, Claude, and ChatGPT. Per-client tokens let you revoke just the one that misbehaves.
Keep redaction on. Meta's contributor API tier documents training rights on submitted data; redacted fields never reach the model on any tier.
MCP is outside Muse Code's sandbox by Meta's own design, and muse --yolo disables the client-side guardrails entirely. PortEden's server-side policy keeps enforcing either way, so put the rules there.
Review the audit log weekly. Filter by the Muse Code token to see what was asked, what was allowed, and what was blocked.
Revoke tokens promptly when an experiment ends. Revocation is instant and does not require touching Google or Muse Code.
FAQ
Do I need a PortEden account before I start?
No. Add the MCP server entry to settings.json first. When the PortEden sign-in opens on the first email tool call, you can sign up at that moment with Google one-click or with email. If you already have an account, it signs you in instead.
I already have a PortEden account with Gmail connected. Do I need to reauthorize Gmail?
No. PortEden detects your existing Gmail connection during the auth flow and skips the Google OAuth step automatically. The next tool call from Muse Code just works.
Does Muse Code store my Gmail OAuth token?
No. The Google OAuth credentials stay inside PortEden. Muse Code only holds a PortEden Access Token scoped to email, which you can revoke at any time without breaking the underlying Google connection.
Will Meta train on my Gmail content?
It depends on the Meta Model API tier behind your session. Meta's standard tier does not include training rights and offers zero data retention on request; the discounted contributor tier documents training rights on submitted data. PortEden reduces what reaches Meta on any tier: PII is redacted, fields are minimized, and access is scoped. Check Meta's current data-use terms for your tier.
Do Muse Code's sub-agents get the same Gmail access?
Yes. Sub-agents use the session's MCP connections, so the PortEden token's scope is the effective boundary for the whole fleet, up to 16 parallel agents. That is why this guide recommends read-only defaults plus contact, label, and time rules.
Can I connect multiple Gmail accounts?
Yes. Each Gmail connection lives independently in PortEden. Add a second server entry (for example 'work-gmail' and 'personal-gmail') pointing at the same URL, authenticate each under the matching PortEden account or profile, and keep the names short and descriptive so the agent picks the right one.
Does this work with Outlook or M365 email?
Yes. PortEden's email capability covers Gmail, Outlook (Microsoft 365), and Exchange. The MCP URL is the same: https://mcp.porteden.com/email. The auth flow lets you connect Outlook instead of Gmail when prompted, and there is a dedicated Outlook guide.
Next steps
Connect PortEden to Muse Code
The general setup reference: all endpoints, settings fields, and troubleshooting.
MCP Email tool reference
All email tools exposed by the PortEden MCP server, with arguments and responses.
Muse Code MCP servers, explained
What Muse Code can reach over MCP and what Meta's docs say about sandboxing and tiers.
Risks of connecting email to AI
A regulator-aware look at what can go wrong, and how PortEden mitigates each risk.