@ekwo-ai/mcp 0.27.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.d.ts CHANGED
@@ -23,7 +23,7 @@ export declare const SERVER_NAME = "@ekwo-ai/mcp";
23
23
  * `tests/mcp/surface.test.ts` keeps the two equal, so a release that bumps one
24
24
  * and forgets the other fails the build.
25
25
  */
26
- export declare const SERVER_VERSION = "0.27.0";
26
+ export declare const SERVER_VERSION = "0.29.0";
27
27
  export interface ServerOptions {
28
28
  /**
29
29
  * The modules this installation carries, from `public.modules`. Their tools
@@ -76,7 +76,21 @@ export interface ServerOptions {
76
76
  * `tools/loading.ts`.
77
77
  */
78
78
  tools?: ToolLoading;
79
+ /**
80
+ * The version of a database older than `SCHEMA_MIN`, which this server
81
+ * opens for reading only: every tool that writes is refused by name with
82
+ * the command that upgrades it, and the instructions say so. `start.ts` and
83
+ * `http.ts` set it from `readSchemaStatus()`; left out, the database is at
84
+ * the floor or above.
85
+ */
86
+ belowFloor?: string;
79
87
  }
88
+ /**
89
+ * The period a report of the ledger reads, said once for every tool that takes
90
+ * `from` and `to`: the same figure asked two ways is the same answer, and the
91
+ * screens of the books read a year in progress up to today.
92
+ */
93
+ export declare const PERIOD_READ = "A financial year in progress is read up to today unless the person asks otherwise; the answer states the period read.";
80
94
  /**
81
95
  * What a client reads at the handshake, before it calls anything.
82
96
  *
@@ -89,6 +103,8 @@ export interface ServerOptions {
89
103
  export declare const INSTRUCTIONS: string;
90
104
  /** The instructions, with the invitation to register and the Cloud offer when they apply. */
91
105
  export declare function instructionsFor(options?: ServerOptions): string;
106
+ /** What a client is told at the handshake about a database below the floor. */
107
+ export declare function belowFloorInstructions(installed: string): string;
92
108
  /**
93
109
  * `registerTool`, as this server allows it: with a title, a description and
94
110
  * the hints of what the tool does (`tools/effect.ts`). A registration without
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.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,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,aAAkB,GAAG,SAAS,CAs1CpF"}
package/dist/server.js CHANGED
@@ -11,6 +11,7 @@
11
11
  import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
12
12
  import { z } from 'zod';
13
13
  import { EkwoMcpError } from './backend.js';
14
+ import { MISSING_OBJECT, SCHEMA_MIN, UPGRADE_COMMAND, belowFloorRefusal } from './schema.js';
14
15
  import { columns, relayableCloudOffer, relayableInvitation } from '@ekwo-ai/core';
15
16
  import * as read from './tools/read.js';
16
17
  import * as write from './tools/write.js';
@@ -26,7 +27,7 @@ export const SERVER_NAME = '@ekwo-ai/mcp';
26
27
  * `tests/mcp/surface.test.ts` keeps the two equal, so a release that bumps one
27
28
  * and forgets the other fails the build.
28
29
  */
29
- export const SERVER_VERSION = '0.27.0';
30
+ export const SERVER_VERSION = '0.29.0';
30
31
  /** Everything a tool returns: JSON, pretty-printed, as one text block. */
31
32
  function ok(payload) {
32
33
  return { content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }] };
@@ -54,6 +55,12 @@ async function guard(run) {
54
55
  return fail(error);
55
56
  }
56
57
  }
