MarginFront MCP Setup Guide
What is MCP?
MCP (Model Context Protocol) lets your AI coding assistant talk to MarginFront directly. Instead of writing curl commands or switching to the dashboard, you can say “show me my customers” and your AI tool fetches them. Think of it like giving your AI assistant a phone line to MarginFront — it can look things up, record usage events, and answer billing questions without you leaving your editor.Before You Start
You need three things:- A MarginFront API key that starts with
mf_sk_. You can find it (or create one) in the MarginFront dashboard under Developer Zone > API Keys. - Node.js 18 or newer installed on your machine. Check by running
node --versionin your terminal — the number should be 18 or higher. - One of these AI tools installed: Claude Code, Claude Desktop, Cursor, VS Code, Windsurf, or Codex.
Setup by Tool
Pick the tool you use and follow only that section. Each one takes about 60 seconds.Claude Code
- Open your project folder in your terminal.
- Create a file called
.mcp.jsonin the project root (the top-level folder). - Paste this into the file:
- Replace
mf_sk_your_key_herewith your real API key. - Save the file.
- Restart Claude Code so it picks up the new config.
Claude Desktop
- Open Claude Desktop.
- Go to Settings > Developer > Edit Config to open
claude_desktop_config.json. - Paste this into the file (or merge it with any existing config):
- Replace
mf_sk_your_key_herewith your real API key. - Save the file.
- Restart Claude Desktop.
Cursor
- Open your project in Cursor.
- Create a folder called
.cursorin your project root (if it doesn’t exist already). - Inside
.cursor, create a file calledmcp.json. - Paste this into the file:
- Replace
mf_sk_your_key_herewith your real API key. - Save the file.
- Restart Cursor.
VS Code / Windsurf / Codex
- Open your project in VS Code (or Windsurf or Codex).
- Create a folder called
.vscodein your project root (if it doesn’t exist already). - Inside
.vscode, create a file calledmcp.json. - Paste this into the file:
Important: VS Code uses"servers"instead of"mcpServers". This is the only difference from the other tools.
- Replace
mf_sk_your_key_herewith your real API key. - Save the file.
- Restart VS Code.
Optional: Custom API URL
By default, the MCP server talks tohttps://api.marginfront.com/v1. If you’re running MarginFront locally or using a staging server, add MF_API_BASE_URL to the env block:
Verify the Connection
Once you’ve set up the config and restarted your tool:- Open a new chat in your AI tool.
- Type: “Verify my MarginFront connection”
- Your AI tool should respond with your organization name and a “verified” status.
Example Prompts to Try
Once connected, try any of these to see MCP in action:- “Show me my MarginFront customers” — lists all your customers with names and IDs.
- “What events were logged today?” — shows usage events from today.
- “How much did customer acme-001 cost this month?” — pulls analytics for a specific customer.
- “Record a usage event for customer acme-001 on agent cs-bot, signal messages, model gpt-4o from openai, 500 input tokens, 120 output tokens” — records a single LLM usage event.
- “Are there any events with unknown models?” — checks if any usage events have unrecognized models (meaning cost couldn’t be calculated).
- “Create a customer called Beta Corp with external ID beta-001” — creates a new customer.
What MCP Can and Can’t Do
Things you can do through MCP
- Record usage events (single or batch, up to 100 at a time)
- Look up customers, invoices, subscriptions, and usage events
- Pull usage analytics for any date range
- Create new customers
- Find events where the model wasn’t recognized (cost = unknown)
- Map unknown models to known ones so costs get calculated
Things you should do in the dashboard instead
- Create agents (the AI products you’re billing for)
- Create signals (the metrics you’re tracking, like “messages” or “pages”)
- Create pricing plans
- Create subscriptions (assigning a customer to a plan)
- Generate invoices
Troubleshooting
”Tool not found” or MCP tools don’t appear
What happened: Your AI tool can’t find the@marginfront/mcp package.
Why: The package isn’t available through npx, or there’s a network issue.
Fix:
- Open a terminal and run:
npx -y @marginfront/mcp --help - If that fails, check your internet connection and make sure npm can reach the registry.
- If you’re behind a corporate proxy, you may need to configure npm’s proxy settings.
”Authentication failed”
What happened: The API key was rejected. Why: The key is missing, expired, or not a secret key. Fix:- Open your MCP config file and check the
MF_API_SECRET_KEYvalue. - Make sure it starts with
mf_sk_(notmf_pk_— that’s a publishable key, which doesn’t have permission for most operations). - Make sure there are no extra spaces or quotes around the key.
- If you’re not sure the key is valid, go to Developer Zone > API Keys in the dashboard and create a new one.
”Connection refused” or “Could not reach the MarginFront API”
What happened: The MCP server can’t connect to the MarginFront API. Why: Either the API is down, or you’re pointing to the wrong URL. Fix:- If you set
MF_API_BASE_URL, make sure that server is actually running at that address. - If you’re running locally, make sure the API server is started (
cd apps/api-nest && npm run dev). - If you didn’t set
MF_API_BASE_URL, the default ishttps://api.marginfront.com/v1— check that you can reach it from your network.

