Skip to main content
Glama
Bloomerang MCP Server

Bloomerang MCP Server

README.md
# Build a Bloomerang connector for Claude

*A tutorial by [One Giant Leap](https://github.com/Giant-Leap-ai). MIT licensed.*

This tutorial walks through building and deploying a **remote MCP server** that connects
[Bloomerang](https://bloomerang.com) (the nonprofit donor CRM) to Claude as a **custom connector**.
When you're done, your staff can ask Claude things like:

> "List gifts from the last 30 days, split recurring vs one-time, and tell me which donors still need a thank-you card."

> "Here's a photo of tonight's sign-in sheet. Log attendance for Volunteer Orientation."

Claude answers from live Bloomerang data, in Claude.ai, Claude Desktop, mobile and Claude Code.

The server runs as a Cloudflare Worker (the free plan is enough). Staff sign in with their Google
Workspace account, each person gets a role (admin, attendance or read), and the Bloomerang API key
stays in Cloudflare. Claude never sees it.

## Contents

1. [How it works](#how-it-works)
2. [What you need](#what-you-need)
3. [Step 1: Get the code](#step-1-get-the-code)
4. [Step 2: Create a Bloomerang API key](#step-2-create-a-bloomerang-api-key)
5. [Step 3: Create the Cloudflare Worker](#step-3-create-the-cloudflare-worker)
6. [Step 4: Create a Google OAuth client](#step-4-create-a-google-oauth-client)
7. [Step 5: Configure `wrangler.jsonc`](#step-5-configure-wranglerjsonc)
8. [Step 6: Add storage and secrets](#step-6-add-storage-and-secrets)
9. [Step 7: Deploy and smoke-test](#step-7-deploy-and-smoke-test)
10. [Step 8: Add the connector in Claude](#step-8-add-the-connector-in-claude)
11. [Step 9: Try it](#step-9-try-it)
12. [The tools](#the-tools)
13. [Adding your own tool](#adding-your-own-tool)
14. [Security model](#security-model)
15. [Troubleshooting](#troubleshooting)
16. [Operations](#operations)

---

## How it works

```
 Claude (web, desktop, mobile, Code)
        │  MCP over HTTPS + OAuth 2.1 token
        ▼
 Cloudflare Worker  ─────────────►  Google sign-in (who is this person?)
   • OAuth provider (/authorize, /token, /register)
   • MCP endpoint (/mcp)
   • Role check + audit log on every tool call
        │  X-API-KEY (Worker secret)
        ▼
 Bloomerang REST API v2
```

- **Claude ↔ Worker:** Claude's custom connectors speak MCP and authenticate with OAuth 2.1.
  [`@cloudflare/workers-oauth-provider`](https://github.com/cloudflare/workers-oauth-provider) turns the
  Worker into an OAuth server and supports Dynamic Client Registration (DCR), so Claude registers itself
  and you don't copy client IDs around.
- **Who is signing in:** the Worker hands sign-in to Google, then checks that the account is verified and
  belongs to your Workspace domain. Only the email and name are kept. The Google token is discarded.
- **What they can do:** `ACCESS_POLICY` maps each email to a role. Every tool checks the role before it
  touches Bloomerang. Someone who isn't listed can sign in but gets no data.
- **Bloomerang:** one API key, stored as a Worker secret. Bloomerang keys can't be scoped, so the
  Worker is the only thing that limits what can be read or written.

The code is based on Cloudflare's
[remote MCP server with Google OAuth](https://github.com/cloudflare/ai/tree/main/demos/remote-mcp-google-oauth)
demo, with the stateless `createMcpHandler` from the `agents` package.

### Project layout

| File | What it does |
|---|---|
| `src/index.ts` | The MCP server: tool definitions, role checks, audit logging, OAuth wiring |
| `src/bloomerang.ts` | Small Bloomerang v2 client (retries on 429/5xx) and helpers that trim records to what Claude needs |
| `src/google-handler.ts` | `/authorize` and `/callback`: consent screen, Google sign-in, domain enforcement |
| `src/workers-oauth-utils.ts` | CSRF, state and cookie helpers from the Cloudflare demo |
| `src/utils.ts` | Upstream OAuth helpers and the `Props` stored in each token |
| `wrangler.jsonc` | Worker config: name, vars, KV binding |
| `worker-configuration.d.ts` | Types for the vars, bindings and secrets |

## What you need

- **Bloomerang** with an admin user who can create API keys.
- **Google Workspace** for your staff. Any Google sign-in works with small changes, but domain
  enforcement assumes Workspace.
- **Cloudflare account.** The free plan works.
- **Claude Team or Enterprise** if you want to add the connector once for the whole organization
  (an owner does this). On individual plans each person adds the custom connector themselves.
- **Node.js 20+** and a terminal.

> **There is no Bloomerang sandbox.** Everything you test touches live data. Run the read tools first,
> and test writes on a test record you delete afterwards.

## Step 1: Get the code

```bash
git clone https://github.com/Giant-Leap-ai/bloomerang-mcp-connector.git
cd bloomerang-mcp-connector
npm install
npm run type-check
```

## Step 2: Create a Bloomerang API key

1. In Bloomerang, open **Settings → Integrations → API Keys** (as a Bloomerang administrator).
2. Create a **v2 private API key**. Name it after the connector, e.g. "Claude connector".
3. Keep the page open. You'll paste the key straight into Cloudflare in Step 6.
   Don't put it in a file, a chat or an email.

The key can read and write everything in your database. That's why every guard in this project
lives in the Worker.

## Step 3: Create the Cloudflare Worker

```bash
npx wrangler login     # approve in the browser
npx wrangler whoami    # note your account ID
```

Pick your Worker name now. It's `bloomerang-mcp` in `wrangler.jsonc`. Your URL will be:

```
https://bloomerang-mcp.<your-subdomain>.workers.dev
```

Find `<your-subdomain>` in the Cloudflare dashboard under **Workers & Pages** (shown as your
`workers.dev` subdomain). Set or rename it **now**: the URL ends up in Google, in Claude and in every
token, and changing it later means everyone reconnects.

## Step 4: Create a Google OAuth client

In [Google Cloud Console](https://console.cloud.google.com), signed in as a Workspace admin:

1. Create a project, e.g. "Claude Bloomerang Connector".
2. **APIs & Services → OAuth consent screen**: choose **Internal** so only your Workspace can use it.
   Scopes: `openid`, `email`, `profile`.
3. **Credentials → Create credentials → OAuth client ID → Web application.**
4. Authorized redirect URI:
   ```
   https://bloomerang-mcp.<your-subdomain>.workers.dev/callback
   ```
   For local development, also add `http://localhost:8788/callback`.
5. Keep the client ID and secret open for Step 6.

## Step 5: Configure `wrangler.jsonc`

Open `wrangler.jsonc` and change every line marked `TODO`:

| Setting | Set it to |
|---|---|
| `account_id` | Optional. Your Cloudflare account ID, so deploys can't land in the wrong account |
| `ORG_NAME` | Your organization's name (shown on the sign-in screen) |
| `MCP_RESOURCE` | `https://bloomerang-mcp.<your-subdomain>.workers.dev/mcp`, exactly |
| `HOSTED_DOMAIN` | Your Google Workspace domain, e.g. `yournonprofit.org` |
| `ACCESS_POLICY` | JSON mapping each staff email to `admin`, `attendance` or `read` |

Roles:

| Role | Can do |
|---|---|
| `read` | All read tools: search, records, timelines, gifts, thank-you queue |
| `attendance` | Search, attendance preview/commit, create people and organizations, fix names, link people to organizations. No gift data |
| `admin` | Everything, plus `log_interaction` and contact details (phone, address) on `get_constituent` |

Example:

```jsonc
"ACCESS_POLICY": "{\"director@yournonprofit.org\":\"admin\",\"events@yournonprofit.org\":\"attendance\",\"board@yournonprofit.org\":\"read\"}"
```

## Step 6: Add storage and secrets

The Worker uses one KV namespace for OAuth grants and short-lived write previews:

```bash
npx wrangler kv namespace create OAUTH_KV
# paste the printed id into wrangler.jsonc, replacing REPLACE_WITH_KV_ID
```

Then set four secrets. Each command prompts for the value, so it never lands in your shell history:

```bash
npx wrangler secret put GOOGLE_CLIENT_ID
npx wrangler secret put GOOGLE_CLIENT_SECRET
npx wrangler secret put BLOOMERANG_API_KEY
openssl rand -hex 32 | npx wrangler secret put COOKIE_ENCRYPTION_KEY
```

If someone else holds a value (for example, a Bloomerang admin holds the API key), they can add it themselves in
the Cloudflare dashboard: **Worker → Settings → Variables and Secrets → Add → Secret**.

`wrangler secret put` only works once the Worker exists. If it says the Worker doesn't exist yet, run
`npx wrangler deploy` once first, then add the secrets.

```bash
npx wrangler secret list   # expect all four
```

## Step 7: Deploy and smoke-test

```bash
npm run type-check
npx wrangler deploy
```

Check that the OAuth plumbing is up:

```bash
BASE=https://bloomerang-mcp.<your-subdomain>.workers.dev
curl -s -o /dev/null -w "%{http_code}\n" -X POST $BASE/mcp           # expect 401 (no token yet)
curl -s $BASE/.well-known/oauth-protected-resource | head -c 400      # resource should be $BASE/mcp
curl -s $BASE/.well-known/oauth-authorization-server | head -c 400    # authorize / token / register endpoints
```

Optional: run `npx @modelcontextprotocol/inspector`, connect to `$BASE/mcp`, sign in, and call `whoami`.

### Running locally

```bash
cp .dev.vars.example .dev.vars   # fill in real values; .dev.vars is git-ignored
npm run dev                      # http://localhost:8788/mcp
```

Change `MCP_RESOURCE` to `http://localhost:8788/mcp` while you test locally, and change it back before you deploy.

## Step 8: Add the connector in Claude

**Organization-wide (Team/Enterprise owner):**

1. **Organization settings → Connectors → Add → Custom → Web.**
2. Name: e.g. `Bloomerang`. URL: `https://bloomerang-mcp.<your-subdomain>.workers.dev/mcp`.
3. OAuth client: **Register automatically** (DCR). Leave the other auth fields empty.
4. Set tool permissions. A sensible default:
   - **Always allow:** `whoami`, `search_constituents`, `get_constituent`, `get_constituent_timeline`,
     `list_interactions`, `list_recent_gifts`, `thank_you_queue`, `list_constituents_by_field`,
     `preview_attendance`, `preview_constituent_changes`
   - **Needs approval:** `commit_attendance`, `commit_constituent_changes`, `log_interaction`

You can't edit auth settings after you add the connector. Changing them means removing and
re-adding it, and everyone reconnects.

**Each person:** **Customize → Connectors → Bloomerang → Connect**, sign in with their work Google
account, and approve.

## Step 9: Try it

1. *"Use Bloomerang whoami."* Checks the sign-in and shows your role and tools.
2. *"Using Bloomerang, list gifts from the last 30 days, split recurring vs one-time."* Spot-check one gift in Bloomerang.
3. *"Who still needs a thank-you card from the last two weeks?"*
4. Attendance dry run: *"Preview attendance for Volunteer Orientation on 2026-01-15 for: [two real names]."* Check the matches and don't commit yet.
5. One real write on a test record: approve the prompt, confirm it in Bloomerang, then delete the test interaction there.

## The tools

### Read

| Tool | What it returns |
|---|---|
| `whoami` | Signed-in email, role, and which tools that role can use |
| `search_constituents` | People, organizations and households by name, email or phone |
| `get_constituent` | One record: names, job title, employer, relationships, custom fields (contact details for admins) |
| `list_constituents_by_field` | Everyone with a given custom field value, e.g. Donor level = Gold |
| `get_constituent_timeline` | Recent transactions, interactions, notes and tasks |
| `list_interactions` | Recent interactions for one constituent |
| `list_recent_gifts` | Gifts in the last N days with donor, amount, fund, recurring vs one-time, and totals |
| `thank_you_queue` | Unacknowledged, non-refunded gifts grouped by donor |

### Write (preview → commit)

Writes happen in two steps. A `preview_*` tool writes nothing to Bloomerang: it matches names, runs
duplicate checks, and saves a plan in KV for 60 minutes under a `preview_id`. Claude shows the plan,
the user confirms, and the matching `commit_*` tool applies it. A preview can only be committed once, and only by the person who created it.

| Tool | What it does |
|---|---|
| `preview_attendance` / `commit_attendance` | Matches attendee names (e.g. from a photo of a sign-in sheet) and logs one "Attended <meeting>" interaction each. First-time attendees can be logged as "First <meeting>" |
| `preview_constituent_changes` / `commit_constituent_changes` | Creates individuals and organizations (with Bloomerang's duplicate check), fixes prefix, name, suffix, job title or employer, and links people to organizations |
| `log_interaction` | Admin only: logs a single interaction on one constituent |

Every interaction the connector writes ends with "Logged via Claude by <email>" in its note.

Deliberately **not** included: deletes, merges, editing or removing existing relationships, other field edits,
transaction writes, and a raw API passthrough. Add them only if you decide you need them.

## Adding your own tool

Tools are registered in `createServer()` in `src/index.ts`. The pattern:

1. Add a method to the `Bloomerang` class in `src/bloomerang.ts` for the endpoint you need
   (see the [Bloomerang REST API reference](https://bloomerang.com/api/rest-api)).
2. Register the tool with a clear description. Claude decides when to call a tool from that description.
3. Wrap the handler in `guarded(ctx, name, ROLES, fn)`. It adds the role check, the audit log line and error handling.

```ts
server.registerTool(
	"list_funds",
	{
		title: "List funds",
		description: "Lists active Bloomerang funds (id and name).",
		inputSchema: z.object({}),
		annotations: { readOnlyHint: true, openWorldHint: true },
	},
	guarded<{}>(ctx, "list_funds", READ_ROLES, async (_args, bl) => {
		const res = await bl.funds(); // add funds() to src/bloomerang.ts
		return ok((res.Results ?? []).map((f: any) => ({ id: f.Id, name: f.Name })));
	}),
);
```

Tips:

- Return only the fields Claude needs. The `summarize*` helpers in `src/bloomerang.ts` keep phone numbers, addresses
  and scores out unless they're asked for. Tool results are capped at roughly 150k characters.
- Mark read tools `readOnlyHint: true` and write tools `destructiveHint: true`. Claude shows these to the user.
- For any write, copy the preview → commit pattern instead of writing directly.
- `whoami` lists new tools on its own. Add them to the connector's permission settings in Claude too.

## Security model

- **Secrets** live only in Cloudflare. Nothing in the repo, nothing in Claude.
- **Sign-in** is Google OAuth limited to one Workspace domain. The `hd` parameter sent to Google is only a hint, so
  `/callback` checks the domain and `verified_email` itself.
- **Access** is per email in `ACCESS_POLICY`, checked on every tool call. Accounts that aren't listed get no data.
- **Tokens** are bound to `MCP_RESOURCE`, so they only work for this server.
- **Writes** go through preview → commit, are single-use, can only be committed by the person who created the preview,
  and recheck the record before saving (a rename is skipped if someone changed the record in Bloomerang since the preview).
- **Logs** (Workers Logs) record the user, tool and counts, never donor data.
- **Limits of the design:** one shared Bloomerang key means Bloomerang's own audit trail shows the API key, not the
  person. The Worker's logs and the "Logged via Claude by" note fill that gap. If you need per-user Bloomerang
  permissions, look at [Bloomerang's OAuth](https://bloomerang.com/api/oauth-reference-guide) (apps are registered
  with Bloomerang, tokens last 1 hour, refresh tokens 90 days).

## Troubleshooting

Field names come from Bloomerang's v2 API spec. Bloomerang setups vary, so check these on your first run:

| Symptom | Check |
|---|---|
| `list_recent_gifts` is empty or out of order | `/transactions?orderBy=Date&orderDirection=Desc` should return newest first, with `Designations[].Type` and `AcknowledgementStatus` present |
| Donor names are missing | The pipe-separated `/constituents?id=1\|2\|3` lookup. Fall back to `GET /constituent/{id}` per id |
| `commit_attendance` returns 400 | Channel / Purpose spellings (`InPerson`, `SpecialEvent`) and that `AccountId` is accepted. Zoom meetings use Channel `Other` |
| Prefix or suffix rejected | It must exactly match an entry in Bloomerang's prefix/suffix settings (`Dr.` vs `Dr`) |
| A relationship comes out reversed | The commit result's `saved_as` echoes Bloomerang's roles. Swap `RelationshipRoleId1/2` in `commit_constituent_changes` |
| Contact details warning after a rename | Bloomerang's PUT may not keep fields you leave out. The tool rereads the record and warns you. Check it in Bloomerang |
| Sign-in rejected | Workers Logs show `signin_rejected` with the domain Google returned. Check `HOSTED_DOMAIN` |
| "doesn't have access" | The email isn't in `ACCESS_POLICY`, or the role doesn't include that tool. Run `whoami` |

Logs: Cloudflare dashboard → your Worker → **Logs**, or `npx wrangler tail`.

## Operations

- **Change who has access:** edit `ACCESS_POLICY`, then `npx wrangler deploy`.
- **Rotate the Bloomerang key:** create a new key in Bloomerang, `npx wrangler secret put BLOOMERANG_API_KEY`, then deactivate the old key.
- **Kill switch:** delete the `BLOOMERANG_API_KEY` secret, or deactivate the key in Bloomerang.
- **Changing the URL** (Worker name or subdomain): update `MCP_RESOURCE` and the Google redirect URI, then re-add the
  connector in Claude. Everyone reconnects.
- **Redeploy without a terminal:** connect the repo to [Workers Builds](https://developers.cloudflare.com/workers/ci-cd/builds/) so pushes to `main` deploy automatically.

## References

- [Building connectors for Claude](https://claude.com/docs/connectors/building)
- [Cloudflare: build a remote MCP server](https://developers.cloudflare.com/agents/guides/remote-mcp-server/)
- [cloudflare/ai: remote-mcp-google-oauth demo](https://github.com/cloudflare/ai/tree/main/demos/remote-mcp-google-oauth)
- [Bloomerang REST API](https://bloomerang.com/api/rest-api)
- [Model Context Protocol](https://modelcontextprotocol.io)

## License

[MIT](LICENSE) © One Giant Leap. Use it, fork it, adapt it for your organization.
Bloomerang is a trademark of its owner. This project is independent and not affiliated with or endorsed by Bloomerang.