bimp-mcp 0.2.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.
@@ -0,0 +1,342 @@
1
+ export const PROMPT_TEXTS = {};
2
+ const PROMPTS = {
3
+ bimp_erp_context: {
4
+ def: {
5
+ name: "bimp_erp_context",
6
+ description: "System context about BIMP ERP: entity structure, relationships, and Ukrainian terminology mapping",
7
+ },
8
+ text: `# BIMP ERP System Context
9
+
10
+ ## Entity Structure and Relationships
11
+
12
+ BIMP is a Ukrainian cloud ERP for SMBs. Key entities and their API names:
13
+
14
+ ### Core Entities
15
+ - **Nomenclature** (nomenclature) — products and services catalog. Has groups (nomenclature-group), units of measurement, and parent/child modifications.
16
+ - **Counterparty** (counterparty) — customers and suppliers. Can be marked as isCustomer, isSupplier, or both. Has addresses, EDRPOU (tax ID), contacts.
17
+ - **Specification** (specification) — bill of materials (BOM). Links a nomenclature item to its composition (materials and quantities needed to produce it).
18
+
19
+ ### Sales Flow
20
+ - **Order** (invoiceForCustomerPayment) — customer order with status workflow
21
+ - **Sales Invoice / Realization** (salesInvoice) — goods shipment document, contains products array
22
+ - **Customer Payment** (customerPayment) — payment from customer
23
+ - **Customer Return** (customer-inventories-return) — return of goods from customer
24
+ - **Refund** (refundToCustomer) — money refund to customer
25
+
26
+ ### Procurement Flow
27
+ - **Supplier Invoice** (invoiceForSupplierPayment) — invoice for payment to supplier
28
+ - **Purchase Invoice** (purchaseInvoice) — incoming goods document, contains products array
29
+
30
+ ### Production Flow
31
+ - **Production Order** (production-order) — manufacturing order with products to produce and materials to consume
32
+ - **Production Assembly** (production-assembly) — assembly/production execution record
33
+
34
+ ### Inventory
35
+ - **Inventory** (inventory) — stock balances per warehouse (GET endpoints with page/cursor pagination)
36
+ - **Movement** (movementOfInventories) — transfer between warehouses
37
+ - **Write-off** (writeOffOfInventories) — inventory write-off/disposal
38
+
39
+ ### Finance
40
+ - **Currency** (currency) — currencies with codes
41
+ - **Bank Account** (bankAccounts) — bank accounts with types
42
+ - **Cash Registry** (cashRegistry) — cash registers
43
+ - **VAT** (vat) — VAT rates
44
+ - **Chart of Accounts** (chartOfAccount) — accounting chart
45
+ - **Expense Items** (expenseItems) — expense categories
46
+ - **Other Expenses** (otherExpenses) — general expense documents
47
+ - **Expense Request** (expenseRequest) — request for funds with approval workflow
48
+
49
+ ### Organization
50
+ - **Organization** (organization) — legal entities
51
+ - **Warehouse** (warehouse) — storage locations
52
+ - **Employee** (employee) — staff members with positions and statuses
53
+ - **Contract** (contract) — contracts with counterparties, types, and statuses
54
+ - **Project** (project) — project tracking
55
+ - **Price List** (priceList) — price lists with per-product prices
56
+
57
+ ## Ukrainian Terminology Mapping
58
+
59
+ | Ukrainian | English | API Entity |
60
+ |-----------|---------|------------|
61
+ | Номенклатура | Nomenclature/Product | nomenclature |
62
+ | Група номенклатури | Product Group | nomenclature-group |
63
+ | Контрагент | Counterparty | counterparty |
64
+ | Специфікація | Specification/BOM | specification |
65
+ | Замовлення покупця | Customer Order | invoiceForCustomerPayment |
66
+ | Реалізація | Sales Invoice | salesInvoice |
67
+ | Оплата покупця | Customer Payment | customerPayment |
68
+ | Повернення | Customer Return | customer-inventories-return |
69
+ | Повернення коштів | Refund | refundToCustomer |
70
+ | Прихідна накладна | Purchase Invoice | purchaseInvoice |
71
+ | Рахунок постачальнику | Supplier Invoice | invoiceForSupplierPayment |
72
+ | Виробничий наказ | Production Order | production-order |
73
+ | Збірка | Production Assembly | production-assembly |
74
+ | Склад | Warehouse | warehouse |
75
+ | Залишки | Inventory/Stock | inventory |
76
+ | Переміщення | Movement | movementOfInventories |
77
+ | Списання | Write-off | writeOffOfInventories |
78
+ | Валюта | Currency | currency |
79
+ | Прайс-лист | Price List | priceList |
80
+ | Співробітник | Employee | employee |
81
+ | Договір | Contract | contract |
82
+
83
+ ## Important API Behavior
84
+
85
+ 1. **readList returns INCOMPLETE data** for many entities. For example, salesInvoice.readList does NOT include products, warehouse, or VAT. Use enrich=true in bimp_fetch_all or call the read endpoint separately.
86
+ 2. **No total count** in paginated responses. The only way to know you've reached the end is when data.length < requested count.
87
+ 3. **Max page size is 100** for offset/count pagination.
88
+ 4. **Three pagination types**: offset/count (most POST endpoints), cursor (inventory), page/pageSize (inventory GET).
89
+
90
+ ## Planning & Accounting Fields (Extended API)
91
+
92
+ Some nomenclature fields are only available via the undocumented \`/org2/nomenclatures/\` endpoints (plural):
93
+
94
+ | Field | Description |
95
+ |-------|-------------|
96
+ | minStock | Minimum stock level |
97
+ | maxStock | Maximum stock level |
98
+ | speedOfDemand | Demand rate |
99
+ | insuranceReserve | Safety stock |
100
+ | deliveryTerm | Delivery time in days |
101
+ | plannedCost | Planned cost |
102
+
103
+ These fields are NOT available in the standard \`/org2/nomenclature/\` (singular) API.
104
+ Use the \`bimp_nomenclatures_read\`, \`bimp_nomenclatures_upsert\`, and \`bimp_nomenclatures_readList\` tools to access them.`,
105
+ },
106
+ bimp_data_analysis: {
107
+ def: {
108
+ name: "bimp_data_analysis",
109
+ description: "Guide for analyzing BIMP ERP data: how to fetch complete datasets, handle pagination, and work with incomplete readList data",
110
+ },
111
+ text: `# BIMP Data Analysis Guide
112
+
113
+ ## Fetching Complete Data
114
+
115
+ 1. **Always use bimp_fetch_all** to collect all records — it handles pagination automatically.
116
+ 2. **Use enrich=true** when you need full details. Many readList endpoints return summary data:
117
+ - salesInvoice.readList: missing products, warehouse, VAT
118
+ - specification.readList: missing composition, cost
119
+ - purchaseInvoice.readList: missing products, warehouse
120
+ - production-order.readList: missing products, materials
121
+ - customerPayment.readList: missing paymentDetails
122
+ 3. **Filter by period** using the periodable field: \`filters: { periodable: ["2025-01-01T00:00:00.000Z", "2025-12-31T23:59:59.000Z"] }\`
123
+ 4. **No total count** — to count records, you must fetch all of them.
124
+
125
+ ## Analysis Patterns
126
+
127
+ ### Sales Dynamics
128
+ 1. Fetch all sales invoices for a period: bimp_fetch_all with tool=bimp_salesInvoice_readList, filters={ periodable: [...] }, enrich=true
129
+ 2. Each enriched salesInvoice contains: products array with quantities and prices, counterparty, currency, date
130
+ 3. Aggregate by date/counterparty/product as needed
131
+
132
+ ### Inventory Analysis
133
+ 1. Use bimp_inventory_readList (GET endpoint with page/pageSize pagination) for current stock
134
+ 2. Or use bimp_nomenclature_readStocks for stock per nomenclature
135
+ 3. Cross-reference with specifications to check material availability for production
136
+
137
+ ### Production Planning
138
+ 1. Fetch production orders: bimp_fetch_all with tool=bimp_production_order_readList, enrich=true
139
+ 2. Enriched orders contain products (what to produce) and materials (what to consume)
140
+ 3. Compare materials against inventory to identify shortages
141
+ 4. Fetch specifications for BOM details
142
+
143
+ ### Price Analysis
144
+ 1. Fetch all price lists: bimp_fetch_all with tool=bimp_priceList_readList
145
+ 2. Use bimp_priceList_readPrice with specific price list UUID and nomenclature UUID for individual prices`,
146
+ },
147
+ bimp_bulk_operations: {
148
+ def: {
149
+ name: "bimp_bulk_operations",
150
+ description: "How to perform bulk data operations: mass updates, batch imports, and large-scale data modifications",
151
+ },
152
+ text: `# BIMP Bulk Operations Guide
153
+
154
+ ## Mass Price Update
155
+ 1. Fetch all nomenclature: bimp_fetch_all tool=bimp_nomenclature_readList
156
+ 2. Calculate new prices
157
+ 3. Use bimp_priceList_updatePrice or bimp_bulk_update tool=bimp_priceList_updatePrice for each item
158
+
159
+ ## Mass Product Update
160
+ 1. Fetch products: bimp_fetch_all tool=bimp_nomenclature_readList with filters
161
+ 2. Filter/transform on your side
162
+ 3. Update: bimp_bulk_update tool=bimp_nomenclature_update items=[{uuid, ...fields}]
163
+
164
+ ## Batch Import
165
+ 1. Prepare data as array of objects
166
+ 2. For each entity type, use the create endpoint
167
+ 3. Example: bimp_bulk_update tool=bimp_nomenclature_create items=[{name, article, ...}]
168
+ Note: bulk_update works for create too — it just calls the tool for each item
169
+
170
+ ## Counterparty Bulk Edit
171
+ 1. Fetch: bimp_fetch_all tool=bimp_counterparty_readList
172
+ 2. Filter by type (isCustomer, isSupplier), status, or name
173
+ 3. Update: bimp_bulk_update tool=bimp_counterparty_insert (counterparty uses insert for updates)
174
+
175
+ ## Best Practices
176
+ - Always check the errors array after bulk operations
177
+ - Use lower concurrency (3-5) for create/update operations to avoid rate limiting
178
+ - Use higher concurrency (10-20) for read operations
179
+ - For very large datasets (1000+), consider processing in chunks and reporting progress
180
+ - Test with a small batch first before running on the full dataset`,
181
+ },
182
+ bimp_sales_workflow: {
183
+ def: {
184
+ name: "bimp_sales_workflow",
185
+ description: "Sales process workflow: from customer order to payment and returns",
186
+ },
187
+ text: `# BIMP Sales Workflow
188
+
189
+ ## Order to Realization to Payment
190
+
191
+ ### 1. Customer Order (invoiceForCustomerPayment)
192
+ - Create: bimp_invoiceForCustomerPayment_create
193
+ - Contains: counterparty, products, prices, currency
194
+ - Has status workflow: use bimp_invoiceForCustomerPayment_readStatuses for available statuses
195
+ - Update status: bimp_invoiceForCustomerPayment_updateStatus
196
+
197
+ ### 2. Sales Invoice / Realization (salesInvoice)
198
+ - Create: bimp_salesInvoice_create (link to order via orderUuid)
199
+ - Contains: products shipped, warehouse, VAT, price list
200
+ - Has EntryStatus: Draft (0) or Posted (1)
201
+ - List by order: bimp_salesInvoice_readList with filter orderUuid
202
+
203
+ ### 3. Customer Payment (customerPayment)
204
+ - Create: bimp_customerPayment_create (link to order)
205
+ - Contains: amount, currency, payment details
206
+ - Has status workflow: bimp_customerPayment_readStatuses
207
+ - Cancel: bimp_customerPayment_cancel
208
+ - Filter by order: bimp_customerPayment_readList with orders=[orderUuid]
209
+
210
+ ## Returns and Refunds
211
+
212
+ ### Customer Return (customer-inventories-return)
213
+ - Create: bimp_customer_inventories_return_create
214
+ - Returns products to inventory
215
+
216
+ ### Refund (refundToCustomer)
217
+ - Create: bimp_refundToCustomer_create
218
+ - Returns money to customer
219
+ - Has EntryStatus: Draft (0) or Posted (1)`,
220
+ },
221
+ bimp_production_workflow: {
222
+ def: {
223
+ name: "bimp_production_workflow",
224
+ description: "Production process: from specifications to manufacturing orders and inventory operations",
225
+ },
226
+ text: `# BIMP Production Workflow
227
+
228
+ ## Specification to Production Order to Assembly
229
+
230
+ ### 1. Specification (BOM)
231
+ - A specification defines what materials are needed to produce a product
232
+ - Read: bimp_specification_read (returns composition — array of materials with quantities)
233
+ - Create: bimp_specification_create (link to nomenclature)
234
+ - List: bimp_specification_readList (summary only — use enrich for composition details)
235
+
236
+ ### 2. Production Order
237
+ - Create: bimp_production_order_create
238
+ - Contains: products to produce and materials to consume
239
+ - Has status workflow: bimp_production_order_readStatuses
240
+ - Enriched read includes: products, materials, distributionType
241
+
242
+ ### 3. Production Assembly
243
+ - Records actual production execution
244
+ - Create: bimp_production_assembly_create
245
+ - Links to production order
246
+
247
+ ## Related Inventory Operations
248
+
249
+ ### Material Write-off (writeOffOfInventories)
250
+ - Write off materials consumed in production
251
+ - bimp_writeOffOfInventories_create
252
+
253
+ ### Inventory Movement (movementOfInventories)
254
+ - Transfer materials between warehouses for production
255
+ - bimp_movementOfInventories_create
256
+
257
+ ## Procurement of Materials
258
+ Before production, ensure materials are available:
259
+ 1. Create a supplier counterparty (if needed): bimp_counterparty_insert with isSupplier=true
260
+ 2. Create purchase invoice: bimp_purchaseInvoice_create with products, warehouse, counterparty
261
+ 3. Verify stock: bimp_nomenclature_readStocks to confirm material availability
262
+
263
+ ## Production Planning Pattern
264
+ 1. Fetch all specifications: bimp_fetch_all tool=bimp_specification_readList enrich=true
265
+ 2. Get current inventory: bimp_inventory_readList or bimp_nomenclature_readStocks
266
+ 3. Read planning fields: bimp_nomenclatures_read for minStock, maxStock, speedOfDemand
267
+ 4. Calculate what can be produced based on available materials vs BOM requirements
268
+ 5. Calculate deficit: max(0, minStock - currentStock) for each product
269
+ 6. Create production orders for feasible items`,
270
+ },
271
+ bimp_procurement_workflow: {
272
+ def: {
273
+ name: "bimp_procurement_workflow",
274
+ description: "Procurement process: supplier invoices, purchase documents, and supplier management",
275
+ },
276
+ text: `# BIMP Procurement Workflow
277
+
278
+ ## Supplier Invoice to Purchase Invoice
279
+
280
+ ### 1. Supplier Invoice (invoiceForSupplierPayment)
281
+ - Invoice received from supplier for payment
282
+ - Create: bimp_invoiceForSupplierPayment_create
283
+ - Has status workflow: bimp_invoiceForSupplierPayment_readStatuses
284
+
285
+ ### 2. Purchase Invoice (purchaseInvoice)
286
+ - Incoming goods document — records received products
287
+ - Create: bimp_purchaseInvoice_create
288
+ - Contains: products, warehouse, VAT, counterparty
289
+ - Filter by period: periodable filter
290
+ - Filter by org: organizations filter
291
+ - Flags: showAll (include archived/drafts), managerialAccounting, bookkeperAccounting
292
+
293
+ ## Related Entities
294
+
295
+ ### Counterparties (suppliers)
296
+ - Filter suppliers: bimp_counterparty_readList with types filter
297
+ - Create: bimp_counterparty_insert
298
+
299
+ ### Contracts
300
+ - Manage supplier contracts: bimp_contract_create / bimp_contract_update
301
+ - Link to counterparty, currency, price list
302
+ - Types: bimp_contract_readTypes
303
+ - Statuses: bimp_contract_readStatuses
304
+
305
+ ## Procurement Needs Analysis
306
+ 1. Read planning fields for each product: bimp_nomenclatures_read (minStock, maxStock, speedOfDemand, insuranceReserve, deliveryTerm)
307
+ 2. Get current inventory: bimp_fetch_all tool=bimp_inventory_readList or bimp_nomenclature_readStocks
308
+ 3. Calculate deficit per product: max(0, minStock - currentStock)
309
+ 4. Check specifications for required materials: bimp_fetch_all tool=bimp_specification_readList enrich=true
310
+ 5. Identify shortages based on BOM × planned production quantity
311
+ 6. Factor in deliveryTerm to prioritize urgent orders
312
+ 7. Create supplier invoices for needed materials`,
313
+ },
314
+ };
315
+ // Populate PROMPT_TEXTS for index.ts McpServer prompt registration
316
+ for (const [name, prompt] of Object.entries(PROMPTS)) {
317
+ PROMPT_TEXTS[name] = { description: prompt.def.description, text: prompt.text };
318
+ }
319
+ export function getPrompts() {
320
+ return Object.values(PROMPTS).map((p) => p.def);
321
+ }
322
+ export function handleGetPrompt(name, _args) {
323
+ const prompt = PROMPTS[name];
324
+ if (!prompt) {
325
+ return {
326
+ messages: [
327
+ {
328
+ role: "user",
329
+ content: { type: "text", text: `Unknown prompt: ${name}` },
330
+ },
331
+ ],
332
+ };
333
+ }
334
+ return {
335
+ messages: [
336
+ {
337
+ role: "user",
338
+ content: { type: "text", text: prompt.text },
339
+ },
340
+ ],
341
+ };
342
+ }
@@ -0,0 +1,44 @@
1
+ export interface ToolMetadata {
2
+ method: string;
3
+ path: string;
4
+ tag: string;
5
+ paginationType: "offset" | "cursor" | "page" | "none";
6
+ pathParams: string[];
7
+ }
8
+ export interface ToolDefinition {
9
+ name: string;
10
+ description: string;
11
+ inputSchema: {
12
+ type: "object";
13
+ properties: Record<string, unknown>;
14
+ required?: string[];
15
+ };
16
+ metadata: ToolMetadata;
17
+ }
18
+ export declare function pathToToolName(path: string): string;
19
+ interface OpenAPISpec {
20
+ paths: Record<string, Record<string, OpenAPIOperation>>;
21
+ [key: string]: unknown;
22
+ }
23
+ interface OpenAPIOperation {
24
+ tags?: string[];
25
+ description?: string;
26
+ requestBody?: {
27
+ content?: {
28
+ "application/json"?: {
29
+ schema?: Record<string, unknown>;
30
+ };
31
+ };
32
+ };
33
+ parameters?: Array<{
34
+ in: string;
35
+ name: string;
36
+ schema?: Record<string, unknown>;
37
+ required?: boolean;
38
+ description?: string;
39
+ }>;
40
+ responses?: Record<string, unknown>;
41
+ security?: Array<Record<string, unknown>>;
42
+ }
43
+ export declare function generateTools(spec: OpenAPISpec): ToolDefinition[];
44
+ export {};
@@ -0,0 +1,105 @@
1
+ const EXCLUDED_PATHS = [
2
+ "/org2/images/download",
3
+ "/org2/auth/api-login",
4
+ "/org2/auth/api-refresh",
5
+ "/org2/auth/api-selectCompany",
6
+ "/org2/auth/api-verifyCompanyAccess",
7
+ ];
8
+ const EXCLUDED_PATH_PATTERNS = [/\/integration\/zohoPeople\//];
9
+ export function pathToToolName(path) {
10
+ let cleaned = path.replace(/^\/org2\//, "");
11
+ cleaned = cleaned.replace(/\/api-/, "_");
12
+ cleaned = cleaned.replace(/\/\{[^}]+\}/g, "");
13
+ cleaned = cleaned.replace(/\//g, "_");
14
+ cleaned = cleaned.replace(/-/g, "_");
15
+ return `bimp_${cleaned}`;
16
+ }
17
+ function detectPaginationType(path, method, schema) {
18
+ if (path.includes("/cursor"))
19
+ return "cursor";
20
+ const properties = (schema.properties ?? {});
21
+ if ("pagination" in properties)
22
+ return "offset";
23
+ if (method === "GET") {
24
+ const params = Object.keys(properties);
25
+ if (params.includes("page") || params.includes("pageSize"))
26
+ return "page";
27
+ }
28
+ return "none";
29
+ }
30
+ function extractPathParams(path) {
31
+ const params = [];
32
+ const regex = /\{(\w+)\}/g;
33
+ let match;
34
+ while ((match = regex.exec(path)) !== null) {
35
+ params.push(match[1]);
36
+ }
37
+ return params;
38
+ }
39
+ export function generateTools(spec) {
40
+ const tools = [];
41
+ for (const [path, methods] of Object.entries(spec.paths)) {
42
+ if (EXCLUDED_PATHS.includes(path))
43
+ continue;
44
+ if (EXCLUDED_PATH_PATTERNS.some((p) => p.test(path)))
45
+ continue;
46
+ for (const [method, operation] of Object.entries(methods)) {
47
+ if (typeof operation !== "object" || operation === null)
48
+ continue;
49
+ const op = operation;
50
+ const name = pathToToolName(path);
51
+ const tag = op.tags?.[0] ?? "Unknown";
52
+ const description = op.description ?? `${method.toUpperCase()} ${path}`;
53
+ const pathParams = extractPathParams(path);
54
+ let properties = {};
55
+ let required = [];
56
+ if (method.toUpperCase() === "GET" || method.toUpperCase() === "DELETE") {
57
+ const params = (op.parameters ?? []).filter((p) => p.in === "query" && p.name !== "accept-language");
58
+ for (const param of params) {
59
+ properties[param.name] = param.schema ?? { type: "string" };
60
+ if (param.required)
61
+ required.push(param.name);
62
+ }
63
+ }
64
+ else {
65
+ const bodySchema = op.requestBody?.content?.["application/json"]?.schema;
66
+ if (bodySchema) {
67
+ properties = (bodySchema.properties ?? {});
68
+ required = (bodySchema.required ?? []);
69
+ }
70
+ }
71
+ for (const pp of pathParams) {
72
+ if (!(pp in properties)) {
73
+ properties[pp] = {
74
+ type: "string",
75
+ description: `Path parameter: ${pp}`,
76
+ };
77
+ }
78
+ if (!required.includes(pp)) {
79
+ required.push(pp);
80
+ }
81
+ }
82
+ const inputSchema = {
83
+ type: "object",
84
+ properties,
85
+ };
86
+ if (required.length > 0) {
87
+ inputSchema.required = required;
88
+ }
89
+ const paginationType = detectPaginationType(path, method.toUpperCase(), inputSchema);
90
+ tools.push({
91
+ name,
92
+ description,
93
+ inputSchema,
94
+ metadata: {
95
+ method: method.toUpperCase(),
96
+ path,
97
+ tag,
98
+ paginationType,
99
+ pathParams,
100
+ },
101
+ });
102
+ }
103
+ }
104
+ return tools;
105
+ }
@@ -0,0 +1,13 @@
1
+ import type { BimpClient } from "./client.js";
2
+ import type { ToolDefinition } from "./tool-generator.js";
3
+ export interface UtilityTool {
4
+ name: string;
5
+ description: string;
6
+ inputSchema: {
7
+ type: "object";
8
+ properties: Record<string, unknown>;
9
+ required?: string[];
10
+ };
11
+ handler: (params: Record<string, unknown>) => Promise<unknown>;
12
+ }
13
+ export declare function createUtilityTools(client: BimpClient, toolMap: Map<string, ToolDefinition>): UtilityTool[];