API & MCP

Read Margint data from your agents, your scripts, your IDE.

The same margin data you see in the dashboard is exposed two other ways: a stable REST API for scripts and backends, and an MCP server for agents and AI-aware IDEs.

Why this exists

Once margin is wired into your team's decision flow, you want it inside the tools that make decisions — not only in a browser tab. That's the API. For LLM agents that write code or operate systems on your behalf, that's MCP.

Public API

All endpoints live under /api/v1/ and authenticate with a bearer token:

curl -H "Authorization: Bearer $MARGINT_API_KEY" \
  https://app.margint.dev/api/v1/costs/overview?range=7d

Your key is the same one the SDK uses — create it in Settings → API Keys.

Endpoints

MethodPathPurpose
GET/api/v1/customersList customers with cost, MRR, margin
GET/api/v1/customers/{externalId}Single-customer detail + per-feature breakdown
GET/api/v1/costs/overviewWorkspace totals and unprofitable-customer count
GET/api/v1/budgets/check?customer=...Is this customer still within budget?

Rate limit: 120 requests / minute per key. Responses carry X-RateLimit-* and X-Request-Id headers so you can correlate retries with logs.

Interactive reference with every field documented: app.margint.dev/docs/api. Raw spec: /api/v1/openapi.json.

Versioning

/v1/ is additive-only. We add new fields and endpoints — we don't rename or remove. Breaking changes ship as /v2/ while /v1/ keeps running.

MCP server

Install Claude Desktop, Cursor, or any MCP-aware client. Then drop this into its config:

{
    "mcpServers": {
        "margint": {
            "command": "npx",
            "args": ["-y", "@margint-ai/mcp"],
            "env": { "MARGINT_API_KEY": "m_live_your_key_here" }
        }
    }
}

Claude Desktop config lives at ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows). Cursor's is at ~/.cursor/mcp.json.

Restart the client and ask it real questions:

Which customers lost me money this week?

Show me cust_acme's margin over 90 days and break it down by feature.

Is cust_acme still within their budget for the chat feature?

Tools exposed

ToolWhat it does
margint_list_customersTop 100 customers by margin, worst first.
margint_get_customerDetail + per-feature breakdown for one customer.
margint_cost_overviewWorkspace totals over a rolling window.
margint_check_budgetSelf-gate for agents before making an LLM call.

Every response includes a one-line summary so the calling model can answer most questions without parsing the full payload.