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.

feat(settings): gate company management to internal users; block MCP company creation (#1347)

Brad Barbin65d19c47285d
diff --git a/apps/erp/app/routes/api+/mcp+/lib/mcp-blocked-tools.ts b/apps/erp/app/routes/api+/mcp+/lib/mcp-blocked-tools.ts
index 20698e90a6..967a97fe2e 100644
--- a/apps/erp/app/routes/api+/mcp+/lib/mcp-blocked-tools.ts
+++ b/apps/erp/app/routes/api+/mcp+/lib/mcp-blocked-tools.ts
@@ -4,6 +4,9 @@
*/
export const MCP_BLOCKED_TOOL_NAMES: readonly string[] = [
"settings_seedCompany",
+ // Creating a company is an account-level operation that must not be exposed
+ // as an MCP tool (it would let a company-scoped token create new tenants).
+ "settings_insertCompany",
// Internal sweep orchestration invoked by job/operation completion flows.
// Their args require a userId the MCP executor cannot inject (AuthField has
// no such payload field), so direct calls would only ever fail validation.
diff --git a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json
index 2e809a8b49..3b83eb27cf 100644
--- a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json
+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json
@@ -1,6 +1,6 @@
{
- "generated": "2026-08-07T11:34:00.821Z",
- "totalTools": 1417,
+ "generated": "2026-08-07T12:10:07.116Z",
+ "totalTools": 1416,
"modules": 15,
"tools": [
{
@@ -40258,32 +40258,6 @@
"properties": {}
}
},
- {
- "name": "settings_insertCompany",
- "module": "settings",
- "classification": "WRITE",
- "description": "insert company",
- "paramCount": 1,
- "serviceParams": [
- "client",
- "company",
- "companyGroupId"
- ],
- "injectAuth": [
- "companyId",
- "createdBy",
- "updatedBy"
- ],
- "schema": {
- "type": "object",
- "properties": {
- "company": {}
- },
- "required": [
- "company"
- ]
- }
- },
{
"name": "settings_insertSubsidiary",
"module": "settings",
diff --git a/apps/erp/app/routes/x+/settings+/companies.$id.tsx b/apps/erp/app/routes/x+/settings+/companies.$id.tsx
index 4949b099bc..530922f9a5 100644
--- a/apps/erp/app/routes/x+/settings+/companies.$id.tsx
+++ b/apps/erp/app/routes/x+/settings+/companies.$id.tsx
@@ -2,6 +2,7 @@ import { assertIsPost, error, notFound, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
+import { isInternalEmail } from "@carbon/utils";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
import { redirect, useLoaderData } from "react-router";
import {
@@ -14,10 +15,15 @@ import { invalidateCompanyTimeZone } from "~/modules/shared/timezone.server";
import { path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
+ const { client, email } = await requirePermissions(request, {
view: "settings"
});
+ // Multi-company management is gated to internal (Carbon) users for now.
+ if (!isInternalEmail(email)) {
+ throw redirect(path.to.settings);
+ }
+
const { id } = params;
if (!id) throw notFound("Subsidiary not found");
@@ -34,10 +40,15 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
- const { client, userId } = await requirePermissions(request, {
+ const { client, userId, email } = await requirePermissions(request, {
update: "settings"
});
+ // Multi-company management is gated to internal (Carbon) users for now.
+ if (!isInternalEmail(email)) {
+ throw redirect(path.to.settings);
+ }
+
const { id } = params;
if (!id) throw notFound("Subsidiary not found");
diff --git a/apps/erp/app/routes/x+/settings+/companies.delete.$id.tsx b/apps/erp/app/routes/x+/settings+/companies.delete.$id.tsx
index 616288dfc6..31e1f74c16 100644
--- a/apps/erp/app/routes/x+/settings+/companies.delete.$id.tsx
+++ b/apps/erp/app/routes/x+/settings+/companies.delete.$id.tsx
@@ -2,6 +2,7 @@ import { error, notFound, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { getCarbonServiceRole } from "@carbon/auth/client.server";
import { flash } from "@carbon/auth/session.server";
+import { isInternalEmail } from "@carbon/utils";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
import { redirect, useLoaderData, useNavigate, useParams } from "react-router";
import { ConfirmDelete } from "~/components/Modals";
@@ -9,10 +10,15 @@ import { deleteSubsidiary, getSubsidiary } from "~/modules/settings";
import { path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
+ const { client, email } = await requirePermissions(request, {
view: "settings"
});
+ // Multi-company management is gated to internal (Carbon) users for now.
+ if (!isInternalEmail(email)) {
+ throw redirect(path.to.settings);
+ }
+
const { id } = params;
if (!id) throw notFound("Subsidiary not found");
@@ -28,10 +34,15 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
}
export async function action({ request, params }: ActionFunctionArgs) {
- await requirePermissions(request, {
+ const { email } = await requirePermissions(request, {
delete: "settings"
});
+ // Multi-company management is gated to internal (Carbon) users for now.
+ if (!isInternalEmail(email)) {
+ throw redirect(path.to.settings);
+ }
+
const { id } = params;
if (!id) {
throw redirect(
diff --git a/apps/erp/app/routes/x+/settings+/companies.new.tsx b/apps/erp/app/routes/x+/settings+/companies.new.tsx
index 5aaa89e602..362a898b21 100644
--- a/apps/erp/app/routes/x+/settings+/companies.new.tsx
+++ b/apps/erp/app/routes/x+/settings+/companies.new.tsx
@@ -10,6 +10,7 @@ import {
ModalHeader,
ModalTitle
} from "@carbon/react";
+import { isInternalEmail } from "@carbon/utils";
import { getLocalTimeZone } from "@internationalized/date";
import type { ActionFunctionArgs } from "react-router";
import { redirect, useNavigate } from "react-router";
@@ -26,10 +27,15 @@ import { path } from "~/utils/path";
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
- const { userId } = await requirePermissions(request, {
+ const { userId, email } = await requirePermissions(request, {
create: "settings"
});
+ // Multi-company management is gated to internal (Carbon) users for now.
+ if (!isInternalEmail(email)) {
+ throw redirect(path.to.settings);
+ }
+
const formData = await request.formData();
const validation = await validator(subsidiaryValidator).validate(formData);
diff --git a/apps/erp/app/routes/x+/settings+/companies.tsx b/apps/erp/app/routes/x+/settings+/companies.tsx
index 4a82afa447..fee4552e3b 100644
--- a/apps/erp/app/routes/x+/settings+/companies.tsx
+++ b/apps/erp/app/routes/x+/settings+/companies.tsx
@@ -10,6 +10,7 @@ import {
TabsList,
TabsTrigger
} from "@carbon/react";
+import { isInternalEmail } from "@carbon/utils";
import { useCallback } from "react";
import type { LoaderFunctionArgs } from "react-router";
import { Outlet, redirect, useLoaderData, useNavigate } from "react-router";
@@ -28,10 +29,15 @@ export const handle: Handle = {
};
export async function loader({ request }: LoaderFunctionArgs) {
- const { companyGroupId } = await requirePermissions(request, {
+ const { companyGroupId, email } = await requirePermissions(request, {
view: "settings"
});
+ // Multi-company management is gated to internal (Carbon) users for now.
+ if (!isInternalEmail(email)) {
+ throw redirect(path.to.settings);
+ }
+
const companies = await getSubsidiaries(
getCarbonServiceRole(),
companyGroupId