Skip to content

Commit 167c5f9

Browse files
committed
Initial commit: Gmail Postmaster Tools MCP server (v2 API, BYO Google OAuth)
0 parents  commit 167c5f9

12 files changed

Lines changed: 1051 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Build and Release MCPB
2+
3+
# On a version tag (e.g. v1.0.0) this:
4+
# 1. builds the .mcpb bundle
5+
# 2. attaches it to a GitHub Release
6+
# 3. publishes the server to the MCP Registry (hash + metadata computed here,
7+
# authenticated via GitHub OIDC — no secrets, no manual SHA needed)
8+
9+
on:
10+
push:
11+
tags:
12+
- "v*"
13+
workflow_dispatch:
14+
15+
permissions:
16+
contents: write
17+
id-token: write
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Check out
24+
uses: actions/checkout@v5
25+
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v5
28+
with:
29+
node-version: "lts/*"
30+
31+
- name: Validate manifest
32+
run: npx --yes @anthropic-ai/mcpb validate manifest.json
33+
34+
- name: Pack bundle
35+
run: npx --yes @anthropic-ai/mcpb pack . gmail-postmaster-tools.mcpb
36+
37+
- name: Show bundle info
38+
run: npx --yes @anthropic-ai/mcpb info gmail-postmaster-tools.mcpb
39+
40+
- name: Upload bundle as build artifact
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: gmail-postmaster-tools-mcpb
44+
path: gmail-postmaster-tools.mcpb
45+
46+
- name: Attach bundle to release
47+
if: startsWith(github.ref, 'refs/tags/')
48+
uses: softprops/action-gh-release@v2
49+
with:
50+
files: gmail-postmaster-tools.mcpb
51+
generate_release_notes: true
52+
53+
# ---- Publish to the MCP Registry (tags only) ----
54+
55+
- name: Fill server.json (version, asset URL, SHA-256)
56+
if: startsWith(github.ref, 'refs/tags/')
57+
run: |
58+
TAG="${GITHUB_REF#refs/tags/}"
59+
VERSION="${TAG#v}"
60+
URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${TAG}/gmail-postmaster-tools.mcpb"
61+
SHA="$(sha256sum gmail-postmaster-tools.mcpb | awk '{print $1}')"
62+
jq --arg v "$VERSION" --arg id "$URL" --arg sha "$SHA" \
63+
'.version=$v | .packages[0].identifier=$id | .packages[0].fileSha256=$sha' \
64+
server.json > server.tmp && mv server.tmp server.json
65+
echo "Published metadata:"; cat server.json
66+
67+
- name: Install mcp-publisher
68+
if: startsWith(github.ref, 'refs/tags/')
69+
run: |
70+
curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher
71+
72+
- name: Authenticate to MCP Registry (GitHub OIDC)
73+
if: startsWith(github.ref, 'refs/tags/')
74+
run: ./mcp-publisher login github-oidc
75+
76+
- name: Publish to MCP Registry
77+
if: startsWith(github.ref, 'refs/tags/')
78+
run: ./mcp-publisher publish

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Build output
2+
*.mcpb
3+
4+
# Tooling deps (no runtime deps required)
5+
node_modules/
6+
package-lock.json
7+
8+
# Local token cache (never commit)
9+
.gmail-postmaster-mcp/
10+
tokens.json
11+
12+
# OS / editor cruft
13+
.DS_Store
14+
Thumbs.db
15+
*.log
16+
.idea/
17+
.vscode/

.mcpbignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Files excluded from the packed .mcpb bundle (dev/CI only)
2+
.git/
3+
.github/
4+
.gitignore
5+
.mcpbignore
6+
CONTRIBUTING.md
7+
server.json
8+
node_modules/
9+
package-lock.json
10+
*.mcpb
11+
.DS_Store

