freshbooks-mcp
MCP server for FreshBooks — invoices, clients, estimates and
payments, exposed to Claude as typed tools.
This project was developed and is maintained by AI (Claude Code). Use at your own discretion.
Install
npm install -g @chrischall/freshbooks-mcp
Setup
FreshBooks is OAuth2 only — there is no API key and no personal access token, so a
one-time browser authorization is required.
- Register an app at https://my.freshbooks.com/#/developer. The redirect URI must be
HTTPS with no query string;
https://localhost works and never needs to resolve.
- Note the Client ID and Client Secret.
- Complete the one-time authorization:
- From the server itself (no script): set
FRESHBOOKS_CLIENT_ID and
FRESHBOOKS_CLIENT_SECRET, start it, then call freshbooks_auth_url, open
the URL it returns, approve, and pass the whole URL you land on to
freshbooks_auth_exchange. Its state must match a consent URL the server
issued (valid 15 minutes, single-use), so a bare code, or a redirect URL from
anyone else's authorization, is refused before its code is spent. Local
sessions save the tokens directly to FRESHBOOKS_TOKEN_STORE and return only
a success message. Restart the local MCP server after that message. No token
needs to be copied into chat or configuration. Keep the same app credentials
and store path after restart.
- Hosted connections: mcp-host's
authFlow still captures the refresh
token from the exchange response and supplies it through its secret store.
MCP_DATA_DIR identifies this hosted environment. Do not set it for a local
coding-agent connection: hosted mode intentionally returns the token.
Issued states are kept as digests under MCP_DATA_DIR, so a child that is
respawned while the person approves can still complete the login.
The registration's flow must show the person the authorize_url that
freshbooks_auth_url returns. That URL carries the one-time state,
and the exchange refuses any redirect without it. A static consent link
typed into a step description has no state, so every new login or
repair through it fails. Carry authorize_url from the
freshbooks_auth_url step and show it with a step link
(link: {from: 'authorize_url', hosts: ['auth.freshbooks.com']}, mcp-host
2.30.0 or later) on the step that prompts. That prompt must collect the
whole redirect URL, not just its code. Make this change before a
release with state checking reaches the hosted pin. Existing connections
keep refreshing; only new logins and repairs depend on it.
- Legacy/manual setup: the scripts in
skills/freshbooks-curl print tokens.
Run them only in a private terminal, never in an agent's captured terminal.
- Configure:
FRESHBOOKS_CLIENT_ID=...
FRESHBOOKS_CLIENT_SECRET=...
FRESHBOOKS_REFRESH_TOKEN=... # optional locally; if set during reauth, keep it set
FRESHBOOKS_REDIRECT_URI=https://localhost # optional; must match what you registered
FRESHBOOKS_TOKEN_STORE=~/.freshbooks-mcp/session.json # optional
FRESHBOOKS_BUSINESS_ID=... # optional; required for writes if you belong to several businesses
FRESHBOOKS_ACCOUNT_ID=... # optional; with FRESHBOOKS_BUSINESS_ID, confirms its accountId when FreshBooks omits it
FRESHBOOKS_REQUEST_TIMEOUT_MS=30000 # optional; per-request deadline for API calls
In Claude Desktop, both are optional fields in the extension's settings. If FreshBooks
returns no account_id for the chosen business, invoice/expense writes are refused
(projects and time entries still work) until you set both IDs yourself.
⚠️ Refresh tokens rotate
FreshBooks issues a new refresh token on every refresh and immediately invalidates the
old one. This server persists each rotation to FRESHBOOKS_TOKEN_STORE (mode 0600)
before the refresh is considered complete, and prefers the stored token over the
environment value — the stored one has rotated past it.
The login flow also writes a small file of pending consent state digests
(mode 0600, entries expire after 15 minutes). Locally it sits beside the token
store, at <FRESHBOOKS_TOKEN_STORE>.oauth-state.json (by default
~/.freshbooks-mcp/session.json.oauth-state.json). Hosted, it is
$MCP_DATA_DIR/freshbooks-oauth-state.json. It is created on the first
freshbooks_auth_url call, even if the login is never finished, and holds no
tokens.
Two consequences worth knowing:
- Do not point two tools at the same store. The MCP server and the
freshbooks-curl
skill keep separate state files on purpose; sharing one makes them spend each other's
tokens and locks both out.
- If the store is lost, re-run the bootstrap. A spent refresh token cannot be
recovered.