Docs menu

AI assistants (MCP)

APIs, agents and pipelines

Connect LedgerOne to your own agents and automations: the Claude, OpenAI and Grok APIs' built-in MCP support, and n8n workflows.

Model APIs can connect to a remote MCP server for you: you pass LedgerOne's URL and a personal access token, and the provider calls the tools. These examples read LEDGERONE_TOKEN from the environment.

Claude API

The Messages API's MCP connector (beta). mcp_servers names the server and the mcp_toolset entry chooses which of its tools Claude may use.

Python
import os
import anthropic

client = anthropic.Anthropic()

response = client.beta.messages.create(
    model="claude-opus-5-5",
    max_tokens=16000,
    betas=["mcp-client-2025-11-20", "server-side-fallback-2026-07-01"],
    fallbacks="default",  # retry on another model if a request is declined
    mcp_servers=[{
        "type": "url",
        "url": "https://finance.psycodelabs.lk/api/mcp",
        "name": "ledgerone",
        "authorization_token": os.environ["LEDGERONE_TOKEN"],
    }],
    tools=[{
        "type": "mcp_toolset",
        "mcp_server_name": "ledgerone",
        # Allow-list: only these read-only tools are available.
        "default_config": {"enabled": False},
        "configs": {
            "outstanding_invoices": {"enabled": True},
            "upcoming_due": {"enabled": True},
            "cash_flow": {"enabled": True},
        },
    }],
    messages=[{
        "role": "user",
        "content": "Write a five-line money brief for this week: who owes us, what's due, cash in and out.",
    }],
)

for block in response.content:
    if block.type == "text":
        print(block.text)
TypeScript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

const response = await client.beta.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 16000,
  betas: ["mcp-client-2025-11-20", "server-side-fallback-2026-07-01"],
  fallbacks: "default", // retry on another model if a request is declined
  mcp_servers: [
    {
      type: "url",
      url: "https://finance.psycodelabs.lk/api/mcp",
      name: "ledgerone",
      authorization_token: process.env.LEDGERONE_TOKEN,
    },
  ],
  tools: [
    {
      type: "mcp_toolset",
      mcp_server_name: "ledgerone",
      default_config: { enabled: false },
      configs: {
        outstanding_invoices: { enabled: true },
        upcoming_due: { enabled: true },
        cash_flow: { enabled: true },
      },
    },
  ],
  messages: [
    { role: "user", content: "Write a five-line money brief for this week." },
  ],
});

for (const block of response.content) {
  if (block.type === "text") console.log(block.text);
}

OpenAI API

The Responses API's remote MCP tool. By default OpenAI asks for approval before calling a tool; allowed_tools limits what's imported.

bash
curl https://api.openai.com/v1/responses \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<your model>",
    "input": "Which invoices are overdue, and by how much?",
    "tools": [{
      "type": "mcp",
      "server_label": "ledgerone",
      "server_url": "https://finance.psycodelabs.lk/api/mcp",
      "authorization": "'"$LEDGERONE_TOKEN"'",
      "allowed_tools": ["outstanding_invoices", "upcoming_due"]
    }]
  }'

Grok (xAI API)

xAI's Remote MCP Tools take the same shape in its OpenAI-compatible Responses API: a server_url, a server_label, an optional authorization and allowed_tools. Grok then calls LedgerOne's tools directly, which makes it easy to build bots on X or elsewhere on top of your books.

bash
curl https://api.x.ai/v1/responses \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<grok model>",
    "input": "Summarise this month: sales, spending and what customers still owe.",
    "tools": [{
      "type": "mcp",
      "server_label": "ledgerone",
      "server_url": "https://finance.psycodelabs.lk/api/mcp",
      "authorization": "'"$LEDGERONE_TOKEN"'",
      "allowed_tools": ["financial_summary", "outstanding_invoices"]
    }]
  }'

n8n workflows

  1. 1Add an AI Agent node with the chat model you use.
  2. 2Give it an MCP Client Tool with the endpoint https://finance.psycodelabs.lk/api/mcp (choose Streamable HTTP if your n8n version asks for a transport).
  3. 3Authentication: Bearer, with a credential holding your LedgerOne token.
  4. 4Under tools to include, choose Selected and pick only what the workflow needs (for a receipt bot: list_expense_categories, create_expense, add_expense_receipt).
  5. 5Trigger it however you like: a Telegram or WhatsApp message, a schedule, a form or a webhook.

Good practice for pipelines

  • Create a separate token per pipeline, with an expiry, so you can revoke one without touching the others.
  • Allow-list tools; leave destructive ones (marked DESTRUCTIVE in the tool reference) out of anything unattended.
  • Let pipelines draft customer emails, and send them yourself from LedgerOne after reading them.
  • Use a staff account with limited grants for automations that should only touch expenses, for example.