feat(mcp): tool titles + Connect-with-Claude docs for Connectors Directory readiness (P0-4) (#682)
* feat(mcp): tool titles + Connect-with-Claude docs for Connectors Directory readiness Add a top-level Tool.title (MCP spec 2025-06-18) to all 92 MCP tools and flow it through the tools/list serializer for the Claude Connectors Directory. Trim the ~10 longest tool descriptions toward 180-200 chars (semantics + agent hints preserved) to partly offset the added bytes, and raise the payload-size bench ceiling 32K → 36K with headroom reserved for upcoming Skatteverket tools. Ship a "Connect with Claude" docs page (OAuth 2.1 connector + npx gnubok-mcp stdio bridge, sample sandbox prompts, 10-minute reviewer test, support pointer), wire it into the docs nav, and add a README to the packages/gnubok-mcp npm bridge. Bump one categorized sandbox business expense above 4 000 kr so the VAT close-check demo surfaces a high-value receipt-less expense. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(mcp): restore six spaces lost in the description-trimming pass Review finding (Greptile P2): the trim deleted single spaces in six tool descriptions ("Stages foruser", "länkatill", "kundfordran(1510)", …), producing malformed text in tools/list. All six were pure space deletions with no token gain — restored verbatim. Swept all 92 descriptions for residual merge artifacts; the two remaining matches are pre-existing function-call notation from main. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs(compliance): correct BFL citation in seed + mark 4000 kr as app heuristic Swedish compliance review findings: - The seed comment cited BFL 5 kap 6§ as requiring verifikat on high-value affärshändelser; 6§ governs verifikationens innehåll. Rephrased: BFL 5 kap 6-7§ require every affärshändelse to be documented — the 4 000 kr cut-off is the tool's own heuristic, not a statutory threshold. - The connect-claude docs read as though 4 000 kr were a legal floor (conflatable with the förenklad faktura ceiling, ML 17 kap 26-28§). Clarified that BFL requires underlag regardless of amount. Dismissed as by-design: the gnubok_sk_test_... README placeholders (standard practice; the prefix schema is already public in llms.txt). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
0bc81d4c88
commit
a894af11d0
@@ -504,7 +504,12 @@ export async function POST(request: Request) {
|
||||
company_id: companyId,
|
||||
date: toDateStr(fiveDaysAgo),
|
||||
description: 'SJ BILJETT',
|
||||
amount: -2500,
|
||||
// > 4 000 kr categorized business expense with no attached underlag,
|
||||
// so gnubok_vat_close_check surfaces a non-empty blocker list.
|
||||
// (BFL 5 kap 6–7§ require every affärshändelse to be documented with
|
||||
// underlag; the 4 000 kr cut-off is the tool's own high-value
|
||||
// heuristic, not a statutory threshold.)
|
||||
amount: -4500,
|
||||
category: 'expense_travel',
|
||||
is_business: true,
|
||||
merchant_name: 'SJ',
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { CONNECT_CLAUDE_MD } from '@/lib/docs/content/connect-claude'
|
||||
import { withPublicSecurityHeaders } from '@/lib/api/v1/security-headers'
|
||||
|
||||
export async function GET() {
|
||||
return new NextResponse(CONNECT_CLAUDE_MD, {
|
||||
status: 200,
|
||||
headers: withPublicSecurityHeaders({
|
||||
'Content-Type': 'text/markdown; charset=utf-8',
|
||||
'Cache-Control': 'public, max-age=300, s-maxage=300',
|
||||
}),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { Metadata } from 'next'
|
||||
import { DocsLayout } from '@/components/docs/DocsLayout'
|
||||
import { DocsMarkdown } from '@/lib/docs/markdown'
|
||||
import { CONNECT_CLAUDE_MD } from '@/lib/docs/content/connect-claude'
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Connect with Claude · accounted API',
|
||||
description:
|
||||
'Connect Accounted to Claude (claude.ai, Claude Desktop, Claude Code) via the MCP server — OAuth 2.1 connector or the npx gnubok-mcp stdio bridge.',
|
||||
}
|
||||
|
||||
export default function DocsApiConnectClaudePage() {
|
||||
return (
|
||||
<DocsLayout currentPath="/docs/api/connect-claude">
|
||||
<DocsMarkdown source={CONNECT_CLAUDE_MD} />
|
||||
</DocsLayout>
|
||||
)
|
||||
}
|
||||
@@ -21,7 +21,7 @@ For internal Anthropic API usage (today only `extensions/general/invoice-inbox/l
|
||||
|
||||
## Payload-size watchdog
|
||||
|
||||
`payload-size.bench.test.ts` enforces a `tools/list` JSON payload ceiling (currently 25,000 tokens). If the test fires, the right answer is rarely "raise the ceiling" — instead, trim descriptions or leverage `gnubok_search_tools` (already deployed; tool definitions can defer to it for discovery rather than enumerating in `tools/list`).
|
||||
`payload-size.bench.test.ts` enforces a `tools/list` JSON payload ceiling (currently 36,000 tokens — bumped from 32,000 when top-level `Tool.title` landed on all tools for Claude Connectors Directory readiness). If the test fires, the right answer is rarely "raise the ceiling" — instead, trim descriptions or leverage `gnubok_search_tools` (already deployed; tool definitions can defer to it for discovery rather than enumerating in `tools/list`).
|
||||
|
||||
## Where things live
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ describe('tools/list payload size guard', () => {
|
||||
it('keeps the projected tools/list payload under the context-budget ceiling', () => {
|
||||
const projection = tools.map((t) => ({
|
||||
name: t.name,
|
||||
...(t.title ? { title: t.title } : {}),
|
||||
description: t.description,
|
||||
inputSchema: t.inputSchema,
|
||||
...(t.outputSchema ? { outputSchema: t.outputSchema } : {}),
|
||||
@@ -13,7 +14,7 @@ describe('tools/list payload size guard', () => {
|
||||
}))
|
||||
const payload = JSON.stringify({ tools: projection })
|
||||
const approxTokens = Math.round(payload.length / 4)
|
||||
// Ceiling progression: 20K → 25K → 30K → 31K → 31.5K.
|
||||
// Ceiling progression: 20K → 25K → 30K → 31K → 31.5K → 32K → 36K.
|
||||
// * 20K → 25K when item 8 of the agent-native API plan landed
|
||||
// (additionalProperties: false on all inputSchemas + period_status in the
|
||||
// staged operation envelope).
|
||||
@@ -38,9 +39,13 @@ describe('tools/list payload size guard', () => {
|
||||
// faktura paid against an already-posted verifikat (no new bokföring),
|
||||
// which is exactly the fix for invoices imported from Fortnox as open
|
||||
// payables while their payment already exists in the SIE-imported GL.
|
||||
// * 32K → 36K when top-level Tool.title (MCP spec 2025-06-18) landed on all
|
||||
// 92 tools for Connectors Directory readiness; the ~10 longest descriptions
|
||||
// were trimmed toward 180–200 chars to partly offset. Headroom reserved for
|
||||
// the upcoming Skatteverket tools.
|
||||
// Long-term answer to growth is leaning harder on gnubok_search_tools — if this
|
||||
// fires again, prefer trimming descriptions or making a tool opt-in via search
|
||||
// before bumping further.
|
||||
expect(approxTokens).toBeLessThan(32_000)
|
||||
expect(approxTokens).toBeLessThan(36_000)
|
||||
})
|
||||
})
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,78 @@
|
||||
export const CONNECT_CLAUDE_MD = `# Connect with Claude
|
||||
|
||||
> Talk to your bookkeeping. Connect Accounted to Claude (claude.ai, Claude Desktop, or Claude Code) and ask questions, categorise transactions, and prepare a momsdeklaration in plain language — every write still stages for your approval first.
|
||||
|
||||
Accounted ships an [MCP](https://modelcontextprotocol.io) server that exposes the full bookkeeping engine — 90+ tools — to any MCP client. The endpoint is:
|
||||
|
||||
\`\`\`
|
||||
https://gnubok.app/api/extensions/ext/mcp-server/mcp
|
||||
\`\`\`
|
||||
|
||||
There are two ways to connect, depending on your client. Both reach the same tools and the same approval model: read tools answer immediately, write tools (categorise, mark paid, create voucher, year-end) **stage a pending operation** that you confirm in chat or in the **/pending** web UI before anything is booked.
|
||||
|
||||
## Path A — claude.ai / Claude Desktop custom connector (OAuth 2.1)
|
||||
|
||||
Best for most users. No API key to manage — you authorise Accounted the same way you'd authorise any OAuth app.
|
||||
|
||||
1. In **claude.ai** (Settings → Connectors) or **Claude Desktop** (Settings → Connectors → Add custom connector), choose **Add custom connector**.
|
||||
2. Paste the connector URL:
|
||||
\`\`\`
|
||||
https://gnubok.app/api/extensions/ext/mcp-server/mcp
|
||||
\`\`\`
|
||||
3. Claude opens the Accounted OAuth 2.1 consent screen. Sign in and pick the company you want Claude to act on.
|
||||
4. On the consent screen you grant **read-only scopes by default** (list invoices, read reports, compute VAT). Write scopes (create invoice, categorise, book vouchers, run year-end) are **listed separately and must be ticked explicitly** — leave them unchecked for a read-only review session.
|
||||
5. Approve. Claude now lists the Accounted tools and you can start asking questions.
|
||||
|
||||
Because the consent is per-company and scoped, you can connect a read-only key for a reviewer and a separate write-enabled connection for day-to-day bookkeeping.
|
||||
|
||||
## Path B — \`npx gnubok-mcp\` with an API key (stdio bridge)
|
||||
|
||||
Best for Claude Desktop on a machine where you'd rather use a long-lived API key than the OAuth flow, or for scripting.
|
||||
|
||||
1. Mint an API key in the Accounted dashboard at **/settings/api**. Use a \`gnubok_sk_test_*\` key against the sandbox while you evaluate; switch to \`gnubok_sk_live_*\` for real data.
|
||||
2. Add the stdio bridge to your \`claude_desktop_config.json\`:
|
||||
\`\`\`json
|
||||
{
|
||||
"mcpServers": {
|
||||
"gnubok": {
|
||||
"command": "npx",
|
||||
"args": ["gnubok-mcp"],
|
||||
"env": {
|
||||
"GNUBOK_API_KEY": "gnubok_sk_test_..."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
\`\`\`
|
||||
3. Restart Claude Desktop. The bridge proxies stdio JSON-RPC to the hosted MCP endpoint over HTTPS; the key carries the scopes you granted it at mint time.
|
||||
|
||||
The key's scopes gate exactly which tools are callable — a key without write scopes can read reports and ledgers but cannot stage a booking.
|
||||
|
||||
## Try these prompts
|
||||
|
||||
All three run against the deterministic sandbox seed (use a \`gnubok_sk_test_*\` key or pick the sandbox company on the OAuth consent screen). They exercise the read path end-to-end without booking anything.
|
||||
|
||||
1. **"Show my uncategorized bank transactions and suggest categories."**
|
||||
Claude calls \`gnubok_list_uncategorized_transactions\` then \`gnubok_suggest_categories\` and walks you through the proposals. Approving one stages a \`gnubok_categorize_transaction\` pending operation — nothing is booked until you confirm.
|
||||
2. **"Which invoices are overdue?"**
|
||||
Claude calls \`gnubok_get_ar_ledger\` (kundreskontra) and lists outstanding customer invoices with aging.
|
||||
3. **"Compute my VAT report for this quarter and tell me if I can close it."**
|
||||
Claude calls \`gnubok_get_vat_report\` for the momsdeklaration rutor, then \`gnubok_vat_close_check\` to scan for blockers (uncategorised rows, unapproved supplier invoices, missing receipts on expenses ≥ 4 000 kr — the tool's high-value heuristic; BFL requires underlag for every affärshändelse regardless of amount) and reports \`ready_to_close\`.
|
||||
|
||||
## 10-minute reviewer test
|
||||
|
||||
A quick end-to-end pass to confirm the connection works before you trust it with real data. Run the steps in order; each lists what you do and what you should see.
|
||||
|
||||
1. **Connect.** Use Path A (read-only scopes only) or Path B with a \`gnubok_sk_test_*\` key. → Claude lists the Accounted tools (titles like *List Uncategorized Transactions*, *VAT Declaration (Momsdeklaration)*).
|
||||
2. **Confirm the company.** Ask *"Which company am I connected to?"* → Claude names the sandbox company (e.g. **Sandlådan Konsult**).
|
||||
3. **Run prompt 1** (*uncategorized + suggest categories*). → A list of uncategorised rows plus category suggestions; no booking happens.
|
||||
4. **Run prompt 2** (*overdue invoices*). → At least one overdue customer invoice with aging.
|
||||
5. **Run prompt 3** (*VAT report + can I close*). → Momsdeklaration rutor returned; \`vat_close_check\` reports a **non-empty blocker list** (uncategorised transactions, an unapproved leverantörsfaktura, and a high-value business expense without a receipt).
|
||||
6. **Stage a write.** Ask Claude to categorise one transaction. → Claude stages a pending operation and asks you to confirm — the booking does **not** post until you approve in chat or at **/pending**.
|
||||
|
||||
If every step matches, the connector is wired correctly and the approval model is enforced.
|
||||
|
||||
## Support
|
||||
|
||||
Stuck connecting, or seeing an unexpected blocker? Use the in-app support form at **/help** — it routes straight to the product team with your company context attached. Include the client (claude.ai / Desktop / Code), the path you used (A or B), and the tool name from any error message.
|
||||
`
|
||||
@@ -27,6 +27,7 @@ export const DOCS_NAV: DocsNavSection[] = [
|
||||
{ label: 'Introduction', href: '/docs/api', summary: 'What the Accounted REST API is and how to authenticate.' },
|
||||
{ label: 'Quickstart', href: '/docs/api/cookbook/quickstart', summary: 'Send your first invoice in five minutes.' },
|
||||
{ label: 'Authentication', href: '/docs/api#authentication', summary: 'API keys, scopes, test mode.' },
|
||||
{ label: 'Connect with Claude', href: '/docs/api/connect-claude', summary: 'Connect Claude via the MCP server — OAuth connector or npx gnubok-mcp bridge.' },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
# gnubok-mcp
|
||||
|
||||
Connect [Claude Desktop](https://claude.ai/download) (or any stdio MCP client) to your [Accounted](https://gnubok.app) bookkeeping account. This is a thin stdio → HTTPS bridge: it forwards JSON-RPC over stdio to the hosted Accounted MCP server, which exposes 90+ bookkeeping tools (invoices, transactions, VAT/momsdeklaration, payroll, reports, year-end).
|
||||
|
||||
Write tools stage a pending operation that you confirm before anything is booked — the bridge never books on its own.
|
||||
|
||||
## Quickstart
|
||||
|
||||
1. Mint an API key in the Accounted dashboard at **[/settings/api](https://app.gnubok.se/settings?tab=api)**. Use a `gnubok_sk_test_*` key against the sandbox while you evaluate; switch to `gnubok_sk_live_*` for real data. The key's scopes gate which tools are callable.
|
||||
|
||||
2. Run the bridge with the key in the environment:
|
||||
|
||||
```bash
|
||||
GNUBOK_API_KEY=gnubok_sk_test_... npx gnubok-mcp
|
||||
```
|
||||
|
||||
It reads JSON-RPC from stdin and writes responses to stdout, so you normally point an MCP client at it rather than running it by hand.
|
||||
|
||||
## Claude Desktop config
|
||||
|
||||
Add the bridge to your `claude_desktop_config.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"gnubok": {
|
||||
"command": "npx",
|
||||
"args": ["gnubok-mcp"],
|
||||
"env": {
|
||||
"GNUBOK_API_KEY": "gnubok_sk_test_..."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Restart Claude Desktop. The Accounted tools appear in the client and you can start asking questions like *"Show my uncategorized bank transactions and suggest categories."*
|
||||
|
||||
### Environment variables
|
||||
|
||||
| Variable | Required | Default | Purpose |
|
||||
|---|---|---|---|
|
||||
| `GNUBOK_API_KEY` | yes | — | Your `gnubok_sk_*` API key. |
|
||||
| `GNUBOK_URL` | no | `https://app.gnubok.se/api/extensions/ext/mcp-server/mcp` | Override the MCP endpoint (e.g. for self-hosted Accounted). |
|
||||
|
||||
## Alternative: claude.ai connector (no API key)
|
||||
|
||||
If you use **claude.ai** or Claude Desktop's custom-connector flow, you can skip this bridge entirely and add Accounted as an OAuth 2.1 custom connector instead — paste the connector URL `https://gnubok.app/api/extensions/ext/mcp-server/mcp` and authorise on the Accounted consent screen (read-only scopes by default; write scopes are ticked explicitly).
|
||||
|
||||
## Docs
|
||||
|
||||
Full setup, sample prompts, and a 10-minute reviewer test: **[Connect with Claude](https://gnubok.app/docs/api/connect-claude)**.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
@@ -22,6 +22,7 @@
|
||||
"node": ">=18"
|
||||
},
|
||||
"files": [
|
||||
"index.mjs"
|
||||
"index.mjs",
|
||||
"README.md"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user