@ekwo-ai/mcp 0.24.1 → 0.25.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.
Files changed (44) hide show
  1. package/README.md +34 -3
  2. package/dist/backend.d.ts.map +1 -1
  3. package/dist/backend.js +3 -0
  4. package/dist/backend.js.map +1 -1
  5. package/dist/config.d.ts +9 -0
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js +17 -0
  8. package/dist/config.js.map +1 -1
  9. package/dist/index.d.ts +4 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +3 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/server.d.ts +25 -2
  14. package/dist/server.d.ts.map +1 -1
  15. package/dist/server.js +138 -98
  16. package/dist/server.js.map +1 -1
  17. package/dist/start.d.ts.map +1 -1
  18. package/dist/start.js +8 -2
  19. package/dist/start.js.map +1 -1
  20. package/dist/stdio.d.ts +1 -1
  21. package/dist/stdio.d.ts.map +1 -1
  22. package/dist/stdio.js +3 -0
  23. package/dist/stdio.js.map +1 -1
  24. package/dist/tools/effect.d.ts +48 -0
  25. package/dist/tools/effect.d.ts.map +1 -0
  26. package/dist/tools/effect.js +42 -0
  27. package/dist/tools/effect.js.map +1 -0
  28. package/dist/tools/loading.d.ts +65 -0
  29. package/dist/tools/loading.d.ts.map +1 -0
  30. package/dist/tools/loading.js +119 -0
  31. package/dist/tools/loading.js.map +1 -0
  32. package/dist/tools/modules.d.ts +12 -1
  33. package/dist/tools/modules.d.ts.map +1 -1
  34. package/dist/tools/modules.js +55 -42
  35. package/dist/tools/modules.js.map +1 -1
  36. package/dist/tools/read.d.ts +15 -16
  37. package/dist/tools/read.d.ts.map +1 -1
  38. package/dist/tools/read.js +14 -166
  39. package/dist/tools/read.js.map +1 -1
  40. package/dist/tools/write.d.ts +7 -6
  41. package/dist/tools/write.d.ts.map +1 -1
  42. package/dist/tools/write.js +35 -81
  43. package/dist/tools/write.js.map +1 -1
  44. package/package.json +5 -5
package/dist/server.js CHANGED
@@ -15,6 +15,8 @@ import { columns, relayableCloudOffer, relayableInvitation } from '@ekwo-ai/core
15
15
  import * as read from './tools/read.js';
16
16
  import * as write from './tools/write.js';
17
17
  import { toolsetsFor } from './tools/modules.js';
18
+ import { TOOL_EFFECTS, annotationsFor } from './tools/effect.js';
19
+ import { ON_DEMAND_INSTRUCTIONS, loadTools, searchTools, startOnDemand } from './tools/loading.js';
18
20
  export const SERVER_NAME = '@ekwo-ai/mcp';
19
21
  /**
20
22
  * What this server tells a client it is, in the MCP handshake.
@@ -24,7 +26,7 @@ export const SERVER_NAME = '@ekwo-ai/mcp';
24
26
  * `tests/mcp/surface.test.ts` keeps the two equal, so a release that bumps one
25
27
  * and forgets the other fails the build.
26
28
  */
27
- export const SERVER_VERSION = '0.24.1';
29
+ export const SERVER_VERSION = '0.25.0';
28
30
  /** Everything a tool returns: JSON, pretty-printed, as one text block. */
29
31
  function ok(payload) {
30
32
  return { content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }] };
@@ -64,7 +66,7 @@ async function guard(run) {
64
66
  export const INSTRUCTIONS = [
65
67
  '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.',
66
68
  '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).',
67
- '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, 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.',
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, 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.',
68
70
  '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.',
69
71
  '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.',
70
72
  ].join('\n\n');
@@ -74,6 +76,7 @@ export function instructionsFor(options = {}) {
74
76
  INSTRUCTIONS,
75
77
  ...(options.inviteToRegister === true ? [relayableInvitation()] : []),
76
78
  ...(options.offerCloud === true ? [relayableCloudOffer()] : []),
79
+ ...(options.tools === 'on_demand' ? [ON_DEMAND_INSTRUCTIONS] : []),
77
80
  ].join('\n\n');
78
81
  }
79
82
  /**
@@ -92,16 +95,19 @@ function titled(config) {
92
95
  return { ...config, annotations: { ...config.annotations, title: config.title } };
93
96
  }
94
97
  /**
95
- * A server on which no tool can be registered without `annotations.title`.
96
- *
97
- * Done once, on the server, rather than at each of the registrations below:
98
- * a tool added later goes through the same door, and `tests/mcp/surface.test.ts`
99
- * reads the list a client sees to make sure none slipped past.
98
+ * The one door every tool of this server goes through: it copies the title
99
+ * into the annotations and keeps each registered tool by name, for
100
+ * `search_tools` and `load_tools`. Done once rather than at each
101
+ * registration below, so a tool added later goes through it too, and
102
+ * `tests/mcp/surface.test.ts` reads the list a client sees to make sure none
103
+ * slipped past.
100
104
  */
