Gmail MCP Server
A Model Context Protocol (MCP) server that provides read-only Gmail access to AI assistants like Claude Code. Built in Java 21 using the official MCP Java SDK.
接入你的智能体
從發布者安裝。不是 PlugMCP 端點。
遠端 URL 還是本機指令? 兩種安裝方式的差異
來自發布者
A Model Context Protocol (MCP) server that provides read-only Gmail access to AI assistants like Claude Code. Built in Java 21 using the official MCP Java SDK.
MCP server providing read-only Gmail tools for AI assistants like Claude Code
All access is read-only (GMAIL_READONLY scope). The server cannot send, modify, or delete emails.
Attachments are discovered via read_email (which includes an attachments array with metadata) and fetched individually via get_attachment:
text/*) return decoded content inlineimage/*, up to 10 MB) are returned as inline ImageContent for visual analysis~/.gmail-mcp/attachments/<messageId>/ and the file path is returned~/.gmail-mcp/client_secret.jsongit clone https://github.com/wrxck/gmail-mcp.git
cd gmail-mcp
mvn clean package
This produces a single uber-jar at target/gmail-mcp-1.3.0.jar.
java -jar target/gmail-mcp-1.3.0.jar --auth
This opens your browser for Google OAuth consent. After authorizing, credentials are saved to ~/.gmail-mcp/tokens/ and automatically refreshed on expiry. You only need to do this once.
claude mcp add --scope user --transport stdio gmail -- \
java -jar /path/to/gmail-mcp-1.3.0.jar
Restart Claude Code. The 4 Gmail tools will be available immediately.
Once registered, you can ask Claude:
<message-id>"Email content is untrusted third-party data that gets returned directly into an LLM's context. A malicious email could contain text designed to manipulate the agent into taking unintended actions. This server applies defense-in-depth mitigations:
SecureRandom). Untrusted fields (from, subject, snippet, body, filename, content) are wrapped with this boundary so the LLM can distinguish email data from system structure. Since the boundary is unpredictable, an attacker cannot embed it in their email to escape the content region.list_emails, read_email, search_emails, and get_attachment tool descriptions explicitly warn that returned content is untrusted.[TRUNCATED] indicator to prevent oversized payloads from overwhelming context. Attachment content is truncated at 100,000 characters.text/* attachments return decoded content inline. image/* attachments (up to 10 MB) are returned as ImageContent for vision analysis. All other binary attachments are saved to ~/.gmail-mcp/attachments/ with sanitized filenames, and the file path is returned. Filenames from emails are sanitized to prevent path traversal attacks.Claude Code <--stdio (JSON-RPC)--> gmail-mcp.jar <--HTTPS--> Gmail API
|
~/.gmail-mcp/
client_secret.json
tokens/StoredCredential
GoogleAuthorizationCodeFlow with FileDataStoreFactory handles token persistence and automatic refreshCredentials are stored in ~/.gmail-mcp/ with restricted permissions (rwx------):
~/.gmail-mcp/
client_secret.json # OAuth client credentials (you provide this)
tokens/ # Stored OAuth tokens (auto-managed)
StoredCredential
attachments/ # Saved binary attachments (auto-managed, rwx------)
<messageId>/
<sanitized-filename>
# Build
mvn clean package
# Run tests
mvn test
# Run auth flow
java -jar target/gmail-mcp-1.3.0.jar --auth
# Run server (blocks on stdio — use with Claude Code or an MCP client)
java -jar target/gmail-mcp-1.3.0.jar
src/main/java/com/gmail/mcp/
GmailMcpServer.java # Main class, MCP tool definitions
GmailAuth.java # OAuth flow, credential management
GmailClient.java # Gmail API wrapper
ContentSanitizer.java # Prompt injection mitigations
src/test/java/com/gmail/mcp/
ContentSanitizerTest.java # Boundary wrapping, truncation, sanitization
ResponsePipelineTest.java # End-to-end response pipeline (email vs label tools)
GmailClientTest.java # HTML stripping, base64 decoding, body extraction
GmailMcpServerTest.java # Argument parsing
MCP server providing read-only Gmail tools for AI assistants like Claude Code
工具
尚無工具清單。遠端伺服器會在首次健康檢查後取得工具清單。
常見問題
在本頁複製適用於 Cursor、Claude Desktop、Claude Code 或 VS Code 的 stdio 設定。它使用發布者的安裝方式,而不是 PlugMCP 代理伺服器。
這筆記錄未列出必要的環境變數。
Gmail 透過 stdio 在本機執行。
上次檢查時間:2026-10-27。 MCP server providing read-only Gmail tools for AI assistants like Claude Code