Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

refactor: support trx or db

Brad Barbin15cb1365e8cd
diff --git a/packages/database/supabase/functions/mcp/tools.ts b/packages/database/supabase/functions/mcp/tools.ts
index 51e12c70eb..13406d5979 100644
--- a/packages/database/supabase/functions/mcp/tools.ts
+++ b/packages/database/supabase/functions/mcp/tools.ts
@@ -15,56 +15,6 @@ import { getNextSequence } from "../shared/get-next-sequence.ts";
const model = new Supabase.ai.Session("gte-small");
-export const prompt = {
- name: "carbon-purchasing-mcp-prompt",
- description: "Instructions for using the Carbon Purchasing MCP effectively",
- instructions: `
-This server provides access to Carbon, an ERP for manufacturing. Use it to effectively complete the tasks of a purchasing and procurement department.
-
-When handling purchase order requests:
-1. First identify the part details (including quantities and measurements)
-2. Use getPart to look up the part ID
-3. If no supplier is explicitly specified in the prompt:
- - Use suggestSupplierForParts to get recommended suppliers
- - Ask the user to confirm which supplier they want to use
-4. Only proceed with createPurchaseOrder when both part and supplier are confirmed
-5. If there are multiple options for a part or supplier, ask the user to confirm which one they want to use
-6. If there are no options, ask the user for clarification
-
-For example:
-- If user says "create a purchase order for 5lb of 1/4" steel":
- 1. First look up the part ID for "1/4" steel"
- 2. Then ask user to specify a supplier, potentially offering suggestions
- 3. Only create the PO once supplier is confirmed
-
-- If user says "create a purchase order for 5lb of 1/4" steel from MetalCorp":
- 1. Look up part ID for "1/4" steel"
- 2. Look up supplier ID for "MetalCorp"
- 3. Create the PO with both IDs
-
-Key capabilities:
-- Create and update purchase orders
-- Search for suppliers and parts
-- Suggest suppliers for parts
-- Search for existing purchase orders
-- Search for open purchase orders
-- Search for purchase order history
-
-
-Tools:
-- getPart
- - Search for a part by readable id or description
- - Returns an id that can be used to create a purchase order
-- getSupplier
- - Search for suppliers by id, a specific name from the prompt, a deduced description, or a list of part ids
- - Returns an id that can be used to create a purchase order
-- suggestSupplierForParts
- - Suggest a list of suppliers for a given list of parts
-- createPurchaseOrder
- - Create a purchase order in draft status with multiple parts
-`,
-};
-
const createPurchaseOrder = tool({
name: "createPurchaseOrder",
description: "Create a purchase order",
@@ -463,13 +413,6 @@ async function getSuppliersForParts(
return null;
}
-export const tools = [
- createPurchaseOrder,
- getPart,
- getSupplier,
- suggestSupplierForParts,
-];
-
async function generateEmbedding(text: string): Promise<number[]> {
const embedding = await model.run(text, {
mean_pool: true,
@@ -478,3 +421,60 @@ async function generateEmbedding(text: string): Promise<number[]> {
return embedding as number[];
}
+
+export const tools = [
+ createPurchaseOrder,
+ getPart,
+ getSupplier,
+ suggestSupplierForParts,
+];
+
+export const prompt = {
+ name: "carbon-purchasing-mcp-prompt",
+ description: "Instructions for using the Carbon Purchasing MCP effectively",
+ instructions: `
+This server provides access to Carbon, an ERP for manufacturing. Use it to effectively complete the tasks of a purchasing and procurement department.
+
+When handling purchase order requests:
+1. First identify the part details (including quantities and measurements)
+2. Use getPart to look up the part ID
+3. If no supplier is explicitly specified in the prompt:
+ - Use suggestSupplierForParts to get recommended suppliers
+ - Ask the user to confirm which supplier they want to use
+4. Only proceed with createPurchaseOrder when both part and supplier are confirmed
+5. If there are multiple options for a part or supplier, ask the user to confirm which one they want to use
+6. If there are no options, ask the user for clarification
+
+For example:
+- If user says "create a purchase order for 5lb of 1/4" steel":
+ 1. First look up the part ID for "1/4" steel"
+ 2. Then ask user to specify a supplier, potentially offering suggestions
+ 3. Only create the PO once supplier is confirmed
+
+- If user says "create a purchase order for 5lb of 1/4" steel from MetalCorp":
+ 1. Look up part ID for "1/4" steel"
+ 2. Look up supplier ID for "MetalCorp"
+ 3. Create the PO with both IDs
+
+Key capabilities:
+- Create and update purchase orders
+- Search for suppliers and parts
+- Suggest suppliers for parts
+- Search for existing purchase orders
+- Search for open purchase orders
+- Search for purchase order history
+
+
+Tools:
+- getPart
+ - Search for a part by readable id or description
+ - Returns an id that can be used to create a purchase order
+- getSupplier
+ - Search for suppliers by id, a specific name from the prompt, a deduced description, or a list of part ids
+ - Returns an id that can be used to create a purchase order
+- suggestSupplierForParts
+ - Suggest a list of suppliers for a given list of parts
+- createPurchaseOrder
+ - Create a purchase order in draft status with multiple parts
+`,
+};
\ No newline at end of file
diff --git a/packages/database/supabase/functions/shared/get-next-sequence.ts b/packages/database/supabase/functions/shared/get-next-sequence.ts
index 86717de6a0..65de55c685 100644
--- a/packages/database/supabase/functions/shared/get-next-sequence.ts
+++ b/packages/database/supabase/functions/shared/get-next-sequence.ts
@@ -1,4 +1,4 @@
-import { Transaction } from "https://esm.sh/[email protected]";
+import { Kysely, Transaction } from "https://esm.sh/[email protected]";
import { DB } from "../lib/database.ts";
import { interpolateSequenceDate } from "../lib/utils.ts";