58
+ /**
59
+ * The period a report of the ledger reads, said once for every tool that takes
60
+ * `from` and `to`: the same figure asked two ways is the same answer, and the
61
+ * screens of the books read a year in progress up to today.
62
+ */
63
+ export const PERIOD_READ = 'A financial year in progress is read up to today unless the person asks otherwise; the answer states the period read.';
57
64
  /**
58
65
  * What a client reads at the handshake, before it calls anything.
59
66
  *
@@ -66,7 +73,7 @@ async function guard(run) {
66
73
  export const INSTRUCTIONS = [
67
74
  'Ekwo OS keeps double-entry books in the user\'s own Postgres. You act as that user: everything you can see and change is what row level security lets them see and change. Amounts are decimal strings ("1210.00"), dates are ISO (2026-06-15), identifiers are uuids.',
68
75
  'A first session, in order. (1) list_companies: every other tool takes a company_id from it; an empty list means this user has not been invited to a company yet, and status says who you are acting as. (2) get_company: the financial years and whether each is closed, the lock dates, the journals and the role accounts — a date you book on falls in an open year, after the lock date. (3) list_accounts and the resource ekwo://companies/{companyId}/taxes: a document line names its account and its tax by code, never by rate, because several taxes share a rate; describe_pack says which country pack those codes come from and how far it has been reviewed. (4) search_contacts, then create_contact only if nobody matches, then create_document: a draft with the totals the database computed. Show it to the user. (5) post_document once the user has said yes to that document; record_payment when the money moves. How you may post is the database\'s to hold you to, and status says it: the company\'s agent_posting (in get_company) and the choice the person made for this session. In review, the default, a document is posted only after a person approved that draft as it stands, and post_document is refused with approval_required until then; in autopilot — the company\'s setting, or a session the person started so — you post directly, and every posting is recorded on the audit trail with this session. A company that forbids autopilot refuses it (autopilot_forbidden).',
69
- 'Reading a tax return: vat_return gives the boxes of a period with their names and amounts, summed from what was posted, and the boxes computed from other boxes; a draft is in no box. Name a report_code only where the country files several declarations. It prepares figures and files nothing — the prompt prepare_vat_return walks through checking them against the ledger. The reports beside it are trial_balance, general_ledger, journal_book (the book of one journal or of all of them, with the totals of each), aged_balance, subledger (a receivable or payable account contact by contact, with its control against the trial balance), contact_statement (one contact), financial_statement (list_statements first), financial_analysis, the figures a ratio is computed from, and analytic_report, the result of each project, cost centre or site of an analytic axis.',
76
+ 'Reading a tax return: vat_return gives the boxes of a period with their names and amounts, summed from what was posted, and the boxes computed from other boxes; a draft is in no box. Name a report_code only where the country files several declarations. It prepares figures and files nothing — the prompt prepare_vat_return walks through checking them against the ledger. The reports beside it are trial_balance, general_ledger, journal_book (the book of one journal or of all of them, with the totals of each), aged_balance, subledger (a receivable or payable account contact by contact, with its control against the trial balance), contact_statement (one contact), financial_statement (list_statements first), financial_analysis, the figures a ratio is computed from, and analytic_report, the result of each project, cost centre or site of an analytic axis. The period: a financial year that is over is read whole, from its first day to its last; a year in progress from its first day to today, unless the person asks for another period. Every answer states the period it read.',
70
77
  'Correcting: a posted entry is never deleted or edited. A posted invoice is undone by cancel_document — back to draft where its country allows it and nothing has left, by the credit note that names it otherwise, and it says which — and an entry keyed by hand by reverse_entry. A paid document is unmatched first with unreconcile, and only when the user says so. Ask the user before every post, cancel, reversal, payment or lock.',
71
78
  'When the database refuses, the message starts with a name — period_locked, entry_unbalanced, document_total_mismatch, reversal_date_needed — followed by a sentence saying what to do next. Report it to the user and follow that sentence rather than working around it.',
72
79
  ].join('\n\n');
@@ -77,8 +84,13 @@ export function instructionsFor(options = {}) {
77
84
  ...(options.inviteToRegister === true ? [relayableInvitation()] : []),
78
85
  ...(options.offerCloud === true ? [relayableCloudOffer()] : []),
79
86
  ...(options.tools === 'on_demand' ? [ON_DEMAND_INSTRUCTIONS] : []),
87
+ ...(options.belowFloor === undefined ? [] : [belowFloorInstructions(options.belowFloor)]),
80
88
  ].join('\n\n');
81
89
  }
90
+ /** What a client is told at the handshake about a database below the floor. */
91
+ export function belowFloorInstructions(installed) {
92
+ return `This installation's schema is at ${installed}, older than ${SCHEMA_MIN}, the oldest this server writes to. Its books are open for reading: every tool that reads answers with what this schema holds. Every tool that writes is refused with schema_too_old until the database is upgraded with \`${UPGRADE_COMMAND}\`. Say so once to the person you act for, who decides when to upgrade; nothing in the books is lost by it.`;
93
+ }
82
94
  /**
83
95
  * The same tool, with its title where every reader looks for it.
84
96
  *
@@ -102,13 +114,33 @@ function titled(config) {
102
114
  * `tests/mcp/surface.test.ts` reads the list a client sees to make sure none
103
115
  * slipped past.
104
116
  */