CONTRIBUTING.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Contributing
2+
3+
Thanks for your interest in improving the Gmail Postmaster Tools MCP!
4+
5+
## Project layout
6+
7+
```
8+
manifest.json # MCPB manifest (tools, runtime, user_config)
9+
server/
10+
index.js # MCP stdio server + tool definitions/dispatch
11+
auth.js # Google OAuth (auth-code + PKCE, 127.0.0.1 loopback), token cache
12+
gpt.js # Gmail Postmaster Tools API v2 REST client
13+
.github/workflows/ # CI: pack + attach .mcpb + publish to MCP Registry on tags
14+
```
15+
16+
The runtime has **zero dependencies** — only Node.js built-ins (`http`, `https`,
17+
`crypto`, `readline`). Please keep it that way unless there's a strong reason.
18+
19+
## Local development
20+
21+
Requires Node 18+. Provide your own Google OAuth client (see README) via env vars:
22+
23+
```bash
24+
export GPT_CLIENT_ID="...apps.googleusercontent.com"
25+
export GPT_CLIENT_SECRET="..."
26+
27+
# Smoke-test the protocol over stdio (no sign-in needed for list/initialize)
28+
printf '%s\n' \
29+
'{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{}}}' \
30+
'{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \
31+
| GPT_TOKEN_DIR=$(mktemp -d) node server/index.js
32+
```
33+
34+
## Building the bundle
35+
36+
```bash
37+
npx @anthropic-ai/mcpb validate manifest.json
38+
npx @anthropic-ai/mcpb pack . gmail-postmaster-tools.mcpb
39+
```
40+
41+
## Releasing
42+
43+
Bump `version` in `manifest.json` and `server/package.json`, commit, then tag:
44+
45+
```bash
46+
git tag v1.0.1
47+
git push origin v1.0.1
48+
```
49+
50+
CI validates, packs, attaches the `.mcpb` to the release, and publishes to the
51+
MCP Registry (hash computed in CI; OIDC auth).
52+
53+
## Guidelines
54+
55+
- Never commit tokens, secrets, or anything from `~/.gmail-postmaster-mcp/`.
56+
- Keep tool names/descriptions clear — they're what the model reads.
57+
- Open an issue before large changes.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 OptiPub
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Gmail Postmaster Tools MCP
2+
3+
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
4+
[![Built with MCPB](https://img.shields.io/badge/built%20with-MCPB-7C3AED.svg)](https://github.com/anthropics/mcpb)
5+
[![Node](https://img.shields.io/badge/node-%3E%3D18-339933.svg)](https://nodejs.org)
6+
[![Dependencies](https://img.shields.io/badge/runtime%20deps-0-success.svg)](#why-zero-dependencies)
7+
8+
An [MCP](https://modelcontextprotocol.io) server for the **Gmail Postmaster
9+
Tools API (v2)** — query your domains, sender compliance status, and Gmail
10+
traffic metrics from Claude, Cursor, or any MCP client.
11+
12+
This is a **bring-your-own-credentials** tool for hands-on senders: you supply
13+
your own Google OAuth client, and the server runs the sign-in locally. Nothing
14+
is hosted and no data leaves your machine.
15+
16+
> Want this without setting up a Google Cloud project? That's what
17+
> **[Postmaster+](https://postmasterplus.com)** is for — hosted, multi-provider
18+
> (Gmail + Outlook + more), with verification, history, and alerting.
19+
20+
Built & maintained by the **[Postmaster+](https://postmasterplus.com)** team at **[OptiPub](https://optipub.com)**.
21+
22+
## What you get
23+
24+
- `list_domains` / `get_domain` — your registered domains and their verification state
25+
- `get_compliance_status` — SPF, DKIM, DMARC, alignment, message formatting, DNS records, TLS encryption, user-reported spam rate, and one-click / honored unsubscribe verdicts
26+
- `query_domain_stats` — spam rate, auth success (SPF/DKIM/DMARC), TLS encryption rate, delivery errors, and feedback-loop metrics over any date range
27+
- `gpt_authenticate` / `gpt_auth_status` / `gpt_sign_out`
28+
29+
> Note: Postmaster Tools **v2** covers traffic metrics + compliance. Domain and
30+
> IP *reputation* are not part of v2.
31+
32+
## Prerequisites: create a Google OAuth client (one-time, ~5 min)
33+
34+
You need a Google Cloud OAuth client because Google doesn't offer a shared
35+
public one for this API.
36+
37+
1. Go to the [Google Cloud Console](https://console.cloud.google.com/) and create (or pick) a project.
38+
2. **APIs & Services → Library** → search **"Gmail Postmaster Tools API"****Enable**.
39+
3. **APIs & Services → OAuth consent screen** (redirects to **Google Auth Platform**). If the project has never been configured, click **Get started** and set an **App name** + support email, **Audience = External**, and a contact email. If it's already configured, you'll just see the tabs — skip to the next step.
40+
4. Open the **Audience** tab. If **User type = External**, add your Google address under **Test users → + Add users** and **Save** (leave status as **Testing** — works without app verification, up to 100 users). If **User type = Internal** (a Workspace org project), no test users are needed — org users can sign in directly.
41+
5. Open the **Clients** tab (or **APIs & Services → Credentials**) → **Create client** → application type **Desktop app****Create**.
42+
6. Copy the **Client ID** and **Client secret**.
43+
44+
You'll paste those two values into this extension's configuration at install
45+
time. (Make sure the Google account you sign in with is one that has access in
46+
[Gmail Postmaster Tools](https://postmaster.google.com/).)
47+
48+
## Install in Claude / Cowork (the `.mcpb`)
49+
50+
The `.mcpb` is a packaging convenience for Claude Desktop / Cowork only.
51+
52+
1. Download `gmail-postmaster-tools.mcpb` from the [latest release](../../releases/latest).
53+
2. **Settings → Capabilities → install extension**, pick the file.
54+
3. When prompted, paste your **Google OAuth Client ID** and **Client Secret**.
55+
4. Run `gpt_authenticate` once — your browser opens for the Google sign-in.
56+
57+
## Use with other MCP clients (Cursor, VS Code, Windsurf, …)
58+
59+
Underneath, this is a standard **stdio MCP server** — any client that runs local
60+
MCP servers can use it directly, no `.mcpb` required. Clone or download the repo,
61+
then point the client at `server/index.js` and pass your Google credentials as
62+
env vars.
63+
64+
**Cursor** — edit `~/.cursor/mcp.json` (global) or `.cursor/mcp.json` (per project):
65+
66+
```json
67+
{
68+
"mcpServers": {
69+
"gmail-postmaster-tools": {
70+
"command": "node",
71+
"args": ["/absolute/path/to/gmail-postmaster-tools-mcp/server/index.js"],
72+
"env": {
73+
"GPT_CLIENT_ID": "xxxxx.apps.googleusercontent.com",
74+
"GPT_CLIENT_SECRET": "xxxxx"
75+
}
76+
}
77+
}
78+
}
79+
```
80+
81+
**VS Code** (`.vscode/mcp.json`), **Windsurf**, **Claude Desktop** (manual config),
82+
and most other clients use the same `command` + `args` + `env` shape — only the
83+
config file location differs. Other env overrides are listed under
84+
[Configuration](#configuration-env-overrides).
85+
86+
The first tool call (or `gpt_authenticate`) opens your browser for the Google
87+
sign-in; the `127.0.0.1` loopback works on any local desktop client.
88+
89+
> **Remote-only clients (e.g. Perplexity, ChatGPT connectors):** these accept
90+
> only a remote HTTPS MCP server URL, not a local command, so this stdio build
91+
> can't be added directly. That would require hosting it — which is what
92+
> [Postmaster+](https://postmasterplus.com) provides.
93+
94+
## Usage examples
95+
96+
- "Sign me in to Gmail Postmaster Tools" → `gpt_authenticate`
97+
- "List my Postmaster domains" → `list_domains`
98+
- "Is example.com compliant with Gmail's sender rules?" → `get_compliance_status { domain: "example.com" }`
99+
- "Spam rate for example.com over the last 30 days" → `query_domain_stats { domain: "example.com", start_date: "...", end_date: "...", metrics: ["SPAM_RATE"] }`
100+
- "DKIM auth success for example.com" → `query_domain_stats { domain: "example.com", metrics: [{ "standardMetric": "AUTH_SUCCESS_RATE", "filter": "auth_type=\"dkim\"" }] }`
101+
102+
Some metrics require a filter: `AUTH_SUCCESS_RATE` (`auth_type=spf|dkim|dmarc`),
103+
`TLS_ENCRYPTION_RATE` (`traffic_direction=inbound|outbound`),
104+
`DELIVERY_ERROR_RATE` (optional `error_type=...`). `SPAM_RATE` needs none.
105+
106+
## How authentication works
107+
108+
OAuth 2.0 authorization-code + PKCE, over a `http://127.0.0.1:<dynamic-port>`
109+
loopback redirect (Google's recommended flow for desktop apps). On sign-in the
110+
server starts a short-lived listener on `127.0.0.1`, opens your browser, receives
111+
the code, and exchanges it (with your client secret + PKCE verifier) for tokens.
112+
113+
Google requires a client secret even for desktop apps, which is why both values
114+
are needed. Tokens are stored only on your machine at
115+
`~/.gmail-postmaster-mcp/tokens.json` (`0600`) and are git-ignored.
116+
117+
**Scopes:** by default the server requests
118+
`postmaster.traffic.readonly` (metrics + compliance) and `postmaster.domain`
119+
(list/get domains). Override with the `GPT_SCOPE` env var if you want to narrow
120+
it (e.g. traffic-only, dropping `list_domains`/`get_domain`).
121+
122+
## Configuration (env overrides)
123+
124+
| Variable | Purpose | Default |
125+
| --- | --- | --- |
126+
| `GPT_CLIENT_ID` | Google OAuth client ID (required) ||
127+
| `GPT_CLIENT_SECRET` | Google OAuth client secret (required) ||
128+
| `GPT_SCOPE` | Space-separated OAuth scopes | traffic.readonly + domain |
129+
| `GPT_API_BASE` | API base URL | `https://gmailpostmastertools.googleapis.com/v2` |
130+
| `GPT_TOKEN_DIR` | Token cache directory | `~/.gmail-postmaster-mcp` |
131+
| `GPT_LOGIN_TIMEOUT_MS` | Sign-in wait | `180000` |
132+
| `GPT_REQUEST_TIMEOUT_MS` | Per-request timeout | `60000` |
133+
134+
## Build
135+
136+
```bash
137+
npx @anthropic-ai/mcpb validate manifest.json
138+
npx @anthropic-ai/mcpb pack . gmail-postmaster-tools.mcpb
139+
```
140+
141+
Pushing a `vX.Y.Z` tag triggers CI to pack, attach the `.mcpb` to a GitHub
142+
Release, and publish to the MCP Registry.
143+
144+
## Why zero dependencies
145+
146+
Only Node.js built-ins (`http`, `https`, `crypto`, `readline`) — tiny bundle, no
147+
supply-chain risk, nothing to `npm install`.
148+
149+
## Contributing
150+
151+
See [CONTRIBUTING.md](CONTRIBUTING.md).
152+
153+
## License
154+
155+
[MIT](LICENSE) © OptiPub
156+
157+
---
158+
159+
*Not affiliated with or endorsed by Google. "Gmail", "Google", and "Postmaster
160+
Tools" are trademarks of Google LLC.*

0 commit comments

Comments
 (0)