{"id":26937449,"url":"https://github.com/baryhuang/mcp-headless-gmail","last_synced_at":"2026-01-12T13:31:04.509Z","repository":{"id":283427931,"uuid":"951719324","full_name":"baryhuang/mcp-headless-gmail","owner":"baryhuang","description":"A MCP (Model Context Protocol) server that provides get, send Gmails without local credential or token setup.","archived":false,"fork":false,"pushed_at":"2025-05-24T17:24:30.000Z","size":66,"stargazers_count":34,"open_issues_count":1,"forks_count":20,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-24T18:31:06.672Z","etag":null,"topics":["ai-assistant","gmail","gmail-bot","google-suite","mcp","mcp-server"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baryhuang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-20T06:12:47.000Z","updated_at":"2025-05-24T17:24:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"210326c5-0b1b-4e57-9551-833e141aad19","html_url":"https://github.com/baryhuang/mcp-headless-gmail","commit_stats":null,"previous_names":["baryhuang/mcp-headless-gmail"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/baryhuang/mcp-headless-gmail","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baryhuang%2Fmcp-headless-gmail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baryhuang%2Fmcp-headless-gmail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baryhuang%2Fmcp-headless-gmail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baryhuang%2Fmcp-headless-gmail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baryhuang","download_url":"https://codeload.github.com/baryhuang/mcp-headless-gmail/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baryhuang%2Fmcp-headless-gmail/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28339140,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-assistant","gmail","gmail-bot","google-suite","mcp","mcp-server"],"created_at":"2025-04-02T13:15:14.857Z","updated_at":"2026-01-12T13:31:04.488Z","avatar_url":"https://github.com/baryhuang.png","language":"Python","funding_links":[],"categories":["Productivity","Messaging Mcp Servers","📚 Projects (1974 total)","Community Servers","🤖 AI/ML","MCP 服务器精选列表","Communication","Email and Messaging","カテゴリ","Table of Contents"],"sub_categories":["Google Workspace","MCP Servers","💬 通讯与协作 (Slack, Email, Calendar, Social, etc.)","How to Submit","💬 \u003ca name=\"communication\"\u003e\u003c/a\u003eコミュニケーション","Communication"],"readme":"# MCP Headless Gmail Server (NPM \u0026 Docker)\n\n[![npm version](https://img.shields.io/npm/v/@peakmojo/mcp-server-headless-gmail.svg)](https://www.npmjs.com/package/@peakmojo/mcp-server-headless-gmail) [![Docker Pulls](https://img.shields.io/docker/pulls/buryhuang/mcp-headless-gmail)](https://hub.docker.com/r/buryhuang/mcp-headless-gmail) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA MCP (Model Context Protocol) server that provides get, send Gmails without local credential or token setup.\n\n\u003ca href=\"https://glama.ai/mcp/servers/@baryhuang/mcp-headless-gmail\"\u003e\n  \u003cimg width=\"380\" height=\"200\" src=\"https://glama.ai/mcp/servers/@baryhuang/mcp-headless-gmail/badge\" alt=\"Headless Gmail Server MCP server\" /\u003e\n\u003c/a\u003e\n\n## Why MCP Headless Gmail Server?\n### Critical Advantages\n- **Headless \u0026 Remote Operation**: Unlike other MCP Gmail solutions that require running outside of docker and local file access, this server can run completely headless in remote environments with no browser no local file access.\n- **Decoupled Architecture**: Any client can complete the OAuth flow independently, then pass credentials as context to this MCP server, creating a complete separation between credential storage and server implementation.\n\n### Nice but not critical\n- **Focused Functionality**: In many use cases, especially for marketing applications, only Gmail access is needed without additional Google services like Calendar, making this focused implementation ideal.\n- **Docker-Ready**: Designed with containerization in mind for a well-isolated, environment-independent, one-click setup.\n- **Reliable Dependencies**: Built on the well-maintained google-api-python-client library.\n\n## Features\n\n- Get most recent emails from Gmail with the first 1k characters of the body\n- Get full email body content in 1k chunks using offset parameter\n- Send emails through Gmail\n- Refresh access tokens separately\n- Automatic refresh token handling\n\n## Prerequisites\n\n- Python 3.10 or higher\n- Google API credentials (client ID, client secret, access token, and refresh token)\n\n## Installation\n\n```bash\n# Clone the repository\ngit clone https://github.com/baryhuang/mcp-headless-gmail.git\ncd mcp-headless-gmail\n\n# Install dependencies\npip install -e .\n```\n\n## Docker\n\n### Building the Docker Image\n\n```bash\n# Build the Docker image\ndocker build -t mcp-headless-gmail .\n```\n\n## Usage with Claude Desktop\n\nYou can configure Claude Desktop to use the Docker image by adding the following to your Claude configuration:\n\ndocker\n```json\n{\n  \"mcpServers\": {\n    \"gmail\": {\n      \"command\": \"docker\",\n      \"args\": [\n        \"run\",\n        \"-i\",\n        \"--rm\",\n        \"buryhuang/mcp-headless-gmail:latest\"\n      ]\n    }\n  }\n}\n```\n\nnpm version\n```json\n{\n  \"mcpServers\": {\n    \"gmail\": {\n      \"command\": \"npx\",\n      \"args\": [\n        \"@peakmojo/mcp-server-headless-gmail\"\n      ]\n    }\n  }\n}\n```\n\nNote: With this configuration, you'll need to provide your Google API credentials in the tool calls as shown in the [Using the Tools](#using-the-tools) section. Gmail credentials are not passed as environment variables to maintain separation between credential storage and server implementation.\n\n## Cross-Platform Publishing\n\nTo publish the Docker image for multiple platforms, you can use the `docker buildx` command. Follow these steps:\n\n1. **Create a new builder instance** (if you haven't already):\n   ```bash\n   docker buildx create --use\n   ```\n\n2. **Build and push the image for multiple platforms**:\n   ```bash\n   docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t buryhuang/mcp-headless-gmail:latest --push .\n   ```\n\n3. **Verify the image is available for the specified platforms**:\n   ```bash\n   docker buildx imagetools inspect buryhuang/mcp-headless-gmail:latest\n   ```\n\n## Usage\n\nThe server provides Gmail functionality through MCP tools. Authentication handling is simplified with a dedicated token refresh tool.\n\n### Starting the Server\n\n```bash\nmcp-server-headless-gmail\n```\n\n### Using the Tools\n\nWhen using an MCP client like Claude, you have two main ways to handle authentication:\n\n#### Refreshing Tokens (First Step or When Tokens Expire)\n\nIf you have both access and refresh tokens:\n```json\n{\n  \"google_access_token\": \"your_access_token\",\n  \"google_refresh_token\": \"your_refresh_token\",\n  \"google_client_id\": \"your_client_id\",\n  \"google_client_secret\": \"your_client_secret\"\n}\n```\n\nIf your access token has expired, you can refresh with just the refresh token:\n```json\n{\n  \"google_refresh_token\": \"your_refresh_token\",\n  \"google_client_id\": \"your_client_id\",\n  \"google_client_secret\": \"your_client_secret\"\n}\n```\n\nThis will return a new access token and its expiration time, which you can use for subsequent calls.\n\n#### Getting Recent Emails\n\nRetrieves recent emails with the first 1k characters of each email body:\n\n```json\n{\n  \"google_access_token\": \"your_access_token\",\n  \"max_results\": 5,\n  \"unread_only\": false\n}\n```\n\nResponse includes:\n- Email metadata (id, threadId, from, to, subject, date, etc.)\n- First 1000 characters of the email body\n- `body_size_bytes`: Total size of the email body in bytes\n- `contains_full_body`: Boolean indicating if the entire body is included (true) or truncated (false)\n\n#### Getting Full Email Body Content\n\nFor emails with bodies larger than 1k characters, you can retrieve the full content in chunks:\n\n```json\n{\n  \"google_access_token\": \"your_access_token\",\n  \"message_id\": \"message_id_from_get_recent_emails\",\n  \"offset\": 0\n}\n```\n\nYou can also get email content by thread ID:\n\n```json\n{\n  \"google_access_token\": \"your_access_token\",\n  \"thread_id\": \"thread_id_from_get_recent_emails\",\n  \"offset\": 1000\n}\n```\n\nThe response includes:\n- A 1k chunk of the email body starting from the specified offset\n- `body_size_bytes`: Total size of the email body\n- `chunk_size`: Size of the returned chunk\n- `contains_full_body`: Boolean indicating if the chunk contains the remainder of the body\n\nTo retrieve the entire email body of a long message, make sequential calls increasing the offset by 1000 each time until `contains_full_body` is true.\n\n#### Sending an Email\n\n```json\n{\n  \"google_access_token\": \"your_access_token\",\n  \"to\": \"recipient@example.com\",\n  \"subject\": \"Hello from MCP Gmail\",\n  \"body\": \"This is a test email sent via MCP Gmail server\",\n  \"html_body\": \"\u003cp\u003eThis is a \u003cstrong\u003etest email\u003c/strong\u003e sent via MCP Gmail server\u003c/p\u003e\"\n}\n```\n\n### Token Refresh Workflow\n\n1. Start by calling the `gmail_refresh_token` tool with either:\n   - Your full credentials (access token, refresh token, client ID, and client secret), or\n   - Just your refresh token, client ID, and client secret if the access token has expired\n2. Use the returned new access token for subsequent API calls.\n3. If you get a response indicating token expiration, call the `gmail_refresh_token` tool again to get a new token.\n\nThis approach simplifies most API calls by not requiring client credentials for every operation, while still enabling token refresh when needed.\n\n## Obtaining Google API Credentials\n\nTo obtain the required Google API credentials, follow these steps:\n\n1. Go to the [Google Cloud Console](https://console.cloud.google.com/)\n2. Create a new project\n3. Enable the Gmail API\n4. Configure OAuth consent screen\n5. Create OAuth client ID credentials (select \"Desktop app\" as the application type)\n6. Save the client ID and client secret\n7. Use OAuth 2.0 to obtain access and refresh tokens with the following scopes:\n   - `https://www.googleapis.com/auth/gmail.readonly` (for reading emails)\n   - `https://www.googleapis.com/auth/gmail.send` (for sending emails)\n\n## Token Refreshing\n\nThis server implements automatic token refreshing. When your access token expires, the Google API client will use the refresh token, client ID, and client secret to obtain a new access token without requiring user intervention.\n\n## Security Note\n\nThis server requires direct access to your Google API credentials. Always keep your tokens and credentials secure and never share them with untrusted parties.\n\n## License\n\nSee the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaryhuang%2Fmcp-headless-gmail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaryhuang%2Fmcp-headless-gmail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaryhuang%2Fmcp-headless-gmail/lists"}