105
- function toolRegistrar(server, registered) {
117
+ function toolRegistrar(server, registered, belowFloor) {
106
118
  return (name, config, cb) => {
107
- const tool = server.registerTool(name, titled(config), cb);
119
+ const callback = belowFloor === undefined ? cb : readOnlyBelowTheFloor(name, config.annotations, cb, belowFloor);
120
+ const tool = server.registerTool(name, titled(config), callback);
108
121
  registered.set(name, tool);
109
122
  return tool;
110
123
  };
111
124
  }
125
+ /**
126
+ * A tool on a database below the floor. One that writes is refused before it
127
+ * reaches the database; one that reads runs, and a read that asked for a
128
+ * column, a function or a table this schema does not have is refused by name
129
+ * rather than answered with Postgres's sentence.
130
+ */
131
+ function readOnlyBelowTheFloor(name, annotations, cb, installed) {
132
+ if (annotations.readOnlyHint !== true) {
133
+ return (async () => fail(belowFloorRefusal(name, installed, 'write')));
134
+ }
135
+ const run = cb;
136
+ return (async (...args) => {
137
+ const answer = await run(...args);
138
+ if (answer.isError !== true)
139
+ return answer;
140
+ const said = answer.content.map((part) => (part.type === 'text' ? part.text : '')).join('\n');
141
+ return MISSING_OBJECT.test(said) ? fail(belowFloorRefusal(name, installed, 'read')) : answer;
142
+ });
143
+ }
112
144
  /**
113
145
  * The sentence the posting tools end with: how this session posts, as the
114
146
  * person who started it chose — the tool list is read once, so it is said
@@ -127,7 +159,7 @@ export function sessionPosting(backend) {
127
159
  export function buildServer(backend, options = {}) {
128
160
  const server = new McpServer({ name: SERVER_NAME, version: SERVER_VERSION }, { instructions: instructionsFor(options) });
129
161
  const tools = new Map();
130
- const register = toolRegistrar(server, tools);
162
+ const register = toolRegistrar(server, tools, options.belowFloor);
131
163
  // -------------------------------------------------------------------- read
132
164
  register('list_companies', {
133
165
  title: 'List companies',
@@ -143,13 +175,13 @@ export function buildServer(backend, options = {}) {
143
175
  }, async (args) => guard(() => read.getCompany(backend, args)));
144
176
  register('list_accounts', {
145
177
  title: 'Chart of accounts',
146
- description: 'The accounts a company actually works with, filtered by code prefix, by account type, or by a search on the name. Use it to find the income or expense account a document line should carry. By default it returns the working chart — the accounts that carry entries, that the company\'s settings or an enabled module point at, or that somebody pinned — because a country pack transcribes the whole regulation and a company uses a few dozen of its several hundred accounts; `in_use_from` and `in_use_to` narrow the movements to a period, `include_all` returns the whole chart, and `include_deprecated` returns it with the retired accounts too. This is a reading and not a restriction: any account of the chart that is not deprecated may still be booked on.',
178
+ description: 'The accounts a company actually works with, filtered by code prefix, by account type, or by a search on the name. Use it to find the income or expense account a document line should carry. By default it returns the working chart — the accounts that carry entries, that the company\'s settings or an enabled module point at, or that somebody pinned — because a country pack transcribes the whole regulation and a company uses a few dozen of its several hundred accounts; `in_use_from` and `in_use_to` narrow the movements to a period, `include_all` returns the whole chart, and `include_deprecated` returns it with the retired accounts too. This is a reading and not a restriction: any account of the chart that is not deprecated may still be booked on. A limit above 1000 can come back cut at the row cap of the server (max_rows, 1000 by default) with truncated false: narrow by code_prefix or account_type rather than read a whole chart in one call.',
147
179
  inputSchema: read.ListAccountsInput.shape,
148
180
  annotations: { readOnlyHint: true, openWorldHint: false },
149
181
  }, async (args) => guard(() => read.listAccounts(backend, args)));
150
182
  register('search_contacts', {
151
183
  title: 'Find a contact',
152
- description: 'Customers, suppliers and other third parties of a company, by name, by type or by VAT number. Use it before creating a document: a document is booked against a contact, and creating a second contact for a customer who already exists splits their account. Nobody matches: create_contact. Found: create_document with its id.',
184
+ description: 'Customers, suppliers and other third parties of a company, by name, by type or by VAT number. Use it before creating a document: a document is booked against a contact, and creating a second contact for a customer who already exists splits their account. Nobody matches: create_contact. Found: create_document with its id. A contact merged into another one is returned too, inactive, with merged_into naming the contact that holds its history — the contact to book against; include_merged: false leaves them out, as the contact list of the application does. with_balance: true also says where each contact\'s account stands (balance, open_items) in the same call; read contact_statement instead when the user wants the lines behind the figure or a period.',
153
185
  inputSchema: read.SearchContactsInput.shape,
154
186
  annotations: { readOnlyHint: true, openWorldHint: false },
155
187
  }, async (args) => guard(() => read.searchContacts(backend, args)));
@@ -161,13 +193,19 @@ export function buildServer(backend, options = {}) {
161
193
  }, async (args) => guard(() => read.suggestDuplicateContacts(backend, args)));
162
194
  register('contact_statement', {
163
195
  title: 'Statement of a contact',
164
- description: 'The statement of account of one customer or supplier over a period: the balance carried forward from before it, then every posted line of their receivable and payable accounts — date, journal, entry, the document it books, debit, credit and running balance — and the balance the period ends on. Debit minus credit, in the company currency: positive is what the contact owes the company, negative what the company owes them. Each line says how far a matching has settled it today (matching_state open, partial or matched, and open_amount). Drafts are not in it. It is the ledger read for one contact, the same figures aged_balance gives.',
196
+ description: 'The statement of account of one customer or supplier over a period: the balance carried forward from before it, then every posted line of their receivable and payable accounts — date, journal, entry, the document it books, debit, credit and running balance — and the balance the period ends on. Debit minus credit, in the company currency: positive is what the contact owes the company, negative what the company owes them. Each line says how far a matching has settled it today (matching_state open, partial or matched, and open_amount). Drafts are not in it. It is the ledger read for one contact, on the accounts aged_balance reads, with the opposite sign on a payable: aged_balance gives what is still open as a positive amount on either side, one side at a time.',
165
197
  inputSchema: read.ContactStatementInput.shape,
166
198
  annotations: { readOnlyHint: true, openWorldHint: false },
167
199
  }, async (args) => guard(() => read.contactStatement(backend, args)));
200
+ register('list_tax_certificates', {
201
+ title: 'Certificates the buyers handed over',
202
+ description: 'The certificates the buyers of a company handed over — resale certificates, exemption certificates, declarations of intent — with the contact, the reference, the territory under whose law each was given and the days it covers, the most recent first. A sale invoice under a tax that applies on such a certificate (its conditions in describe_pack include buyer_certificate) posts only if its buyer holds one that covers the document\'s date and place of supply; post_document is refused with no_buyer_certificate otherwise.',
203
+ inputSchema: read.ListTaxCertificatesInput.shape,
204
+ annotations: { readOnlyHint: true, openWorldHint: false },
205
+ }, async (args) => guard(() => read.listTaxCertificates(backend, args)));
168
206
  register('list_documents', {
169
207
  title: 'List documents',
170
- description: 'Invoices, credit notes and quotes of a company, filtered by type, state, settlement state, contact or date range. `state` is the document (draft, posted, cancelled) and `payment_state` is the settlement (not_paid, partially_paid, paid) — two different questions. A quote or an order also carries its answer (accepted_at, accepted_by, declined_at) and `quote_status` — draft, sent, accepted, declined, expired or cancelled — derived by the database from those facts; null on other documents. Returns headers and totals, not lines; use get_document for those.',
208
+ description: 'Invoices, credit notes and quotes of a company, filtered by type, state, settlement state, contact, date range or number — a document asked for by its number is found with `number`, without scanning dates. `state` is the document (draft, posted, cancelled) and `payment_state` is the settlement (not_paid, partially_paid, paid) — two different questions. A quote or an order also carries its answer (accepted_at, accepted_by, declined_at) and `quote_status` — draft, sent, accepted, declined, expired or cancelled — derived by the database from those facts; null on other documents. Returns headers and totals, not lines; use get_document for those. No type is assumed: `state: draft` returns the draft quotes and orders too, and `unpaid: true` the credit notes still open beside the invoices. To count invoices as the application does, name the types — `doc_types: ["sale_invoice", "sale_credit_note"]` for the drafts of sales, `doc_type: "sale_invoice"` (or `"purchase_invoice"`) with `unpaid` for what is still owed.',
171
209
  inputSchema: read.ListDocumentsInput.shape,
172
210
  annotations: { readOnlyHint: true, openWorldHint: false },
173
211
  }, async (args) => guard(() => read.listDocuments(backend, args)));
@@ -177,6 +215,12 @@ export function buildServer(backend, options = {}) {
177
215
  inputSchema: read.GetDocumentInput.shape,
178
216
  annotations: { readOnlyHint: true, openWorldHint: false },
179
217
  }, async (args) => guard(() => read.getDocument(backend, args)));
218
+ register('list_document_files', {
219
+ title: 'The files recorded on a document',
220
+ description: 'The pieces recorded on one document — the PDF of a supplier\'s invoice, the photograph of a receipt — with where each is stored, its name, type, size and SHA-256, the first recorded first. The rows only: the file is read where storage_path says, by whoever has access to that storage.',
221
+ inputSchema: read.ListDocumentFilesInput.shape,
222
+ annotations: { readOnlyHint: true, openWorldHint: false },
223
+ }, async (args) => guard(() => read.listDocumentFiles(backend, args)));
180
224
  register('render_invoice_pdf', {
181
225
  title: 'The PDF of an invoice',
182
226
  description: 'The PDF of a sale invoice or a sale credit note, rendered from the books: the seller with its logo, the buyer, the lines, the tax summary, the totals and what is still due, how to pay, and the legal mentions the country requires — as the views publish them, in the accent colour and on the logo side the company set with update_company_profile. Comes back as a PDF resource (base64) beside a JSON summary: filename, pages, whether the logo was used. factur_x: true embeds the CII XML of a posted document and returns the rules of EN 16931 it breaks. Words of the layout are English unless labels gives them in the document\'s language. Records nothing, sends nothing: the copy a customer received is not kept here.',
@@ -226,25 +270,28 @@ export function buildServer(backend, options = {}) {
226
270
  }, async (args) => guard(() => read.listShares(backend, args)));
227
271
  register('list_bank_transactions', {
228
272
  title: 'Bank transactions',
229
- description: 'Statement lines of a company, pending by default — the ones still waiting to be dealt with. `amount` is signed: positive is money in. A statement line is not a ledger entry; recording a payment is what books it.',
273
+ description: 'Statement lines of a company, pending by default — the ones still waiting to be dealt with. `amount` is signed: positive is money in. A statement line is not a ledger entry; recording a payment is what books it. Every bank account of the company is read, closed ones included, and bank_accounts lists them with their active flag; include_inactive_accounts: false keeps the active accounts only, as the bank screen of the application does.',
230
274
  inputSchema: read.ListBankTransactionsInput.shape,
231
275
  annotations: { readOnlyHint: true, openWorldHint: false },
232
276
  }, async (args) => guard(() => read.listBankTransactions(backend, args)));
233
277
  register('trial_balance', {
234
278
  title: 'Trial balance',
235
- description: 'Opening balance, movements of the period and closing balance for every account, from posted entries only. The debit and credit totals are equal on a healthy ledger; if they are not, say so rather than explaining it away.',
279
+ description: 'Opening balance, movements of the period and closing balance for every account, from posted entries only. The debit and credit totals are equal on a healthy ledger; if they are not, say so rather than explaining it away. The closing entries are in it: on a closed year every income and expense account ends at nothing, so the result of that year is read from financial_statement (the income statement) or financial_analysis. Balances run across years: while a year is not closed, an income or expense account carries it into the opening and closing balances of the next.' +
280
+ ` ${PERIOD_READ}`,
236
281
  inputSchema: read.TrialBalanceInput.shape,
237
282
  annotations: { readOnlyHint: true, openWorldHint: false },
238
283
  }, async (args) => guard(() => read.trialBalance(backend, args)));
239
284
  register('general_ledger', {
240
285
  title: 'General ledger',
241
- description: 'Every posted line of an account over a period, with the balance carried forward from before it and a running balance. Give account_code for one account; leave it out for all of them, which on a real company is a lot of lines. contact_ids keeps the lines of those contacts only, each with its own balance carried forward and running balance — the detail of a row of subledger.',
286
+ description: 'Every posted line of an account over a period, with the balance carried forward from before it and a running balance. Give account_code for one account; leave it out for all of them, which on a real company is a lot of lines. contact_ids keeps the lines of those contacts only, each with its own balance carried forward and running balance — the detail of a row of subledger. Every line is returned; truncated is true only when a ledger too long to read was stopped before its end, and then narrow the period or name an account before reading the last balance as the closing one.' +
287
+ ` ${PERIOD_READ}`,
242
288
  inputSchema: read.GeneralLedgerInput.shape,
243
289
  annotations: { readOnlyHint: true, openWorldHint: false },
244
290
  }, async (args) => guard(() => read.generalLedger(backend, args)));
245
291
  register('journal_book', {
246
292
  title: 'Journal book',
247
- description: 'The book of a journal: every line of every posted entry over a period, in the order a book is read — day, journal, entry number, line — each with its entry, the document behind it, its account and its contact, and the totals of each journal at the head. Give journal_code for one journal (the sales journal, the bank); leave it out for the book of every journal, which on a real company is a lot of lines. For one account with its running balance, use general_ledger.',
293
+ description: 'The book of a journal: every line of every posted entry over a period, in the order a book is read — day, journal, entry number, line — each with its entry, the document behind it, its account and its contact, and the totals of each journal at the head. Give journal_code for one journal (the sales journal, the bank); leave it out for the book of every journal, which on a real company is a lot of lines. For one account with its running balance, use general_ledger. Every line is returned; truncated is true only when a book too long to read was stopped before its end, its lines then no longer add up to the totals, and the period or the journal has to be narrowed.' +
294
+ ` ${PERIOD_READ}`,
248
295
  inputSchema: read.JournalBookInput.shape,
249
296
  annotations: { readOnlyHint: true, openWorldHint: false },
250
297
  }, async (args) => guard(() => read.journalBook(backend, args)));
@@ -266,6 +313,12 @@ export function buildServer(backend, options = {}) {
266
313
  inputSchema: read.MatchingDifferenceOptionsInput.shape,
267
314
  annotations: { readOnlyHint: true, openWorldHint: false },
268
315
  }, async (args) => guard(() => read.matchingDifferenceOptions(backend, args)));
316
+ register('currency_revaluation', {
317
+ title: 'Foreign-currency positions at a closing day',
318
+ description: 'What close_fiscal_year would revalue on a closing day: every receivable and payable still open in a currency other than the company\'s — for the part no matching dated on or before that day settled — and every bank account kept in one, by account, counterparty and currency, with the amount in the currency, the amount the ledger carries it at, the closing rate — the company\'s own rate of that day, otherwise the installation\'s last rate on or before it — with the day and source of that rate (closing_rate_date, closing_rate_source), the amount at that rate and the difference. missing_rates lists the currencies with neither, which would refuse the close until set_closing_rate records one. It writes nothing.',
319
+ inputSchema: read.CurrencyRevaluationInput.shape,
320
+ annotations: { readOnlyHint: true, openWorldHint: false },
321
+ }, async (args) => guard(() => read.currencyRevaluation(backend, args)));
269
322
  register('aged_balance', {
270
323
  title: 'Aged balance',
271
324
  description: 'What customers still owe (or what is still owed to suppliers), bucketed by how overdue it is. It reads unmatched ledger lines, not invoices, so it ties back to the balance sheet: an invoice counts as settled only once its payment has been matched.',
@@ -274,13 +327,14 @@ export function buildServer(backend, options = {}) {
274
327
  }, async (args) => guard(() => read.agedBalance(backend, args)));
275
328
  register('subledger', {
276
329
  title: 'Subsidiary ledger',
277
- description: 'A control account read contact by contact, as an accountant audits it: for each receivable and payable account (or the one account_code names) and each contact, the balance brought forward from before the period, the debit and credit of the period, the closing balance, the number of lines of the period and the number still open today; the lines that name no contact in a row of their own, contact_id null. Debit minus credit, in the company currency; drafts are not in it. control gives, per account, its figures in the trial balance, the sum of its named contacts and the difference — the lines naming nobody — with ties_out true when that row is the difference to the cent. The lines of one row: general_ledger with account_code and contact_ids; one contact across its accounts: contact_statement.',
330
+ description: 'A control account read contact by contact, as an accountant audits it: for each receivable and payable account (or the one account_code names) and each contact, the balance brought forward from before the period, the debit and credit of the period, the closing balance, the number of lines of the period and the number still open today; the lines that name no contact in a row of their own, contact_id null. Debit minus credit, in the company currency; drafts are not in it. control gives, per account, its figures in the trial balance, the sum of its named contacts and the difference — the lines naming nobody — with ties_out true when that row is the difference to the cent. The lines of one row: general_ledger with account_code and contact_ids; one contact across its accounts: contact_statement.' +
331
+ ` ${PERIOD_READ}`,
278
332
  inputSchema: read.SubledgerInput.shape,
279
333
  annotations: { readOnlyHint: true, openWorldHint: false },
280
334
  }, async (args) => guard(() => read.subledger(backend, args)));
281
335
  register('vat_return', {
282
336
  title: 'VAT return',
283
- description: 'The boxes of the VAT return for a period, with their names: the base and tax boxes are summed from what the postings wrote on the ledger lines, the totals are derived from them by the declaration form of the country pack. No country rule lives in this tool, nor in the function behind it. Name a report_code only where a country files several declarations. It prepares figures; it files nothing.',
337
+ description: 'The boxes of the VAT return for a period, with their names: the base and tax boxes are summed from what the postings wrote on the ledger lines, the totals are derived from them by the declaration form of the country pack. No country rule lives in this tool, nor in the function behind it. Name a report_code only where a country files several declarations. It prepares figures; it files nothing. The boxes are read live from the ledger at the moment of the call. Where a declaration of the period was already prepared or filed, filing carries it — its state, dates and reference, and per box what was filed, what the ledger says now and the difference — and when drifted is true, tell the person that the filed figures are the ones the administration holds, that something was booked in the period since, and that changing a declaration that has gone takes a corrective.',
284
338
  inputSchema: read.VatReturnInput.shape,
285
339
  annotations: { readOnlyHint: true, openWorldHint: false },
286
340
  }, async (args) => guard(() => read.vatReturn(backend, args)));
@@ -322,13 +376,15 @@ export function buildServer(backend, options = {}) {
322
376
  }, async (args) => guard(() => read.listStatements(backend, args)));
323
377
  register('financial_statement', {
324
378
  title: 'Financial statement',
325
- description: 'A balance sheet or an income statement for a period, on the scheme the country pack declares — the Belgian abbreviated model, the French liasse — or on the generic framework by account type. Each line is summed from the accounts its rules catch and the totals are derived from the lines; no country rule lives in this tool. It also returns the accounts no line catches: if that list is not empty, say so instead of presenting a statement that does not tie out. It prepares figures; it files nothing.',
379
+ description: 'A balance sheet or an income statement for a period, on the scheme the country pack declares — the Belgian abbreviated model, the French liasse — or on the generic framework by account type. Each line is summed from the accounts its rules catch and the totals are derived from the lines; no country rule lives in this tool. It also returns the accounts no line catches: if that list is not empty, say so instead of presenting a statement that does not tie out. It prepares figures; it files nothing.' +
380
+ ` ${PERIOD_READ}`,
326
381
  inputSchema: read.FinancialStatementInput.shape,
327
382
  annotations: { readOnlyHint: true, openWorldHint: false },
328
383
  }, async (args) => guard(() => read.financialStatement(backend, args)));
329
384
  register('financial_analysis', {
330
385
  title: 'Financial analysis',
331
- description: "The figures an analysis of a company is computed from — revenue, other operating income, purchases, staff costs, depreciation, the financial result, income tax, the net result, equity, total and current assets, cash, trade receivables, current liabilities, trade payables, long-term debt — each with the accounts that make it. The movements are read over the period and the balances at its end; equity includes the result of the years not closed yet. Which accounts make each figure is written in the company's country pack and in no tool. Each row carries source: pack when the country pack defines the analysis; framework when it defines none and the figures are read by account type through the generic framework, which leaves out staff costs, the financial result and income tax because no account type tells them apart — say those are not read rather than zero. The figures are never to be guessed from account codes. Ratios — a margin, a current ratio, days of sales outstanding — are worked out from these, not stored. It prepares figures; it files nothing.",
386
+ description: "The figures an analysis of a company is computed from — revenue, other operating income, purchases, staff costs, depreciation, the financial result, income tax, the net result, equity, total and current assets, cash, trade receivables, current liabilities, trade payables, long-term debt — each with the accounts that make it. The movements are read over the period and the balances at its end; equity includes the result of the years not closed yet. Which accounts make each figure is written in the company's country pack and in no tool. Each row carries source: pack when the country pack defines the analysis; framework when it defines none and the figures are read by account type through the generic framework, which leaves out staff costs, the financial result and income tax because no account type tells them apart — say those are not read rather than zero. The figures are never to be guessed from account codes. Ratios — a margin, a current ratio, days of sales outstanding — are worked out from these, not stored. It prepares figures; it files nothing." +
387
+ ` ${PERIOD_READ}`,
332
388
  inputSchema: read.FinancialAnalysisInput.shape,
333
389
  annotations: { readOnlyHint: true, openWorldHint: false },
334
390
  }, async (args) => guard(() => read.financialAnalysis(backend, args)));
@@ -340,7 +396,8 @@ export function buildServer(backend, options = {}) {
340
396
  }, async (args) => guard(() => read.listAnalyticAxes(backend, args)));
341
397
  register('analytic_report', {
342
398
  title: 'Result by analytic value',
343
- description: 'The result of each value of one analytic axis over a period, read from the posted ledger: the income, the expense and their difference per value, in the company\'s currency, from the whole income statement — salaries, rent and depreciation included, wherever they were split — and fixed_assets, the net movement of the fixed-asset accounts, beside the result and never in it. A value with others below it holds their subtotal; its own amount alone is in the direct_ columns, and level is its depth. unassigned is the part no share of the axis reaches and total the whole period: the direct_ amounts and unassigned add up to total, so say how large unassigned is rather than presenting the values as the whole, and never add a parent to its children. The margin of each product is a different question, read from the invoices. It prepares figures; it files nothing.',
399
+ description: 'The result of each value of one analytic axis over a period, read from the posted ledger: the income, the expense and their difference per value, in the company\'s currency, from the whole income statement — salaries, rent and depreciation included, wherever they were split — and fixed_assets, the net movement of the fixed-asset accounts, beside the result and never in it. A value with others below it holds their subtotal; its own amount alone is in the direct_ columns, and level is its depth. unassigned is the part no share of the axis reaches and total the whole period: the direct_ amounts and unassigned add up to total, so say how large unassigned is rather than presenting the values as the whole, and never add a parent to its children. The margin of each product is a different question, read from the invoices. It prepares figures; it files nothing.' +
400
+ ` ${PERIOD_READ}`,
344
401
  inputSchema: read.AnalyticReportInput.shape,
345
402
  annotations: { readOnlyHint: true, openWorldHint: false },
346
403
  }, async (args) => guard(() => read.analyticReport(backend, args)));
@@ -352,7 +409,7 @@ export function buildServer(backend, options = {}) {
352
409
  }, async (args) => guard(() => read.generateFec(backend, args)));
353
410
  register('describe_pack', {
354
411
  title: 'Where a country pack comes from',
355
- description: "The country packs this installation holds, with their version, how much anyone has read them, and the register of texts each was built from — the title, the official publisher, an absolute link and the day somebody opened it, per text. Use it whenever you are asked where a rate, a chart of accounts or a box of the declaration comes from, and before repeating a figure a pack gave you: a community pack has not been read by an accountant, and the status says so. The article behind a single rule is on that rule itself — legal_reference on a tax or on a box — and the register is where that article can be read. It carries no copy of the law: a link that has gone quiet means the register is stale, never that the rule is wrong.",
412
+ description: "The country packs this installation holds, with their version, how much anyone has read them, and the register of texts each was built from — the title, the official publisher, an absolute link and the day somebody opened it, per text. Use it whenever you are asked where a rate, a chart of accounts or a box of the declaration comes from, and before repeating a figure a pack gave you: a community pack has not been read by an accountant, and the status says so. The article behind a single rule is on that rule itself — legal_reference on a tax or on a box — and the register is where that article can be read. It carries no copy of the law: a link that has gone quiet means the register is stale, never that the rule is wrong. It also lists the charts of accounts each country offers — a country may offer several, for instance one for companies and one for associations and foundations, each with its audience — and create_company takes the chosen one as chart_code.",
356
413
  inputSchema: read.DescribePackInput.shape,
357
414
  annotations: { readOnlyHint: true, openWorldHint: false },
358
415
  }, async (args) => guard(() => read.describePack(backend, args)));
@@ -393,6 +450,18 @@ export function buildServer(backend, options = {}) {
393
450
  inputSchema: write.CreateContactInput.shape,
394
451
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
395
452
  }, async (args) => guard(() => write.createContact(backend, args)));
453
+ register('set_contact_territory', {
454
+ title: 'Say where a contact is below its country',
455
+ description: 'Records the territory a contact is in below its country — the state of an American customer, the province of a Canadian supplier — as ISO 3166-2 with the country prefix (US-NY), or takes it back with null. A tax that names a territory is judged on it when a document is posted: the contact is the buyer on a sale and the seller on a purchase, and post_document refuses a tax whose territory the parties are not in (tax_territory_mismatch). Only where the taxes of the pack name territories (describe_pack), and only with what the user said: never guessed from an address. One outside the contact\'s country is refused (territory_outside_country). Posted documents keep the territory they were judged on.',
456
+ inputSchema: write.SetContactTerritoryInput.shape,
457
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
458
+ }, async (args) => guard(() => write.setContactTerritory(backend, args)));
459
+ register('record_tax_certificate', {
460
+ title: 'Record a certificate a buyer handed over',
461
+ description: 'Records on a contact a certificate they handed over — a resale certificate, an exemption certificate, a declaration of intent — with the number it carries, the territory under whose law it was given (left out, it covers every place of supply) and the days it covers. A sale invoice under a tax whose conditions include buyer_certificate is refused at posting (no_buyer_certificate) unless its buyer holds one valid on the document\'s date for its place of supply. Record only a certificate the user says they hold, with the figures written on it; never record one to get an invoice posted. Whether a certificate is good enough is in the article the tax cites, and the user\'s accountant answers it.',
462
+ inputSchema: write.RecordTaxCertificateInput.shape,
463
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
464
+ }, async (args) => guard(() => write.recordTaxCertificate(backend, args)));
396
465
  register('merge_contacts', {
397
466
  title: 'Merge two contacts of one company',
398
467
  description: 'One party created twice — two spellings of one customer, two imports of one supplier: everything that names the absorbed contact names the kept one afterwards, in one transaction — posted ledger lines and issued documents included, statement lines, payments, branches, files and learned motifs — and the kept contact\'s empty fields (VAT number, IBAN, address, email…) are filled from the absorbed one without overwriting any. The absorbed contact is retired, never deleted, and no row may name it again. No amount, account, date or tax box moves, and there is no unmerge. Refused by name: unknown_contact (also a contact of another company), same_contact, already_merged, different_identifiers (two different VAT or registration numbers are two parties), matching_across_parties, not_allowed. suggest_duplicate_contacts proposes the pairs. Show the user the two contacts side by side with search_contacts and ask which one to keep before calling it; never decide that two contacts are one yourself.',
@@ -411,6 +480,12 @@ export function buildServer(backend, options = {}) {
411
480
  inputSchema: write.UpdateDocumentLinesInput.shape,
412
481
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
413
482
  }, async (args) => guard(() => write.updateDocumentLines(backend, args)));
483
+ register('attach_document_file', {
484
+ title: 'Record the file of a document',
485
+ description: 'Records a file as the piece of a document: the PDF of the supplier\'s invoice a purchase invoice was created from, the photograph of a receipt, the copy a customer was sent. This server stores no bytes: the file is stored first, in the storage of the installation or wherever its application keeps files, and this records where, with its name, type, size and SHA-256. The same file recorded again on the same document is returned (replayed: true), not recorded twice. A piece goes on its document, never on the entry the document posted; a document of any state takes one. Nothing is booked. Next: list_document_files reads them back.',
486
+ inputSchema: write.AttachDocumentFileInput.shape,
487
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
488
+ }, async (args) => guard(() => write.attachDocumentFile(backend, args)));
414
489
  register('post_document', {
415
490
  title: 'Post a document to the ledger',
416
491
  description: 'Books a draft document: base lines, VAT lines from the tax configuration, and the customer or supplier counterpart, numbered and posted. A posted entry is never edited; a mistake is undone by cancel_document, which puts the document back to draft only where its country allows it and nothing has left, and issues a credit note otherwise. The database decides whether you may, from the company\'s agent_posting (get_company) and this session\'s choice: in review, the default, only once a person has approved this draft as it stands (ekwo doc approve, or the web application) — refused with approval_required otherwise, and again if the draft changed after the approval; in autopilot, directly, within your rights; autopilot_forbidden where the session asked for autopilot and the company allows review only. Either way the posting is recorded on the audit trail as an agent\'s, with the mode and the session. dry_run: true is always allowed and is what to show the user before they approve.' +
@@ -508,7 +583,7 @@ export function buildServer(backend, options = {}) {
508
583
  }, async (args) => guard(() => write.settleFromStatement(backend, args)));
509
584
  register('create_bank_account', {
510
585
  title: 'Add a bank account',
511
- description: "Registers a bank account of the company from its identifier — an IBAN, an ABA routing number and an account number, a sort code and an account number, whatever the banks of the company's country use; the pack of the country says which, and it is checked — and wires it to the bank journal and to the ledger account behind it — both of which the country template has already chosen, so neither has to be given. Running it twice with the same identifier returns the one that exists rather than creating a second; a name another account already carries is refused (bank_account_exists), so ask the user for a label when a company has several accounts. The schema's create_bank_account() does the work, the same function a web application calls. Do this once per account: until a company has one, an invoice carries no account to pay into and record_payment can only book on the journal's default account.",
586
+ description: "Registers a bank account of the company from its identifier — an IBAN, an ABA routing number and an account number, a sort code and an account number, whatever the banks of the company's country use; the pack of the country says which, and it is checked — and wires it to the bank journal and to the ledger account behind it — both of which the country template has already chosen, so neither has to be given. Its bank, where the user gives it, is bank_scheme and bank_identifier in any scheme of bank_identifier_schemes (bic, aba, sort-code, bsb, ifsc…), checked by its scheme. Running it twice with the same identifier returns the one that exists rather than creating a second; a name another account already carries is refused (bank_account_exists), so ask the user for a label when a company has several accounts. The schema's create_bank_account() does the work, the same function a web application calls. Do this once per account: until a company has one, an invoice carries no account to pay into and record_payment can only book on the journal's default account.",
512
587
  inputSchema: write.CreateBankAccountInput.shape,
513
588
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
514
589
  }, async (args) => guard(() => write.createBankAccount(backend, args)));
@@ -538,13 +613,13 @@ export function buildServer(backend, options = {}) {
538
613
  }, async (args) => guard(() => write.importBankStatement(backend, args)));
539
614
  register('create_company', {
540
615
  title: 'Create a company',
541
- description: 'Creates a company on a country pack: its chart of accounts, its journals and its taxes are copied in, its first financial year is opened on the month that country opens one on, and you become its first member. Creating a company is an instance-level act — it needs an instance administrator, and being one is not the same as being on anybody\u2019s books. Ask the user for the country rather than guessing: the wrong answer is a whole chart of accounts.',
616
+ description: 'Creates a company on a country pack: its chart of accounts, its journals and its taxes are copied in, its first financial year is opened on the month that country opens one on, and you become its first member. Creating a company is an instance-level act — it needs an instance administrator, and being one is not the same as being on anybody\u2019s books. Ask the user for the country rather than guessing: the wrong answer is a whole chart of accounts — and for the territory, where the pack requires one (a state of the United States).',
542
617
  inputSchema: write.CreateCompanyInput.shape,
543
618
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
544
619
  }, async (args) => guard(() => write.createCompany(backend, args)));
545
620
  register('update_company_profile', {
546
621
  title: 'Change the company itself',
547
- description: 'Changes what a company says about itself on its documents: the names it goes by, its address and identifiers, its logo and the colour, logo side and typeface of its invoice PDF, whether its invoices print the late payment mention of its country, the pattern of its document numbers, its stated capital, its activity code and the bank account customers are asked to pay into — and agent_posting, how agents post its documents, which you only ever make stricter. Only the fields you name change. It touches nothing in the ledger, and it needs company.write — the owner preset, not the accountant one.',
622
+ description: 'Changes what a company says about itself on its documents: the names it goes by, its address and identifiers, the territory it is established in below its country, its logo and the colour, logo side and typeface of its invoice PDF, whether its invoices print the late payment mention of its country, the pattern of its document numbers, its stated capital, its activity code and the bank account customers are asked to pay into — and agent_posting, how agents post its documents, which you only ever make stricter. Only the fields you name change. It touches nothing in the ledger, and it needs company.write — the owner preset, not the accountant one.',
548
623
  inputSchema: write.UpdateCompanyProfileInput.shape,
549
624
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
550
625
  }, async (args) => guard(() => write.updateCompanyProfile(backend, args)));
@@ -634,9 +709,15 @@ export function buildServer(backend, options = {}) {
634
709
  inputSchema: write.OpeningBalanceInput.shape,
635
710
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
636
711
  }, async (args) => guard(() => write.openingBalance(backend, args)));
712
+ register('set_closing_rate', {
713
+ title: 'Set a closing exchange rate',
714
+ description: 'Records the rate a company closes a foreign currency at on a day — units of that currency for one unit of the company\'s — which close_fiscal_year reads on the last day of the year for every currency still open there (fx_closing_rate_missing otherwise). The same currency and day again replaces the rate. Needs year_end.close. Never pick a rate yourself: use the one the user gives, or the series they name, and say where it came from in source.',
715
+ inputSchema: write.SetClosingRateInput.shape,
716
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
717
+ }, async (args) => guard(() => write.setClosingRate(backend, args)));
637
718
  register('close_fiscal_year', {
638
719
  title: 'Close a fiscal year',
639
- description: 'Closes a year: the result of the year leaves the income statement the way the country model says — straight to retained earnings, into a current-year result account, or through the appropriation accounts — every income and expense account goes back to zero, and the year stops accepting entries. The close can be undone with reopen_fiscal_year; final_close in the answer says whether the country also requires a final close, which cannot, and by when. Refused while the year holds a draft entry, while an earlier year with entries is open, or when a later year is already closed. It never writes what a general meeting decides to do with the result. Always ask the user before calling it.',
720
+ description: 'Closes a year: what is still open in a foreign currency is first stated at the closing rate of its last day (set_closing_rate; currency_revaluation shows it) on the accounts the country pack names, and reversed the next day; then the result of the year leaves the income statement the way the country model says — straight to retained earnings, into a current-year result account, or through the appropriation accounts — every income and expense account goes back to zero, and the year stops accepting entries. The close can be undone with reopen_fiscal_year; final_close in the answer says whether the country also requires a final close, which cannot, and by when. Refused while the year holds a draft entry, while an earlier year with entries is open, or when a later year is already closed. It never writes what a general meeting decides to do with the result. Always ask the user before calling it.',
640
721
  inputSchema: write.CloseFiscalYearInput.shape,
641
722
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
642
723
  }, async (args) => guard(() => write.closeFiscalYear(backend, args)));