101
- function withTitledTools(server) {
102
- const register = server.registerTool.bind(server);
103
- server.registerTool = ((name, config, callback) => register(name, titled(config), callback));
104
- return server;
105
+ function toolRegistrar(server, registered) {
106
+ return (name, config, cb) => {
107
+ const tool = server.registerTool(name, titled(config), cb);
108
+ registered.set(name, tool);
109
+ return tool;
110
+ };
105
111
  }
106
112
  /**
107
113
  * The sentence the posting tools end with: how this session posts, as the
@@ -119,51 +125,59 @@ export function sessionPosting(backend) {
119
125
  }
120
126
  }
121
127
  export function buildServer(backend, options = {}) {
122
- const server = withTitledTools(new McpServer({ name: SERVER_NAME, version: SERVER_VERSION }, { instructions: instructionsFor(options) }));
128
+ const server = new McpServer({ name: SERVER_NAME, version: SERVER_VERSION }, { instructions: instructionsFor(options) });
129
+ const tools = new Map();
130
+ const register = toolRegistrar(server, tools);
123
131
  // -------------------------------------------------------------------- read
124
- server.registerTool('list_companies', {
132
+ register('list_companies', {
125
133
  title: 'List companies',
126
134
  description: 'The companies of this installation that you are a member of, with your role on each. Start here: every other tool needs a company_id. Returns id, name, country, currency and your role. It does not list companies you were never invited to — those are invisible, not hidden. Next: get_company on the one the user means.',
127
135
  inputSchema: read.ListCompaniesInput.shape,
128
136
  annotations: { readOnlyHint: true, openWorldHint: false },
129
137
  }, async () => guard(() => read.listCompanies(backend)));
130
- server.registerTool('get_company', {
138
+ register('get_company', {
131
139
  title: 'Company settings',
132
140
  description: 'Everything needed before booking in a company: its financial years and whether they are closed, its lock dates, its journals, and the accounts that play the receivable, payable, suspense and retained-earnings roles. Read this before creating a document if you do not already know the journals and the lock dates. Next: list_accounts and the ekwo://companies/{companyId}/taxes resource give the codes a document line names.',
133
141
  inputSchema: read.GetCompanyInput.shape,
134
142
  annotations: { readOnlyHint: true, openWorldHint: false },
135
143
  }, async (args) => guard(() => read.getCompany(backend, args)));
136
- server.registerTool('list_accounts', {
144
+ register('list_accounts', {
137
145
  title: 'Chart of accounts',
138
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.',
139
147
  inputSchema: read.ListAccountsInput.shape,
140
148
  annotations: { readOnlyHint: true, openWorldHint: false },
141
149
  }, async (args) => guard(() => read.listAccounts(backend, args)));
142
- server.registerTool('search_contacts', {
150
+ register('search_contacts', {
143
151
  title: 'Find a contact',
144
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.',
145
153
  inputSchema: read.SearchContactsInput.shape,
146
154
  annotations: { readOnlyHint: true, openWorldHint: false },
147
155
  }, async (args) => guard(() => read.searchContacts(backend, args)));
148
- server.registerTool('suggest_duplicate_contacts', {
156
+ register('suggest_duplicate_contacts', {
149
157
  title: 'Find the contacts that are probably one party',
150
- description: 'The active contacts of a company that are probably one party — two spellings of one customer, two imports of one supplier — strongest first, one row per contact to absorb. The rows that share a keep_id are one group (the contacts a chain of pairs joins); each names the contact to keep (the one of the group more ledger lines and documents name, then the older), the one to absorb, proposed_name (the simplest name the group carries — the fewest words carried by contacts outside the group, then the fewest words — a proposal for the kept contact, written only if the user wants it), a score from 0 to 1, the kinds of evidence (vat_number, registration_number, account: the same number or bank account, score 1; name: the words of the shorter name in the longer, each weighed by how few contacts carry it, so that a shared trade, place or legal form alone is never a pair; 0.950 for the same name, 0.900 otherwise, 0.600 when the shorter name agrees with several contacts) and the evidence in sentences. Two contacts with different VAT or registration numbers, a contact and its own parent, and inactive or merged contacts are never proposed. It writes nothing: show the user both contacts and call merge_contacts only on a pair they confirm, with the contact they choose to keep.',
158
+ description: 'The active contacts of a company that are probably one party — two spellings of one customer, two imports of one supplier — strongest first, one row per contact to absorb. The rows that share a keep_id are one group (the contacts a chain of pairs joins); each names the contact to keep (the one of the group more ledger lines and documents name, then the older), the one to absorb, proposed_name (the simplest name the group carries — the fewest words carried by contacts outside the group, then the fewest words — a proposal for the kept contact, written only if the user wants it), a score from 0 to 1, the kinds of evidence (vat_number, registration_number, account: the same number or bank account, score 1; name: the words of the shorter name in the longer, each weighed by how few contacts carry it, so that a shared trade, place or legal form alone is never a pair; 0.950 for the same name, 0.900 otherwise, 0.600 when the shorter name agrees with several contacts) and the evidence in sentences. Two contacts with different VAT or registration numbers, a contact and its own parent, and inactive or merged contacts are never proposed. contact_types keeps the proposals among the contacts of those types — customer, supplier and both for the parties of the books — and every contact is read when it is absent. It writes nothing: show the user both contacts and call merge_contacts only on a pair they confirm, with the contact they choose to keep.',
151
159
  inputSchema: read.SuggestDuplicateContactsInput.shape,
152
160
  annotations: { readOnlyHint: true, openWorldHint: false },
153
161
  }, async (args) => guard(() => read.suggestDuplicateContacts(backend, args)));
154
- server.registerTool('list_documents', {
162
+ register('contact_statement', {
163
+ 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.',
165
+ inputSchema: read.ContactStatementInput.shape,
166
+ annotations: { readOnlyHint: true, openWorldHint: false },
167
+ }, async (args) => guard(() => read.contactStatement(backend, args)));
168
+ register('list_documents', {
155
169
  title: 'List documents',
156
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. Returns headers and totals, not lines; use get_document for those.',
157
171
  inputSchema: read.ListDocumentsInput.shape,
158
172
  annotations: { readOnlyHint: true, openWorldHint: false },
159
173
  }, async (args) => guard(() => read.listDocuments(backend, args)));
160
- server.registerTool('get_document', {
174
+ register('get_document', {
161
175
  title: 'Read a document',
162
176
  description: 'One document with its lines, the account and tax of each line, the legal mentions its country requires on it, that country\'s payment and e-invoicing rules, and — when it has been posted — the ledger entry it produced with every ledger line. Use it to check what a document will book, what it did book, and what has to be printed on it.',
163
177
  inputSchema: read.GetDocumentInput.shape,
164
178
  annotations: { readOnlyHint: true, openWorldHint: false },
165
179
  }, async (args) => guard(() => read.getDocument(backend, args)));
166
- server.registerTool('render_invoice_pdf', {
180
+ register('render_invoice_pdf', {
167
181
  title: 'The PDF of an invoice',
168
182
  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.',
169
183
  inputSchema: read.RenderInvoicePdfInput.shape,
@@ -186,206 +200,206 @@ export function buildServer(backend, options = {}) {
186
200
  return fail(error);
187
201
  }
188
202
  });
189
- server.registerTool('get_preferences', {
203
+ register('get_preferences', {
190
204
  title: 'What this user prefers',
191
205
  description: 'The signed-in user\u2019s own preferences — which company an interface opens on, the language they read labels in, their timezone and how they like a date and a number written — and the language chain to read labels with: theirs, then the company\u2019s, then the country pack\u2019s. Every one of them may be null, and null means "take the next answer in the chain" rather than a default this installation picked.',
192
206
  inputSchema: read.GetPreferencesInput.shape,
193
207
  annotations: { readOnlyHint: true, openWorldHint: false },
194
208
  }, async (args) => guard(() => read.getPreferences(backend, args)));
195
- server.registerTool('list_api_keys', {
209
+ register('list_api_keys', {
196
210
  title: 'Machine keys of a company',
197
211
  description: 'The keys a company has issued to machines, what each one may do, how it posts a document (posting_mode, review or autopilot, fixed when it was issued), when it was last used and whether it is still live. Only somebody who manages members sees them, and no secret is in here: a key is shown once, when it is issued.',
198
212
  inputSchema: read.ListApiKeysInput.shape,
199
213
  annotations: { readOnlyHint: true, openWorldHint: false },
200
214
  }, async (args) => guard(() => read.listApiKeys(backend, args)));
201
- server.registerTool('list_invitations', {
215
+ register('list_invitations', {
202
216
  title: 'Invitations into a company',
203
217
  description: 'The people invited into a company and not yet on its books, with the preset and the capabilities each was invited with, and whether the invitation is still pending, expired, accepted or withdrawn. Only somebody who manages members sees them. The token is never in here: it is shown once, when the invitation is issued.',
204
218
  inputSchema: read.ListInvitationsInput.shape,
205
219
  annotations: { readOnlyHint: true, openWorldHint: false },
206
220
  }, async (args) => guard(() => read.listInvitations(backend, args)));
207
- server.registerTool('list_shares', {
221
+ register('list_shares', {
208
222
  title: 'Public links onto documents',
209
223
  description: 'The links a company has published onto its own sales documents, with how many times each was opened and when it was last opened. No token is in here: a link is shown once, when it is made. Use it to answer "did the customer open the invoice?" and to find the link to withdraw.',
210
224
  inputSchema: read.ListSharesInput.shape,
211
225
  annotations: { readOnlyHint: true, openWorldHint: false },
212
226
  }, async (args) => guard(() => read.listShares(backend, args)));
213
- server.registerTool('list_bank_transactions', {
227
+ register('list_bank_transactions', {
214
228
  title: 'Bank transactions',
215
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.',
216
230
  inputSchema: read.ListBankTransactionsInput.shape,
217
231
  annotations: { readOnlyHint: true, openWorldHint: false },
218
232
  }, async (args) => guard(() => read.listBankTransactions(backend, args)));
219
- server.registerTool('trial_balance', {
233
+ register('trial_balance', {
220
234
  title: 'Trial balance',
221
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.',
222
236
  inputSchema: read.TrialBalanceInput.shape,
223
237
  annotations: { readOnlyHint: true, openWorldHint: false },
224
238
  }, async (args) => guard(() => read.trialBalance(backend, args)));
225
- server.registerTool('general_ledger', {
239
+ register('general_ledger', {
226
240
  title: 'General ledger',
227
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.',
228
242
  inputSchema: read.GeneralLedgerInput.shape,
229
243
  annotations: { readOnlyHint: true, openWorldHint: false },
230
244
  }, async (args) => guard(() => read.generalLedger(backend, args)));
231
- server.registerTool('journal_book', {
245
+ register('journal_book', {
232
246
  title: 'Journal book',
233
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.',
234
248
  inputSchema: read.JournalBookInput.shape,
235
249
  annotations: { readOnlyHint: true, openWorldHint: false },
236
250
  }, async (args) => guard(() => read.journalBook(backend, args)));
237
- server.registerTool('suggest_line_contacts', {
251
+ register('suggest_line_contacts', {
238
252
  title: 'Suggest the contact of lines that name nobody',
239
253
  description: 'For each open line on a receivable or payable account that names no contact — typically the open items of books imported line by line — the contacts it could be, best first, each with a score, the method (a learned motif, the number of a document of the company quoted in the label, the description or the reference of the entry, the words of a contact\'s name), the evidence in a sentence, and alternatives: how many contacts the same evidence reached. More than 1 is a question for the user, not an answer. It writes nothing; set_line_contact names a line once the user has chosen.',
240
254
  inputSchema: read.SuggestLineContactsInput.shape,
241
255
  annotations: { readOnlyHint: true, openWorldHint: false },
242
256
  }, async (args) => guard(() => read.suggestLineContacts(backend, args)));
243
- server.registerTool('suggest_item_combinations', {
257
+ register('suggest_item_combinations', {
244
258
  title: 'Suggest which open items settle each other',
245
259
  description: 'For each open line on a receivable or payable account of one counterparty (a branch and its parent are one party), the lines of the other side on the same account that could settle it, up to three proposals a line: an exact pair, several lines that add up to it to the cent ("this payment settles these three invoices", or one invoice paid in instalments), and — only when nothing is exact — a pair or several lines within the company\'s difference tolerance, with the difference (the line less the total). Each proposal has a stable proposal_id, a kind (pair, combination), the lines and a sentence. It writes nothing: show the user, then reconcile_many for a difference of 0.00, or reconcile_with_difference once they have seen the difference and chosen a reason.',
246
260
  inputSchema: read.SuggestItemCombinationsInput.shape,
247
261
  annotations: { readOnlyHint: true, openWorldHint: false },
248
262
  }, async (args) => guard(() => read.suggestItemCombinations(backend, args)));
249
- server.registerTool('matching_difference_options', {
263
+ register('matching_difference_options', {
250
264
  title: 'The reasons and the tolerance for booking a difference',
251
265
  description: 'What reconcile_with_difference accepts for this company: the largest difference it books (in units of the currency and as an amount) and the reasons — rounding, exchange_difference — each with the account the pack gives, the side it answers (charge, income, either) and whether it is available. No pack carries a role for bank charges or payment discounts, so they are not reasons.',
252
266
  inputSchema: read.MatchingDifferenceOptionsInput.shape,
253
267
  annotations: { readOnlyHint: true, openWorldHint: false },
254
268
  }, async (args) => guard(() => read.matchingDifferenceOptions(backend, args)));
255
- server.registerTool('aged_balance', {
269
+ register('aged_balance', {
256
270
  title: 'Aged balance',
257
271
  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.',
258
272
  inputSchema: read.AgedBalanceInput.shape,
259
273
  annotations: { readOnlyHint: true, openWorldHint: false },
260
274
  }, async (args) => guard(() => read.agedBalance(backend, args)));
261
- server.registerTool('vat_return', {
275
+ register('vat_return', {
262
276
  title: 'VAT return',
263
277
  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.',
264
278
  inputSchema: read.VatReturnInput.shape,
265
279
  annotations: { readOnlyHint: true, openWorldHint: false },
266
280
  }, async (args) => guard(() => read.vatReturn(backend, args)));
267
- server.registerTool('instalment_plan', {
281
+ register('instalment_plan', {
268
282
  title: 'VAT instalments of a period',
269
283
  description: 'The payments on account of a declaration that the VAT scheme a company recorded asks for during its period — a simplified scheme pays part of the year\'s tax before filing the annual return — with what was due, what was paid and what is outstanding. The schedule, the percentages and the box of the previous year they are read on are country pack data; no country rule lives in this tool. It reads; it pays nothing.',
270
284
  inputSchema: read.InstalmentPlanInput.shape,
271
285
  annotations: { readOnlyHint: true, openWorldHint: false },
272
286
  }, async (args) => guard(() => read.instalmentPlan(backend, args)));
273
- server.registerTool('ec_sales_list', {
287
+ register('ec_sales_list', {
274
288
  title: 'Recapitulative statement of European Union supplies',
275
289
  description: 'Who, in another Member State, was supplied without VAT over a period, and for how much: one line per customer VAT number and per nature — goods, services — read from the treatment of the tax on each sale line, with credit notes deducted. The totals tie back to the European Union boxes of vat_return for the same period. A line that carries an issue cannot be filed as it stands, most often because the customer has no VAT number recorded: say so rather than leaving it out of the answer. Name a report_code to have the period checked against the cadence this company files that statement on — it has one of its own, and it is rarely the cadence of the return. No country rule lives in this tool. It prepares a statement; it files nothing.',
276
290
  inputSchema: read.EcSalesListInput.shape,
277
291
  annotations: { readOnlyHint: true, openWorldHint: false },
278
292
  }, async (args) => guard(() => read.ecSalesList(backend, args)));
279
- server.registerTool('portfolio_upcoming_filings', {
293
+ register('portfolio_upcoming_filings', {
280
294
  title: 'Returns falling due, across your companies',
281
295
  description: 'What falls due between two dates in every company you may read the declarations of — the question a firm asks of all the books it keeps, and the one a person asks of the single company they run. "Portfolio" is meant as an accounting firm means it — its client portfolio — and is nothing but that: the companies you hold filings.read on, worked out at each call, never a list anybody maintains. Every one of them is in the answer, including a company whose country pack names no deadline, which is listed without a date and says so; a company left out would be indistinguishable from one that was never looked at. No country rule lives in this tool. It reads a calendar; it prepares and files nothing.',
282
296
  inputSchema: read.PortfolioUpcomingFilingsInput.shape,
283
297
  annotations: { readOnlyHint: true, openWorldHint: false },
284
298
  }, async (args) => guard(() => read.portfolioUpcomingFilings(backend, args)));
285
- server.registerTool('portfolio_filings_touched_since', {
299
+ register('portfolio_filings_touched_since', {
286
300
  title: 'Declared periods that moved, across your companies',
287
301
  description: 'Which declarations, across your portfolio — every company you may read the declarations of, which for an accounting firm is its clients — had entries posted into their period after they were filed — with the company named, how many entries, and how many of the filed figures now disagree. A period stays open after its return has gone, on purpose; this is what keeps a late entry from going unnoticed. Companies with nothing to report are named too, with how many filed declarations were examined. It reads; whether a corrective is owed is for whoever keeps the books.',
288
302
  inputSchema: read.PortfolioFilingsTouchedSinceInput.shape,
289
303
  annotations: { readOnlyHint: true, openWorldHint: false },
290
304
  }, async (args) => guard(() => read.portfolioFilingsTouchedSince(backend, args)));
291
- server.registerTool('list_statements', {
305
+ register('list_statements', {
292
306
  title: 'List financial statements',
293
307
  description: 'The schemes this company can be presented on: those of its country and of its chart of accounts, plus the generic framework by account type that fits any chart. Ask this before financial_statement rather than guessing a code.',
294
308
  inputSchema: read.ListStatementsInput.shape,
295
309
  annotations: { readOnlyHint: true, openWorldHint: false },
296
310
  }, async (args) => guard(() => read.listStatements(backend, args)));
297
- server.registerTool('financial_statement', {
311
+ register('financial_statement', {
298
312
  title: 'Financial statement',
299
313
  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.',
300
314
  inputSchema: read.FinancialStatementInput.shape,
301
315
  annotations: { readOnlyHint: true, openWorldHint: false },
302
316
  }, async (args) => guard(() => read.financialStatement(backend, args)));
303
- server.registerTool('financial_analysis', {
317
+ register('financial_analysis', {
304
318
  title: 'Financial analysis',
305
319
  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.",
306
320
  inputSchema: read.FinancialAnalysisInput.shape,
307
321
  annotations: { readOnlyHint: true, openWorldHint: false },
308
322
  }, async (args) => guard(() => read.financialAnalysis(backend, args)));
309
- server.registerTool('list_analytic_axes', {
323
+ register('list_analytic_axes', {
310
324
  title: 'Analytic axes',
311
325
  description: 'The analytic axes of a company — a cost centre, a project, a site, a business unit — each with its values, which may nest under a parent_id, and required_on: none, or expense, income or result — the lines that must carry the axis whole, or posting refuses them (analytic_axis_required). A value says what a cost, a revenue or a fixed asset is for; a product says what was sold or bought. A retired value takes no new share. Read it before analytic_report, which takes an axis by its code.',
312
326
  inputSchema: read.ListAnalyticAxesInput.shape,
313
327
  annotations: { readOnlyHint: true, openWorldHint: false },
314
328
  }, async (args) => guard(() => read.listAnalyticAxes(backend, args)));
315
- server.registerTool('analytic_report', {
329
+ register('analytic_report', {
316
330
  title: 'Result by analytic value',
317
331
  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.',
318
332
  inputSchema: read.AnalyticReportInput.shape,
319
333
  annotations: { readOnlyHint: true, openWorldHint: false },
320
334
  }, async (args) => guard(() => read.analyticReport(backend, args)));
321
- server.registerTool('generate_fec', {
335
+ register('generate_fec', {
322
336
  title: 'Generate the French FEC',
323
337
  description: 'The Fichier des Écritures Comptables for a period: the eighteen columns of the arrêté du 29 juillet 2013, as text, with the checks a tax inspector applies first (mandatory fields, one side per line, entries balancing) and the filename the format wants. The file comes back in the answer; writing it to disk is the caller\'s business.',
324
338
  inputSchema: read.GenerateFecInput.shape,
325
339
  annotations: { readOnlyHint: true, openWorldHint: false },
326
340
  }, async (args) => guard(() => read.generateFec(backend, args)));
327
- server.registerTool('describe_pack', {
341
+ register('describe_pack', {
328
342
  title: 'Where a country pack comes from',
329
343
  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.",
330
344
  inputSchema: read.DescribePackInput.shape,
331
345
  annotations: { readOnlyHint: true, openWorldHint: false },
332
346
  }, async (args) => guard(() => read.describePack(backend, args)));
333
- server.registerTool('status', {
347
+ register('status', {
334
348
  title: 'Installation status',
335
349
  description: 'The schema version, the instance this is, how this server is connected and as whom, whether this session posts in review or in autopilot, and the companies you can see with the mode a posting meets in each. Use it first when something does not add up — an empty company list usually means the user was never invited rather than that the books are empty.',
336
350
  inputSchema: read.StatusInput.shape,
337
351
  annotations: { readOnlyHint: true, openWorldHint: false },
338
352
  }, async () => guard(() => read.status(backend, { inviteToRegister: options.inviteToRegister === true })));
339
- server.registerTool('read_audit_log', {
353
+ register('read_audit_log', {
340
354
  title: 'Audit trail',
341
355
  description: "Who changed what, and when. Every change to the configuration and reference data of a company — the chart of accounts, the journals, the taxes and the accounts they post to, the bank accounts, the contacts, the products, the financial years, the members and their roles, the country pack version — and every act that changes a state: a document posted or cancelled, an entry posted or reversed, a payment booked, matched or unmatched, a financial year closed or reopened. Filter by table, by natural key, by user, by act, or by date range. The ledger itself is not in here: a posted entry is immutable and is corrected by a reversal, so what is recorded is the act of posting and never the lines. Read-only, and there is no tool that writes it: the trail is append-only and even the operator cannot edit a row.",
342
356
  inputSchema: read.ReadAuditLogInput.shape,
343
357
  annotations: { readOnlyHint: true, openWorldHint: false },
344
358
  }, async (args) => guard(() => read.readAuditLog(backend, args)));
345
359
  // ------------------------------------------------------------------- write
346
- server.registerTool('search_products', {
360
+ register('search_products', {
347
361
  title: 'Find a product',
348
362
  description: 'The catalogue of a company: what it sells and buys, with the code, the unit, the price, the account each books to and the tax each carries. Search it before writing a line by hand — a product fills in the text, the price, the account and the tax, and keeps two invoices for the same thing consistent. Retired products are left out unless you ask for them.',
349
363
  inputSchema: read.SearchProductsInput.shape,
350
364
  annotations: { readOnlyHint: true, openWorldHint: false },
351
365
  }, async (args) => guard(() => read.searchProducts(backend, args)));
352
- server.registerTool('create_product', {
366
+ register('create_product', {
353
367
  title: 'Add a product',
354
368
  description: 'Adds an item to the catalogue: a code unique in the company, a name, a unit, a price, and optionally the account and the tax a sale or a purchase of it carries. It changes nothing already booked — a product is what a new line is filled in from, never a rule applied to the past. Search first: a second code for the same thing is how a price list stops being one.',
355
369
  inputSchema: write.CreateProductInput.shape,
356
370
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
357
371
  }, async (args) => guard(() => write.createProduct(backend, args)));
358
- server.registerTool('update_product', {
372
+ register('update_product', {
359
373
  title: 'Change a product',
360
374
  description: "Changes a catalogue row — its name, price, unit, account, tax — or retires it with active: false. Documents already written keep the text, the price and the account they were invoiced with; an invoice is a statement about the day it was raised, and this tool cannot rewrite one. Retiring is the way to withdraw something: deleting is refused while any line still points at it.",
361
375
  inputSchema: write.UpdateProductInput.shape,
362
376
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
363
377
  }, async (args) => guard(() => write.updateProduct(backend, args)));
364
- server.registerTool('create_contact', {
378
+ register('create_contact', {
365
379
  title: 'Create a contact',
366
380
  description: 'Adds a customer, supplier or other third party to a company. Search first: a duplicate contact splits a customer account in two and the aged balance stops making sense. payment_terms_days drives the due date a posted invoice gets when none is given. Next: create_document with the id it returns.',
367
381
  inputSchema: write.CreateContactInput.shape,
368
382
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
369
383
  }, async (args) => guard(() => write.createContact(backend, args)));
370
- server.registerTool('merge_contacts', {
384
+ register('merge_contacts', {
371
385
  title: 'Merge two contacts of one company',
372
386
  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.',
373
387
  inputSchema: write.MergeContactsInput.shape,
374
388
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
375
389
  }, async (args) => guard(() => write.mergeContacts(backend, args)));
376
- server.registerTool('create_document', {
390
+ register('create_document', {
377
391
  title: 'Create a draft invoice',
378
392
  description: 'Creates a draft invoice, credit note or quote with its lines, and returns it with the totals the database computed — never with totals you supplied. A line may name a product_code, which fills in its text, price, unit, account and tax; anything the line carries wins over that. With no product and no account_code, the account falls back to the company default and then to its country model. A tax is different: a line with none is booked as a base with no VAT box, which is not the same as 0 %. Nothing is in the ledger yet. Next: show the draft to the user; update_document_lines changes it, and post_document books it once they agree.',
379
393
  inputSchema: write.CreateDocumentInput.shape,
380
394
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
381
395
  }, async (args) => guard(() => write.createDocument(backend, args)));
382
- server.registerTool('update_document_lines', {
396
+ register('update_document_lines', {
383
397
  title: 'Replace the lines of a draft',
384
398
  description: 'Replaces every line of a draft document with the set you give, and returns the document with its recomputed totals. Lines take product_code the same way create_document does. Drafts only: a posted document is never edited; cancel_document undoes it with a credit note.',
385
399
  inputSchema: write.UpdateDocumentLinesInput.shape,
386
400
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
387
401
  }, async (args) => guard(() => write.updateDocumentLines(backend, args)));
388
- server.registerTool('post_document', {
402
+ register('post_document', {
389
403
  title: 'Post a document to the ledger',
390
404
  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.' +
391
405
  sessionPosting(backend) +
@@ -393,207 +407,207 @@ export function buildServer(backend, options = {}) {
393
407
  inputSchema: write.PostDocumentInput.shape,
394
408
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
395
409
  }, async (args) => guard(() => write.postDocument(backend, args)));
396
- server.registerTool('cancel_document', {
410
+ register('cancel_document', {
397
411
  title: 'Undo a posted invoice',
398
412
  description: "Undoes a posted sale or purchase invoice in one call, the one way its country and its facts allow, and says which in undone_by. 'draft': the country's posted_edit_policy lets a posted document go back to draft and nothing about this one has left — never sent nor on Peppol, not paid, not declared, its period open and, where numbering is gapless, its number the last one drawn; its entry is taken away, its number given back, and it is a draft to correct and post again. 'credit_note' otherwise, with the reason in why: its credit note — the same lines, taxes, accounts, contact, currency and rate — is issued naming it, posted and matched against it, and the invoice is cancelled, payment state reversed; the invoice keeps its number and its entry. Tell the user which it was. A date, or credit_note: true, asks for the credit note outright. Dated on the invoice's booking day unless you give a date; refused by name when that period is locked or closed (reversal_date_needed), and then you ask the user for a date rather than choosing one. Refused for a draft, a credit note, an invoice already cancelled or credited, and one that is paid in part or in full — the payment is unmatched first with unreconcile, and only when the user says so. Where you post in review, the credit note is a posting nobody approved, so that way is refused (approval_required) and the user cancels it themselves. Ask the user before calling it." + sessionPosting(backend),
399
413
  inputSchema: write.CancelDocumentInput.shape,
400
414
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
401
415
  }, async (args) => guard(() => write.undoDocument(backend, args)));
402
- server.registerTool('reverse_entry', {
416
+ register('reverse_entry', {
403
417
  title: 'Reverse a posted entry',
404
418
  description: "Undoes a posted entry in one call: writes its mirror in the same journal — every line on the other side — naming it, posts it under the next number, and matches the two. The original keeps its number and its lines. Dated on the original's day unless you give a date; refused by name when that period is locked or closed (reversal_date_needed), and then you ask the user for a date rather than choosing one. Refused for an entry a document wrote (use cancel_document), the entries of a close (reopen_fiscal_year), an opening, the entry of a payment, a bank transaction, a module or a matching, an entry already reversed or that is itself a reversal, and a matched entry — unmatch it first with unreconcile, and only when the user says so. Ask the user before calling it.",
405
419
  inputSchema: write.ReverseEntryInput.shape,
406
420
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
407
421
  }, async (args) => guard(() => write.reverseEntry(backend, args)));
408
- server.registerTool('record_payment', {
422
+ register('record_payment', {
409
423
  title: 'Record a payment',
410
424
  description: 'Records money in or out, books it (bank against the customer or supplier account) and, unless you say otherwise, matches it against that contact\'s oldest open invoices up to the amount paid. Matching is what makes an invoice count as paid. The entry it produces cannot be unposted, though the matching can be undone with unreconcile.',
411
425
  inputSchema: write.RecordPaymentInput.shape,
412
426
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
413
427
  }, async (args) => guard(() => write.recordPayment(backend, args)));
414
- server.registerTool('reconcile', {
428
+ register('reconcile', {
415
429
  title: 'Match two ledger lines',
416
430
  description: 'Matches a debit line against a credit line on the same reconcilable account, for an amount, defaulting to the smaller of the two open amounts. Use it to settle an invoice against a payment by hand. Matching changes no account and stays possible after a period is locked.',
417
431
  inputSchema: write.ReconcileInput.shape,
418
432
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
419
433
  }, async (args) => guard(() => write.reconcile(backend, args)));
420
- server.registerTool('unreconcile', {
434
+ register('unreconcile', {
421
435
  title: 'Undo a matching',
422
436
  description: 'Removes one matching, putting the residual back on both lines. The entries themselves are untouched. It is what cancel_document and reverse_entry ask for first when what they would undo is matched.',
423
437
  inputSchema: write.UnreconcileInput.shape,
424
438
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
425
439
  }, async (args) => guard(() => write.unreconcile(backend, args)));
426
- server.registerTool('set_line_contact', {
440
+ register('set_line_contact', {
427
441
  title: 'Name the contact of a ledger line',
428
442
  description: 'Names the contact of an open line on a receivable or payable account that names nobody — the open items of books imported line by line — once, from nothing to a contact of the same company, and learns the label as a motif of that contact for the next suggestion. Refused by name: unknown_line, line_not_posted, line_has_contact (a posted counterparty is corrected by reversing the entry), line_matched (unmatch it first, and only when the user says so), line_not_third_party, unknown_contact. Changes no amount, account or tax box. Show the user the candidates of suggest_line_contacts and ask which one before calling it; never pick one yourself.',
429
443
  inputSchema: write.SetLineContactInput.shape,
430
444
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
431
445
  }, async (args) => guard(() => write.setLineContact(backend, args)));
432
- server.registerTool('leave_line_unnamed', {
446
+ register('leave_line_unnamed', {
433
447
  title: 'Leave a ledger line without a contact',
434
448
  description: 'Records that an open line on a receivable or payable account names nobody on purpose — a cash difference, a one-off refund — with the user\'s reason: suggest_line_contacts no longer proposes it. The line does not move and stays an open item. Refused by name: unknown_line, not_allowed, reason_required, reason_too_long, line_not_posted, line_has_contact, line_not_third_party, line_left_unnamed. Ask the user before calling it.',
435
449
  inputSchema: write.LeaveLineUnnamedInput.shape,
436
450
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
437
451
  }, async (args) => guard(() => write.leaveLineUnnamed(backend, args)));
438
- server.registerTool('undo_leave_line_unnamed', {
452
+ register('undo_leave_line_unnamed', {
439
453
  title: 'Take back leaving a line without a contact',
440
454
  description: 'Takes back leave_line_unnamed: the line is proposed a contact again. Refused by name: unknown_line, not_allowed, line_not_left_unnamed.',
441
455
  inputSchema: write.UndoLeaveLineUnnamedInput.shape,
442
456
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
443
457
  }, async (args) => guard(() => write.undoLeaveLineUnnamed(backend, args)));
444
- server.registerTool('reconcile_many', {
458
+ register('reconcile_many', {
445
459
  title: 'Match several ledger lines together',
446
460
  description: 'Matches several lines together in one call — one payment against several invoices, one invoice against several instalments — when their open debits and credits are equal to the cent: posted lines of one company, one reconcilable account, one counterparty (a line naming nobody is attributed by the matching), in the company\'s currency. Paired oldest first through reconcile, under one letter. Refused by name, and never settled in part: reconcile_unbalanced gives the difference. Show the user the lines and ask before calling it.',
447
461
  inputSchema: write.ReconcileManyInput.shape,
448
462
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
449
463
  }, async (args) => guard(() => write.reconcileMany(backend, args)));
450
- server.registerTool('reconcile_with_difference', {
464
+ register('reconcile_with_difference', {
451
465
  title: 'Match ledger lines and book a small difference',
452
466
  description: 'Matches the same set of lines as reconcile_many when their totals differ by no more than the company\'s tolerance: posts an entry that books the difference on the same account and counterparty against the account the pack gives for the reason (matching_difference_options: rounding, exchange_difference), then matches everything under one letter. Refused by name: difference_above_tolerance, no_difference, unknown_difference_reason, no_account_for_reason, and every refusal of reconcile_many. The entry is posted; unreconcile of the matching of the difference line takes it back. Show the user the difference and the account, and let them choose the reason, before calling it.',
453
467
  inputSchema: write.ReconcileWithDifferenceInput.shape,
454
468
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
455
469
  }, async (args) => guard(() => write.reconcileWithDifference(backend, args)));
456
- server.registerTool('settle_from_statement', {
470
+ register('settle_from_statement', {
457
471
  title: 'Settle a bank statement line',
458
472
  description: 'Books a pending statement line as the payment it is and matches it against the documents or open items named, in one entry: the bank, the customer or supplier account, and the extra lines the money is net of — the fee a payment provider kept from a payout, the charges of a bank, each on the account and with the tax the user names. A payout of 97.00 for an invoice of 100.00 settles the invoice in full with an extra line of 3.00 on a fee account. amounts says how much settles each item; left out, oldest first. The line has to balance to the cent (settlement_unbalanced otherwise, with the difference). Extra lines alone settle a bank charge. One counterparty per line. The entry cannot be unposted. Ask the user before calling it, and for the fee account and its tax.',
459
473
  inputSchema: write.SettleFromStatementInput.shape,
460
474
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
461
475
  }, async (args) => guard(() => write.settleFromStatement(backend, args)));
462
- server.registerTool('create_bank_account', {
476
+ register('create_bank_account', {
463
477
  title: 'Add a bank account',
464
- 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. 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.",
478
+ 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.",
465
479
  inputSchema: write.CreateBankAccountInput.shape,
466
480
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
467
481
  }, async (args) => guard(() => write.createBankAccount(backend, args)));
468
- server.registerTool('list_bank_accounts', {
482
+ register('list_bank_accounts', {
469
483
  title: 'Bank accounts',
470
484
  description: 'The bank accounts of a company, with their identifier and the scheme it is written in, the journal they book through and the ledger account behind each. Read it before recording a payment on a particular account, and to find out whether the company has one at all.',
471
485
  inputSchema: read.ListBankAccountsInput.shape,
472
486
  annotations: { readOnlyHint: true, openWorldHint: false },
473
487
  }, async (args) => guard(() => read.listBankAccounts(backend, args)));
474
- server.registerTool('create_bank_transaction', {
488
+ register('create_bank_transaction', {
475
489
  title: 'Add a bank transaction',
476
490
  description: 'Records one statement line by hand, for an installation without a bank feed. `amount` is signed: positive is money in. It books nothing — the line waits as pending until a payment is recorded.',
477
491
  inputSchema: write.CreateBankTransactionInput.shape,
478
492
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
479
493
  }, async (args) => guard(() => write.createBankTransaction(backend, args)));
480
- server.registerTool('import_bank_statement', {
494
+ register('import_bank_statement', {
481
495
  title: 'Import a bank statement',
482
496
  description: 'Reads a bank statement file and writes its statements and lines. `format` says what the file is — `camt.053` (the ISO 20022 XML statement), `coda` or `cfonb120`, which are the ones this server reads today — and `content` is the file as text. It is never guessed from the content. It books nothing: every line waits as pending, to be settled afterwards. Safe to repeat: the same file imported twice creates nothing the second time, and a statement overlapping an earlier one imports only the new lines. Refused by name, with nothing written: an account the company does not have (create it first with create_bank_account — an import never creates one), a statement whose opening balance plus lines is not its closing balance, a line in another currency. Signalled in `warnings`, not refused: an opening balance that is not the previous closing one, which means a statement is missing.',
483
497
  inputSchema: write.ImportBankStatementInput.shape,
484
498
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
485
499
  }, async (args) => guard(() => write.importBankStatement(backend, args)));
486
- server.registerTool('create_company', {
500
+ register('create_company', {
487
501
  title: 'Create a company',
488
502
  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.',
489
503
  inputSchema: write.CreateCompanyInput.shape,
490
504
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
491
505
  }, async (args) => guard(() => write.createCompany(backend, args)));
492
- server.registerTool('update_company_profile', {
506
+ register('update_company_profile', {
493
507
  title: 'Change the company itself',
494
- 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, 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.',
508
+ 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.',
495
509
  inputSchema: write.UpdateCompanyProfileInput.shape,
496
510
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
497
511
  }, async (args) => guard(() => write.updateCompanyProfile(backend, args)));
498
- server.registerTool('set_number_prefix', {
512
+ register('set_number_prefix', {
499
513
  title: 'Change what a journal prints in its numbers',
500
514
  description: "Sets the prefix one journal prints in place of {CODE} in the numbers it draws — FAC instead of SAL, for instance — or puts its code back with null. The journal keeps its code and its counter: the series goes on at the next number. A prefix another journal of the company already prints is refused. The pattern around it (year, width) is the company's number_format in update_company_profile. Needs settings.write.",
501
515
  inputSchema: write.SetNumberPrefixInput.shape,
502
516
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
503
517
  }, async (args) => guard(() => write.setNumberPrefix(backend, args)));
504
- server.registerTool('set_preferences', {
518
+ register('set_preferences', {
505
519
  title: 'Change what this user prefers',
506
520
  description: 'Writes the signed-in user\u2019s own preferences and nobody else\u2019s. Only the fields you name change: leave one out and it is untouched, pass null and it is cleared, which puts that question back to the company and then to the country pack. It changes nothing in the books.',
507
521
  inputSchema: write.SetPreferencesInput.shape,
508
522
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
509
523
  }, async (args) => guard(() => write.setPreferences(backend, args)));
510
- server.registerTool('invite_member', {
524
+ register('invite_member', {
511
525
  title: 'Invite somebody into a company',
512
526
  description: 'Invites an address into a company with a preset — viewer reads, client reads and hands pieces over, accountant keeps the books, owner also administers — and any capability granted on top of it. It returns a token once and stores only its hash, so hand the token to the person you invited: they accept it themselves, signed in with that address. It does not send an e-mail, and it does not create an account. Inviting the same address again withdraws the invitation that was pending.',
513
527
  inputSchema: write.InviteMemberInput.shape,
514
528
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
515
529
  }, async (args) => guard(() => write.inviteMember(backend, args)));
516
- server.registerTool('create_api_key', {
530
+ register('create_api_key', {
517
531
  title: 'Issue a key to a machine',
518
532
  description: 'Issues a key so a script — a nightly import, a till, a bank feed — can work in one company without a person signing in. It carries an explicit list of capabilities and nothing else, it can never reach another company, and it cannot hold a capability you do not hold yourself — at issuance and at every use: if you lose a capability or leave the company, the key loses it too. Its posting_mode is fixed now and never raised afterwards: review by default, autopilot only when the user asks for it in so many words. The secret comes back once and is stored only as a hash: show it to the user and say it cannot be read back. Prefer this to sharing anybody\u2019s password, and never suggest a service key.',
519
533
  inputSchema: write.CreateApiKeyInput.shape,
520
534
  // Destructive: a key reaches the books without a person, until it is withdrawn.
521
535
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
522
536
  }, async (args) => guard(() => write.createApiKey(backend, args)));
523
- server.registerTool('revoke_api_key', {
537
+ register('revoke_api_key', {
524
538
  title: 'Withdraw a machine key',
525
539
  description: 'Stops a key working, now and for good. There is no un-withdraw: a secret that has been out of the building is issued again rather than brought back. Whatever the machine was doing with it stops, so say so before calling it.',
526
540
  inputSchema: write.RevokeApiKeyInput.shape,
527
541
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
528
542
  }, async (args) => guard(() => write.revokeApiKey(backend, args)));
529
- server.registerTool('revoke_invitation', {
543
+ register('revoke_invitation', {
530
544
  title: 'Withdraw an invitation',
531
545
  description: 'Withdraws an invitation that has not been accepted, so its token stops working. An invitation that has already become a membership is refused: a member is taken out with remove_member.',
532
546
  inputSchema: write.RevokeInvitationInput.shape,
533
547
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
534
548
  }, async (args) => guard(() => write.revokeInvitation(backend, args)));
535
- server.registerTool('remove_member', {
549
+ register('remove_member', {
536
550
  title: 'Take somebody out of a company',
537
551
  description: 'Removes a member from a company, now: they stop reading and writing its books. Needs members.manage, except to leave a company yourself. The last owner of a company is refused, themself included; make somebody else owner with set_member_role first. Their pending invitations are not touched. Say who is being removed before calling it.',
538
552
  inputSchema: write.RemoveMemberInput.shape,
539
553
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
540
554
  }, async (args) => guard(() => write.removeMember(backend, args)));
541
- server.registerTool('set_member_role', {
555
+ register('set_member_role', {
542
556
  title: 'Move a member to another preset',
543
557
  description: 'Changes the preset of a member of a company — viewer reads, client reads and hands pieces over, accountant keeps the books, owner also administers. Needs members.manage. The capabilities granted or revoked on that member so far are cleared, and the ones you pass are granted on top of the new preset, the way an invitation writes a new member. The last owner of a company cannot be demoted: promote the successor first.',
544
558
  inputSchema: write.SetMemberRoleInput.shape,
545
559
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
546
560
  }, async (args) => guard(() => write.setMemberRole(backend, args)));
547
- server.registerTool('share_document', {
561
+ register('share_document', {
548
562
  title: 'Publish a document behind a link',
549
563
  description: 'Publishes a posted sales invoice, credit note or quote behind a link the customer opens without an account and without a password: the token in the url is the whole secret. It returns that token once and stores only its hash, so give the url to the customer and say it cannot be read back. The page shows the document as it was sent and what is still owed on it today, so the link stays worth opening after a payment. A purchase document is refused — it is a third party\u2019s own document — and so is a draft. A link is never edited: to change when it expires, withdraw it and make another.',
550
564
  inputSchema: write.ShareDocumentInput.shape,
551
565
  // Destructive: the document leaves the ledger for whoever holds the link.
552
566
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
553
567
  }, async (args) => guard(() => write.shareDocument(backend, args)));
554
- server.registerTool('revoke_share', {
568
+ register('revoke_share', {
555
569
  title: 'Withdraw a published link',
556
570
  description: 'Stops a link working, now and for good. Whoever holds it sees exactly what they would see for a link that never existed. There is no un-withdraw: a secret that has been out of the building is issued again rather than brought back, so say so before calling it.',
557
571
  inputSchema: write.RevokeShareInput.shape,
558
572
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
559
573
  }, async (args) => guard(() => write.revokeShare(backend, args)));
560
- server.registerTool('pin_accounts', {
574
+ register('pin_accounts', {
561
575
  title: 'Pin accounts to the working chart',
562
576
  description: 'Adds accounts to the working chart of a company, so list_accounts offers them whether or not anything has been booked on them. Pass pinned: false to take one back out. Pinning is display and nothing else: an unpinned account may still be booked on, and a pinned one is still hidden once it is deprecated.',
563
577
  inputSchema: write.PinAccountsInput.shape,
564
578
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
565
579
  }, async (args) => guard(() => write.pinAccounts(backend, args)));
566
- server.registerTool('lock_period', {
580
+ register('lock_period', {
567
581
  title: 'Lock a period',
568
582
  description: 'Moves the accounting lock date, the VAT lock date, or both. After this, nothing can be booked, changed or deleted on or before that date — including corrections you may want later. Only an owner of the company may do it. Always ask the user first, and never lock a period you have just posted into without being told to.',
569
583
  inputSchema: write.LockPeriodInput.shape,
570
584
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
571
585
  }, async (args) => guard(() => write.lockPeriod(backend, args)));
572
- server.registerTool('import_books', {
586
+ register('import_books', {
573
587
  title: 'Import books from another system',
574
588
  description: write.IMPORT_BOOKS_DESCRIPTION,
575
589
  inputSchema: write.ImportBooksInput.shape,
576
590
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
577
591
  }, async (args) => guard(() => write.importBooksTool(backend, args)));
578
- server.registerTool('opening_balance', {
592
+ register('opening_balance', {
579
593
  title: 'Import an opening balance',
580
594
  description: 'Turns the trial balance of whatever kept the books before into the opening entry of a fiscal year, on the opening journal, dated on its first day — or on opening_date, the day inside the year the books were taken over. Lines are {account_code, debit, credit}; total debit must equal total credit. Balance-sheet accounts only, unless allow_result_accounts is set, which is for taking books over in the middle of a year. items are the invoices and credit notes still open that day, each posted as a document with its number, payment reference and due date, so a bank statement finds it; the items of an account replace its line and must add up to it. A year holds one opening: a second call is refused rather than added to.',
581
595
  inputSchema: write.OpeningBalanceInput.shape,
582
596
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
583
597
  }, async (args) => guard(() => write.openingBalance(backend, args)));
584
- server.registerTool('close_fiscal_year', {
598
+ register('close_fiscal_year', {
585
599
  title: 'Close a fiscal year',
586
600
  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.',
587
601
  inputSchema: write.CloseFiscalYearInput.shape,
588
602
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
589
603
  }, async (args) => guard(() => write.closeFiscalYear(backend, args)));
590
- server.registerTool('reopen_fiscal_year', {
604
+ register('reopen_fiscal_year', {
591
605
  title: 'Re-open a closed fiscal year',
592
606
  description: 'Undoes an ordinary close, to correct the year: the entries it wrote are reversed, never deleted, and the year accepts entries again. Entries already posted in later years do not prevent it and are not touched — they read this year from the ledger, so closing it again carries the corrected result to them. Refused for a year under a final close (fiscal_year_finally_closed), for everybody, and while a later year is closed (later_fiscal_year_closed): reopen that one first. Always ask the user before calling it.',
593
607
  inputSchema: write.ReopenFiscalYearInput.shape,
594
608
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
595
609
  }, async (args) => guard(() => write.reopenFiscalYear(backend, args)));
596
- server.registerTool('close_fiscal_year_finally', {
610
+ register('close_fiscal_year_finally', {
597
611
  title: 'Close a fiscal year for good',
598
612
  description: 'The final close: a year already closed is frozen, and from then on nobody can reopen it or change it — not the owner, not an accountant, not the operator. Refused on an open year (fiscal_year_not_closed) and while a closed year before it is not finally closed. Whether the country requires it, and by when, is final_close in the answer of close_fiscal_year. Irreversible: call it only when the user has asked for this specific year to be closed for good.',
599
613
  inputSchema: write.CloseFiscalYearFinallyInput.shape,
@@ -739,16 +753,17 @@ export function buildServer(backend, options = {}) {
739
753
  // with its tools, under the same prefix.
740
754
  for (const toolset of toolsetsFor(options.modules ?? [])) {
741
755
  for (const tool of toolset.tools) {
742
- server.registerTool(`${toolset.prefix}_${tool.verb}`, {
756
+ register(`${toolset.prefix}_${tool.verb}`, {
743
757
  title: tool.title,
744
758
  description: tool.description,
745
759
  inputSchema: tool.input.shape,
746
- // A module tool that is not read-only writes the books — an asset
747
- // recorded, a depreciation booked, budget lines replaced — and says
748
- // so, the way the socle's writes above do.
749
- annotations: tool.readOnly
750
- ? { readOnlyHint: true, openWorldHint: false }
751
- : { readOnlyHint: false, destructiveHint: true, openWorldHint: false },
760
+ // Said by the module, the way the socle's tools say it above: a
761
+ // card or a note is added, a depreciation booked or a file sent
762
+ // destroys. See packages/mcp/TOOL_DESIGN.md.
763
+ annotations: annotationsFor(tool.effect, {
764
+ ...(tool.idempotent === undefined ? {} : { idempotent: tool.idempotent }),
765
+ ...(tool.openWorld === undefined ? {} : { openWorld: tool.openWorld }),
766
+ }),
752
767
  }, async (args) => guard(() => tool.run(backend, args, {
753
768
  ...(options.einvoiceTransport === undefined ? {} : { einvoiceTransport: options.einvoiceTransport }),
754
769
  ...(options.fiscalSystem === undefined ? {} : { fiscalSystem: options.fiscalSystem }),
@@ -764,6 +779,31 @@ export function buildServer(backend, options = {}) {
764
779
  }));
765
780
  }
766
781
  }
782
+ // ------------------------------------------------------------- on demand
783
+ //
784
+ // Registered last, so that they see every tool above. A session that asked
785
+ // for all of them never sees these two.
786
+ if (options.tools === 'on_demand') {
787
+ register('search_tools', {
788
+ title: 'Search tools',
789
+ description: 'Finds the tools of this server by what they do: give a word or two of the task — "fixed asset", "contract", "bank statement", "budget" — and get the matching tools, best first, each with its title, the first sentence of its description, whether it reads, adds or destroys (effect), and whether it is loaded in this session. Without a query, every tool. It changes nothing; load_tools adds the ones you need.',
790
+ inputSchema: {
791
+ query: z.string().max(200).optional().describe('Words of the task. Left out, every tool is listed.'),
792
+ effect: z.enum(TOOL_EFFECTS).optional().describe('Only the tools that read, that add, or that are destructive.'),
793
+ limit: z.number().int().min(1).max(200).optional().describe('At most this many, 20 by default.'),
794
+ },
795
+ annotations: { readOnlyHint: true, openWorldHint: false },
796
+ }, async (args) => guard(async () => searchTools(tools, args.query, args.effect, args.limit ?? 20)));
797
+ register('load_tools', {
798
+ title: 'Load tools',
799
+ description: 'Adds the tools you name to this session, by the names search_tools gave. The tool list changes and your client is told so; call them as any other. Answers which were loaded, which were already there and which this server does not have. It changes the tools you see, never the books, and loading a tool gives it no right the database would refuse.',
800
+ inputSchema: {
801
+ names: z.array(z.string().min(1).max(64)).min(1).max(50).describe('The names of the tools to add, as search_tools lists them.'),
802
+ },
803
+ annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false },
804
+ }, async (args) => guard(async () => loadTools(tools, args.names)));
805
+ startOnDemand(tools);
806
+ }
767
807
  return server;
768
808
  }
769
809
  //# sourceMappingURL=server.js.map