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: allow api key on mcp server

Brad Barbincbe86fa95295
diff --git a/packages/database/supabase/functions/chat/index.ts b/packages/database/supabase/functions/chat/index.ts
index 0b74c22646..c20f9f42f5 100644
--- a/packages/database/supabase/functions/chat/index.ts
+++ b/packages/database/supabase/functions/chat/index.ts
@@ -5,7 +5,7 @@ import { z } from "npm:[email protected]";
import { corsHeaders } from "../lib/headers.ts";
import SupabaseClient from "https://esm.sh/v135/@supabase/[email protected]/dist/module/SupabaseClient.d.ts";
-import { getAuthFromAPIKey, getSupabase } from "../lib/supabase.ts";
+import { getSupabase } from "../lib/supabase.ts";
import { Database } from "../lib/types.ts";
const model = createAnthropic({
@@ -21,16 +21,6 @@ serve(async (req: Request) => {
let userId: string | null = null;
let companyId: string | null = null;
- const CARBON_MCP_API_KEY = Deno.env.get("CARBON_MCP_API_KEY");
- if (CARBON_MCP_API_KEY) {
- const auth = await getAuthFromAPIKey(CARBON_MCP_API_KEY);
- if (auth) {
- client = auth.client;
- userId = auth.userId;
- companyId = auth.companyId;
- }
- }
-
const authHeader = req.headers.get("Authorization");
const token = authHeader?.replace("Bearer ", "") ?? null;
diff --git a/packages/database/supabase/functions/mcp/index.ts b/packages/database/supabase/functions/mcp/index.ts
index ddb3aab09a..b8b9f82952 100644
--- a/packages/database/supabase/functions/mcp/index.ts
+++ b/packages/database/supabase/functions/mcp/index.ts
@@ -29,9 +29,11 @@ serve(async (req: Request) => {
let userId: string | null = null;
let companyId: string | null = null;
- const CARBON_MCP_API_KEY = Deno.env.get("CARBON_MCP_API_KEY");
- if (CARBON_MCP_API_KEY) {
- const auth = await getAuthFromAPIKey(CARBON_MCP_API_KEY);
+ const authHeader = req.headers.get("Authorization");
+ const token = authHeader?.replace("Bearer ", "") ?? null;
+
+ if (token && token.startsWith("crbn_")) {
+ const auth = await getAuthFromAPIKey(token);
if (auth) {
client = auth.client;
userId = auth.userId;
@@ -39,9 +41,6 @@ serve(async (req: Request) => {
}
}
- const authHeader = req.headers.get("Authorization");
- const token = authHeader?.replace("Bearer ", "") ?? null;
-
if (token && !client) {
client = getSupabase(token);
companyId = req.headers.get("x-company-id");