Cronometer MCP on Cloudflare Workers
by reedpen
README.md
# Cronometer MCP on Cloudflare Workers
A TypeScript port of **[cronometer-api-mcp](https://github.com/rwestergren/cronometer-api-mcp)** by **[Randy Westergren](https://github.com/rwestergren)**. It runs as a Cloudflare Worker and connects to Claude as a custom connector. See [Credits](#credits).
> [!WARNING]
> This is an unofficial project. It isn't affiliated with or endorsed by Cronometer or by the original project's author. It uses an unofficial API that can change without notice. Check Cronometer's terms and use it at your own risk.
Each deployment is for **one Cronometer account**. Deploy your own copy, and don't share your `ACCESS_PASSWORD`.
It includes all 32 tools from the original: food log, nutrition totals and scores, food search, custom foods, recipes, recipe import, macro targets, fasting, biometrics, exercise and notes. It uses the same unofficial mobile API the Cronometer Android app uses.
## How it works
- `/mcp` is a stateless Streamable HTTP MCP endpoint, served by `createMcpHandler` from the `agents` package. No Durable Objects are needed.
- OAuth 2.1 is handled by `@cloudflare/workers-oauth-provider`. When Claude connects, you're shown a small login page. Enter your `ACCESS_PASSWORD` there and Claude gets a token.
- Your Cronometer login token is cached in KV, so new connections and new isolates reuse it. Cronometer rate-limits logins.
## Deploy
You need a Cloudflare account, a Cronometer account and a current version of Node.js.
```sh
git clone https://github.com/reedpen/cronometer-mcp-worker.git
cd cronometer-mcp-worker
npm ci
npx wrangler login
# Creates the Worker and its KV namespace, and writes the namespace ID to wrangler.jsonc
npx wrangler deploy
# Set the secrets (each command prompts for the value)
npx wrangler secret put CRONOMETER_USERNAME # your Cronometer email
npx wrangler secret put CRONOMETER_PASSWORD
npx wrangler secret put ACCESS_PASSWORD # long and random, e.g. from: openssl rand -base64 32
# Optional
npx wrangler secret put CRONOMETER_TOTP_SECRET # only if your account has 2FA: the base32 key shown at setup
npx wrangler secret put CRONOMETER_ACCOUNT_TZ # e.g. America/Denver, if the account's zone comes back wrong
```
Nobody can connect until `ACCESS_PASSWORD` is set. New secrets take effect without another deploy.
### Deploy from the browser
[](https://deploy.workers.cloudflare.com/?url=https://github.com/reedpen/cronometer-mcp-worker)
The button copies this repo to your GitHub account, creates the Worker and its KV namespace, and asks for the three required secrets. Two things to know:
- **`ACCESS_PASSWORD` is the password you'll type when you connect Claude.** Make it long and random, and save it in your password manager.
- **If your account has 2FA,** add `CRONOMETER_TOTP_SECRET` to the Worker's secrets afterwards (**Settings → Variables and Secrets**). The button doesn't ask for it.
## Connect it to Claude
1. In Claude, go to **Settings → Connectors → Add custom connector**.
2. For the URL, enter `https://cronometer-mcp.<your-subdomain>.workers.dev/mcp`.
3. Claude opens the connect page. Enter your `ACCESS_PASSWORD` and choose **Allow access**.
## Notes
- **Custom domain:** if you serve the Worker from your own domain instead of `workers.dev`, set a `PUBLIC_URL` var (for example `https://cronometer.example.com`). Also pass `allowedHostnames` / `allowedOriginHostnames` to `createMcpHandler` in `src/index.ts`.
- **Anyone with `ACCESS_PASSWORD` can read and edit your diary.** Make it long and random, because the login page doesn't limit repeated guesses. To lock everyone out, change the password and clear the `OAUTH_KV` namespace. It only holds OAuth grants and the cached Cronometer session, so you just reconnect afterwards.
- **Unofficial API:** Cronometer doesn't publish this API, so a Cronometer app update can break things. Changes upstream can be ported from the Python repo, since the file layout mirrors it: `client.ts` ↔ `client.py` and `tools.ts` ↔ `server.py`.
## Develop
Run `npm ci`, copy `.dev.vars.example` to `.dev.vars` and fill in the values (Git ignores `.dev.vars`). Then run:
```sh
npm run dev # wrangler dev on :8787
npm test # unit tests (mocked Cronometer)
npm run typecheck
```
## Credits
This project is based on **[cronometer-api-mcp](https://github.com/rwestergren/cronometer-api-mcp)** by **[Randy Westergren](https://github.com/rwestergren)**. The original Python project provided the Cronometer API client, the design of all 32 tools and the behavior this port follows. Thank you!
This version ports that work to TypeScript and adds the Cloudflare Workers hosting, the OAuth login page and session caching in KV.
## License
[MIT](LICENSE). The license includes the copyright notices for the original project and this port. The original project's license is also included unchanged in [LICENSE.upstream](LICENSE.upstream).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues