Skip to content
Muse Code × Gmail 5 min setup

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: transport streamable_http, URL https://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, then muse 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.

You do not need to create a PortEden account in advance. When the PortEden sign-in opens on Muse Code's first email tool call (Step 2), you can sign up with Google one-click or with email in the same flow. If you already have a PortEden account, you will be signed in instead.

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.

1
Open (or create) the settings file:
mkdir -p ~/.config/muse
$EDITOR ~/.config/muse/settings.json
2
Add the email server entry. If the file is new, this is the whole file:
~/.config/muse/settings.json
{
"schema_version": 1,
"mcp_servers": {
"gmail": {
"transport": "streamable_http",
"url": "https://mcp.porteden.com/email",
"mode": "optional"
}
}
}
3
Save the file and restart Muse Code so it picks up the new server. Continue to Step 2.

schema_version is mandatory

Muse Code refuses to start with a malformed settings file error if "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.

1
Trigger a first call from a Muse Code session, for example: "List the tools available from the gmail server." The PortEden sign-in opens in your browser.
2
If you do not have a PortEden account: click Continue with Google for one-click signup, or use the email option. Your account is created in the same flow.
3
Approve the connection request. PortEden creates a scoped Access Token for this Muse Code connection automatically and stores it on your account. Nothing to copy or manage by hand.

Beta build not opening a sign-in?

Muse Code is a young beta. If your build does not run a browser sign-in for remote MCP servers, create an Access Token at my.porteden.com (scope it to email only) and pass it in the server entry instead: "headers": { "Authorization": "Bearer pe_your_token" }. Scoping, redaction, and audit behave identically.

What the token looks like

The token PortEden issues to Muse Code is scoped to email only, with redaction on and confirm-before-write enabled for send and delete. You can see and tighten it at any time in my.porteden.com under Access Tokens. See Step 5 below.

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

1
PortEden will prompt you to Connect Gmail. Click it.
2
Complete Google's OAuth consent screen. Approve the requested Gmail scopes (read by default; send and modify are requested too so Muse Code can draft when allowed).
3
The window closes. Return to your terminal and retry the prompt; the connection is now live. Move to Step 4.

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

If your Gmail is part of Google Workspace, your admin may need to enable third-party OAuth access. PortEden requests standard Gmail scopes only: 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

Show me my last five unread emails, subjects and senders only.
Find emails mentioning "bug" or "crash" from the past week and list the subjects.
Summarize the most recent thread with the subject containing "release".
List the senders that emailed me most this month.

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

If the response is empty or vague, send this prompt:
List every tool you have available from the gmail MCP server, with a one-line description each.
A working connection will show tools like 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

PresetWhat Muse Code can doWhat it cannot do
read_only (recommended)Search, read, summarize, and quote messagesSend, draft, label, archive, delete
read_and_draftRead plus create drafts in the Drafts folderSend anything outside of drafts
read_sendRead plus send replies and new messagesDelete or modify labels
full_emailAll email actions including label and archiveTouch 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

PortEden re-evaluates the token on every tool call from Muse Code. There is no reconnect, no restart, no token rotation. Save the change in the dashboard and the very next request, from the lead agent or any sub-agent, uses the new rules.

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.

Bug triage

"Find bug reports emailed to support this week and turn each into a numbered repro checklist."

Changelog

"Read the thread with subject "v2.4 release" and draft changelog entries for the changes discussed."

Search

"Find every email from ci@ or alerts@ in the last 7 days and group the failures by test suite."

Context

"Summarize what the customer in the "API timeout" thread actually reported, steps and environment only."

Draft

"Draft a reply to the latest message in the "staging access" thread saying the fix ships Thursday. Do not send."

Follow up

"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.

SETTINGS_MALFORMED

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

Not applicable, this one fails before a session starts. Fix the JSON and rerun muse.
MCP_UNREACHABLE

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

Try calling any tool from the gmail MCP server and report the exact error, status code, or connection failure you receive.
AUTH_NOT_PROMPTED

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

Call any gmail tool and quote the full error response, including any WWW-Authenticate header or auth URL it mentions.
AUTH_REVOKED

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

Call the PortEden whoami tool and quote the JSON response back to me, including any error message verbatim.
PERMISSION_DENIED

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

Show me the full accessInfo field from the last error response, then summarize which permission, contact rule, or time window blocked the call.
RATE_LIMIT

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

Quote the last rate_limit or quota_exceeded response from the PortEden server, including the retry_after value if present.
REDACTION_TOO_AGGRESSIVE

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

List the field types that came back redacted in the last response and propose which ones I could safely allow for this workflow.
CONNECTION_DROPPED

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

Quote the last provider_reauth_required error from PortEden and tell me which provider needs to be reconnected.

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.

Nothing is happening
"List every MCP server configured in this session and mark whether each one is currently reachable."
Tool exists but fails
"Call the gmail server's whoami or health tool. Quote the full JSON response, including any error code."
Permission denied
"Re-run the last failing call. From the response, quote the accessInfo field verbatim and tell me which rule blocked it."
Strange data back
"Show me the raw JSON of the last successful PortEden tool response, truncated to the first 1000 characters, so I can inspect the shape."
Sub-agent confusion
"Which of your sub-agents made email tool calls in this session, and what did each request?"
Quota or limits
"Quote the last response that mentioned quota, rate_limit, or retry_after, including all numeric fields."

Pair every debug prompt with the audit log

PortEden's audit log shows the raw decision for every tool call, including calls made by sub-agents. If Muse Code's answer disagrees with what PortEden recorded, trust the audit log. Open my.porteden.com and filter by token name. Muse Code's own local JSONL session logs (~/.local/share/muse/sessions/) are useful for the client-side view.

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