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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix: mcp connector via oauth
Brad Barbin0467706ac356
diff --git a/apps/erp/app/routes/[.]well-known.oauth-authorization-server.ts b/apps/erp/app/routes/[.]well-known.oauth-authorization-server.tsindex 5853c7724a..4623357330 100644--- a/apps/erp/app/routes/[.]well-known.oauth-authorization-server.ts+++ b/apps/erp/app/routes/[.]well-known.oauth-authorization-server.ts@@ -1,9 +1,9 @@-import { VERCEL_URL } from "@carbon/auth";+import { getAppUrl } from "@carbon/env";import type { LoaderFunctionArgs } from "react-router";export async function loader({ request }: LoaderFunctionArgs) {const url = new URL(request.url);- const issuer = VERCEL_URL || url.origin;+ const issuer = getAppUrl() || url.origin;const metadata = {issuer,diff --git a/apps/erp/app/routes/[.]well-known.oauth-protected-resource.ts b/apps/erp/app/routes/[.]well-known.oauth-protected-resource.tsnew file mode 100644index 0000000000..09a5d51948--- /dev/null+++ b/apps/erp/app/routes/[.]well-known.oauth-protected-resource.ts@@ -0,0 +1,25 @@+import { getAppUrl } from "@carbon/env";+import type { LoaderFunctionArgs } from "react-router";++export async function loader({ request }: LoaderFunctionArgs) {+ const url = new URL(request.url);+ const origin = getAppUrl() || url.origin;++ return new Response(+ JSON.stringify({+ resource: `${origin}/api/mcp`,+ authorization_servers: [origin],+ bearer_methods_supported: ["header"],+ scopes_supported: ["mcp:tools"]+ }),+ {+ status: 200,+ headers: {+ "Content-Type": "application/json",+ "Access-Control-Allow-Origin": "*",+ "Access-Control-Allow-Methods": "GET, OPTIONS",+ "Cache-Control": "public, max-age=3600"+ }+ }+ );+}diff --git a/apps/erp/app/routes/api+/mcp+/_index.ts b/apps/erp/app/routes/api+/mcp+/_index.tsindex 8285538821..aac1642b65 100644--- a/apps/erp/app/routes/api+/mcp+/_index.ts+++ b/apps/erp/app/routes/api+/mcp+/_index.ts@@ -84,6 +84,16 @@ async function resolveAuth(request: Request): Promise<{request};}++ // OAuth token was provided but invalid — return 401 so the client+ // can re-authenticate rather than falling through to cookie auth+ throw new Response(null, {+ status: 401,+ headers: {+ "WWW-Authenticate": `Bearer resource_metadata="${new URL(request.url).origin}/.well-known/oauth-protected-resource"`,+ ...corsHeaders+ }+ });}// Fall back to carbon-key auth@@ -92,6 +102,17 @@ async function resolveAuth(request: Request): Promise<{request = new Request(request, { headers });}+ // No Authorization header at all — return 401 for OAuth discovery+ if (!authHeader && !hasCarbonKey) {+ throw new Response(null, {+ status: 401,+ headers: {+ "WWW-Authenticate": `Bearer resource_metadata="${new URL(request.url).origin}/.well-known/oauth-protected-resource"`,+ ...corsHeaders+ }+ });+ }+const { client, companyId, companyGroupId, userId } =await requirePermissions(request, {});diff --git a/ci/src/deploy.ts b/ci/src/deploy.tsindex 72b2371df0..3f3ef02ab8 100644--- a/ci/src/deploy.ts+++ b/ci/src/deploy.ts@@ -123,6 +123,7 @@ async function deploy(): Promise<void> {jira_client_secret,jira_oauth_redirect_url,jira_state_secret,+ jwt_key,openai_api_key,posthog_api_host,posthog_project_public_key,@@ -292,6 +293,7 @@ async function deploy(): Promise<void> {STRIPE_WEBHOOK_SECRET: stripe_webhook_secret ?? undefined,SUPABASE_ANON_KEY: anon_key,SUPABASE_DB_URL: database_connection_pooler_url,+ SUPABASE_JWT_SECRET: jwt_key ?? undefined,SUPABASE_SERVICE_ROLE_KEY: service_role_key,SUPABASE_URL: database_url,URL_ERP: url_erp,diff --git a/sst.config.ts b/sst.config.tsindex 58d7e7153a..8c6f7b8864 100644--- a/sst.config.ts+++ b/sst.config.ts@@ -88,6 +88,7 @@ export default $config({STRIPE_WEBHOOK_SECRET: process.env.STRIPE_WEBHOOK_SECRET,SUPABASE_ANON_KEY: process.env.SUPABASE_ANON_KEY,SUPABASE_DB_URL: process.env.SUPABASE_DB_URL,+ SUPABASE_JWT_SECRET: process.env.SUPABASE_JWT_SECRET,SUPABASE_SERVICE_ROLE_KEY: process.env.SUPABASE_SERVICE_ROLE_KEY,SUPABASE_URL: process.env.SUPABASE_URL,VERCEL_ENV: "production",@@ -167,6 +168,7 @@ export default $config({SESSION_SECRET: process.env.SESSION_SECRET,SUPABASE_ANON_KEY: process.env.SUPABASE_ANON_KEY,SUPABASE_DB_URL: process.env.SUPABASE_DB_URL,+ SUPABASE_JWT_SECRET: process.env.SUPABASE_JWT_SECRET,SUPABASE_SERVICE_ROLE_KEY: process.env.SUPABASE_SERVICE_ROLE_KEY,SUPABASE_URL: process.env.SUPABASE_URL,VERCEL_ENV: "production",