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
mcp upsert operation flag (#1375)
Anshul sharmab39eb654086a
diff --git a/.ai/plans/2026-08-12-mcp-upsert-operation-flag.md b/.ai/plans/2026-08-12-mcp-upsert-operation-flag.mdnew file mode 100644index 0000000000..8ff531a297--- /dev/null+++ b/.ai/plans/2026-08-12-mcp-upsert-operation-flag.md@@ -0,0 +1,116 @@+# MCP: explicit `_operation` for ambiguous upsert tools++Branch: `fix/mcp-upsert-operation-flag`++## Problem++Carbon's `upsert*` service functions pick insert vs update by testing+`if ("createdBy" in payload)`. The web app is safe because the "new" route and the+"edit" route each hard-code their intent (`createdBy: userId` vs `updatedBy: userId`).++MCP has one tool per service function, so it cannot know the intent. Today+`enrichWithAuthContext` (`apps/erp/app/routes/api+/mcp+/lib/direct-executor.ts:57`)+stamps `createdBy` onto every payload for any tool whose `injectAuth` contains it —+262 of 1431 tools. Consequence: **an edit issued through MCP always takes the insert+branch**, so it either duplicates or fails on the primary key instead of updating.++Rejected alternatives (and why):++- **Decide on `id` presence** — breaks entities whose id is a human-typed code.+ `partValidator` (`apps/erp/app/modules/items/items.models.ts:824`) requires `id` on+ create, so `items_upsertPart` would become a no-op update. Confirmed create call+ sites that pass both `createdBy` and an `id`:+ `apps/erp/app/routes/api+/sales-rfq.$rfqId.map-lines.ts:99`,+ `apps/erp/app/routes/api+/purchase-invoice.$invoiceId.map-lines.ts:94`,+ `apps/erp/app/routes/x+/part+/new.tsx:36`, `x+/tool+/new.tsx:35`,+ `x+/material+/new.tsx:35`, `x+/consumable+/new.tsx:35`, `x+/service+/new.tsx:35`,+ `x+/items+/methods+/operation.new.tsx:41`.+- **Decide on `createdAt` presence** — only works if the caller echoes back a whole+ row it read; a model editing one field won't.+- **A new marker column / field on the service payload** — would require touching all+ affected service signatures and stripping the field before every write.++## Approach++Add an MCP-only argument `_operation: "create" | "update"`, required, on the tools+that genuinely branch. The executor reads it, removes it from the payload, and stamps+`createdBy` or `updatedBy` accordingly. No service, validator, or table changes.++### Scope — which tools get the flag++Only tools whose service body literally contains `if ("createdBy" in …)`. Measured+today: **88 tools** (of the 191 `upsert*`-named tools, of the 262 `createdBy`-injecting+tools). Detection is done in the generator by inspecting the parsed function body, so+the set stays correct as services change — it is not a hand-maintained list.++Deliberately excluded:++- The 71 `insert|create|copy|generate|duplicate|add` tools — always create. Asking the+ model "create or update?" only introduces a wrong answer that could skip `createdBy`+ and hit a NOT NULL violation.+- The ~103 `upsert*` tools that decide some other way (Postgres `.upsert()`, `"id" in`,+ or always-insert). They still need `createdBy`; changing their injection could break+ writes that work today.++## Changes++### 1. `scripts/generate-mcp.ts`++- New helper `usesCreatedByDiscriminator(serviceContent, funcName)`: locate the+ function body (reuse `findMatchingBrace`) and test for `"createdBy" in`.+- New `ToolMetadata` field `operationArg?: true`, set when that helper is true **and**+ `injectAuth` includes `createdBy`.+- When `operationArg` is set, add to the emitted schema:+ ```+ _operation: {+ type: "string",+ enum: ["create", "update"],+ description: "Whether this call creates a new record or updates an existing one."+ }+ ```+ and add `"_operation"` to the schema's `required` array.+- Regenerate `apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json`+ (`npx tsx scripts/generate-mcp.ts`). Never hand-edit that file.++### 2. `apps/erp/app/routes/api+/mcp+/lib/direct-executor.ts`++- Immediately after `normalizedArgs` is derived, lift the flag out and drop it from the+ object that will be passed on:+ ```+ const operation = normalizedArgs?._operation as "create" | "update" | undefined;+ ```+ then build the working args without `_operation`. This must happen **before** the+ branches at lines ~164 and ~187, which hand the args object to the service as-is —+ a leftover `_operation` would reach Supabase as a nonexistent column.+- If the tool has `operationArg` and `operation` is missing or not one of the two+ values, return `{ success: false, error: "..." }` without calling the service.+- `enrichWithAuthContext(value, context, fields, operation)`:+ - `operation === "update"` → stamp `updatedBy` (and `companyId`), **never** `createdBy`.+ - `operation === "create"` or tool has no `operationArg` → today's behaviour exactly.+ - Keep the existing `!("createdBy" in enriched)` guard so a caller-supplied value wins.++### 3. Nested-payload note++`_operation` arrives at the top level of the tool arguments, while the payload may be+nested under a parameter name (line ~168). Lifting it out at the top, as above, covers+both the nested and the flat shapes.++## Verification++- `npx tsx scripts/generate-mcp.ts` → diff shows `_operation` on ~88 tools and on no+ others; `totalTools` unchanged at 1431.+- `pnpm exec turbo run typecheck --filter=erp` (package is named `erp`, not `@carbon/erp`).+- `pnpm exec biome check` on the touched files.+- Manual MCP calls against a running dev stack:+ - `sales_upsertCustomerStatus` with `_operation: "update"` + an existing id → row is+ updated, `createdBy` unchanged, `updatedBy` set.+ - `sales_upsertCustomerStatus` with `_operation: "create"` → new row as before.+ - `items_upsertPart` with `_operation: "create"` and a human-typed `id` → still creates.+ - A `..._insert*` tool → unchanged, no `_operation` in its schema.++## Out of scope++- Changing the `if ("createdBy" in …)` convention in the 88 services.+- An existence lookup as a cross-check on a wrong `_operation`. Worth revisiting if the+ model gets it wrong in practice; a wrong value fails loudly today (PK conflict or a+ zero-row update), which is already better than the silent misroute.diff --git a/.claude/rules/mcp-tools-reference.md b/.claude/rules/mcp-tools-reference.mdindex 6467425319..d9648f2915 100644--- a/.claude/rules/mcp-tools-reference.md+++ b/.claude/rules/mcp-tools-reference.md@@ -90,6 +90,15 @@ and writes `apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json``["companyId","createdBy","updatedBy"]`; `update|set|sync|run|…*` →`["companyId","updatedBy"]`.+- **`_operation`** (`usesCreatedByDiscriminator`): the ~96 tools whose service picks+ insert-vs-update with `if ("createdBy" in …)` get a **required**+ `_operation: "create" | "update"` in their schema — the schema is the only marker,+ there is no parallel metadata flag. `direct-executor.ts` strips `_operation` from the+ args (top level *and* the `{ args: {...} }` wrapper) before building the payload, then+ suppresses the `createdBy` stamp when it is `"update"` — otherwise every MCP edit would+ take the insert branch. Missing/invalid `_operation` on such a tool is rejected before+ the service is called; `call_tool.arguments` is `z.any()`, so the executor is the gate.+## The 15 modules (current `tool-metadata.json`)`account` · `accounting` · `documents` · `inventory` · `invoicing` · `items` ·diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.tsindex ff41d3fe77..7ad02dbdfe 100644--- a/apps/erp/app/modules/items/items.service.ts+++ b/apps/erp/app/modules/items/items.service.ts@@ -3780,7 +3780,6 @@ export async function upsertSupplierPart(client: SupabaseClient<Database>,supplierPart:| (Omit<z.infer<typeof supplierPartValidator>, "id"> & {- id?: undefined;companyId: string;createdBy: string;customFields?: Json;@@ -3792,25 +3791,18 @@ export async function upsertSupplierPart(customFields?: Json;})) {- // Branch on `id`, not on `createdBy` — the MCP executor stamps `createdBy` onto- // every payload, which turned every API-side edit into a duplicate insert.- if (supplierPart.id !== undefined) {- // Drop any injected `createdBy` so an edit can't rewrite who created the row.- const { createdBy: _createdBy, ...update } =- supplierPart as typeof supplierPart & {- createdBy?: string;- };+ if ("createdBy" in supplierPart) {return client.from("supplierPart")- .update(sanitize(update))- .eq("id", supplierPart.id)- .eq("companyId", supplierPart.companyId)+ .insert([supplierPart]).select("id").single();}return client.from("supplierPart")- .insert([supplierPart])+ .update(sanitize(supplierPart))+ .eq("id", supplierPart.id)+ .eq("companyId", supplierPart.companyId).select("id").single();}diff --git a/apps/erp/app/routes/api+/mcp+/lib/direct-executor.ts b/apps/erp/app/routes/api+/mcp+/lib/direct-executor.tsindex 588e741748..3f0e2ba325 100644--- a/apps/erp/app/routes/api+/mcp+/lib/direct-executor.ts+++ b/apps/erp/app/routes/api+/mcp+/lib/direct-executor.ts@@ -51,13 +51,16 @@ export interface ExecutorContext {userId: string;}+export type McpOperation = "create" | "update";+// Stamps auth identity onto typed payloads. Carbon's services expect auth// fields inside the payload (predates MCP). `fields` is per-tool from// tool-metadata.json so reads stay clean and updates don't overwrite createdBy.function enrichWithAuthContext(value: unknown,context: ExecutorContext,- fields: AuthField[]+ fields: AuthField[],+ operation?: McpOperation): unknown {if (!value || typeof value !== "object" || Array.isArray(value)) return value;if (fields.length === 0) return value;@@ -66,7 +69,10 @@ function enrichWithAuthContext(...(value as Record<string, unknown>)};- if (fields.includes("createdBy") && !("createdBy" in enriched)) {+ // A caller-supplied createdBy would send the service down its insert branch.+ if (operation === "update") {+ delete enriched.createdBy;+ } else if (fields.includes("createdBy") && !("createdBy" in enriched)) {enriched.createdBy = context.userId;}if (fields.includes("updatedBy")) {@@ -82,6 +88,35 @@ function enrichWithAuthContext(return enriched;}+// Pulls the MCP-only `_operation` flag out of the args, top level or nested.+// Returns every value it found so the caller can reject contradictory ones.+function extractOperation(args: Record<string, any> | undefined): {+ operations: string[];+ args: Record<string, any> | undefined;+} {+ if (!args) return { operations: [], args };++ const operations: string[] = [];+ const cleaned: Record<string, any> = {};++ if (args._operation !== undefined) operations.push(String(args._operation));++ for (const [key, value] of Object.entries(args)) {+ if (key === "_operation") continue;+ if (value && typeof value === "object" && !Array.isArray(value)) {+ const { _operation, ...rest } = value as Record<string, any>;+ if (_operation !== undefined) {+ operations.push(String(_operation));+ cleaned[key] = rest;+ continue;+ }+ }+ cleaned[key] = value;+ }++ return { operations, args: cleaned };+}+export async function executeFunction(functionName: string,context: ExecutorContext,@@ -97,7 +132,11 @@ export async function executeFunction(};}}- const normalizedArgs = args && typeof args === "object" ? args : undefined;+ const rawArgs = args && typeof args === "object" ? args : undefined;++ // Strip before use — the branches below hand args straight to the service.+ const { operations: requestedOperations, args: normalizedArgs } =+ extractOperation(rawArgs);if (isMcpBlockedTool(functionName)) {return {@@ -143,6 +182,31 @@ export async function executeFunction(toolMeta && "injectAuth" in toolMeta? ((toolMeta as any).injectAuth as AuthField[]): [];+ const needsOperation = Boolean(+ (toolMeta as any)?.schema?.properties?._operation+ );++ const distinctOperations = [...new Set(requestedOperations)];+ if (needsOperation && distinctOperations.length > 1) {+ return {+ success: false,+ error: `${functionName} received conflicting _operation values (${distinctOperations.join(", ")}).`+ };+ }+ const requestedOperation = distinctOperations[0];+ if (+ needsOperation &&+ requestedOperation !== "create" &&+ requestedOperation !== "update"+ ) {+ return {+ success: false,+ error: `${functionName} requires _operation to be "create" (insert a new record) or "update" (modify an existing one).`+ };+ }+ const operation = needsOperation+ ? (requestedOperation as McpOperation)+ : undefined;// Build arguments array based on parameter namesconst functionArgs: any[] = [];@@ -165,7 +229,12 @@ export async function executeFunction(functionArgs.push(argsValue);} else if (normalizedArgs && paramName in normalizedArgs) {functionArgs.push(- enrichWithAuthContext(normalizedArgs[paramName], context, injectAuth)+ enrichWithAuthContext(+ normalizedArgs[paramName],+ context,+ injectAuth,+ operation+ ));} else if (normalizedArgs &&@@ -178,13 +247,20 @@ export async function executeFunction(// and use as positional. Hits the documented `{ args: {...} }` wrapper// and any LLM that guesses a key name (e.g. `{ item: {...} }`).const value = Object.values(normalizedArgs)[0];- functionArgs.push(enrichWithAuthContext(value, context, injectAuth));+ functionArgs.push(+ enrichWithAuthContext(value, context, injectAuth, operation)+ );} else if (normalizedArgs && Object.keys(normalizedArgs).length > 0) {// No key matched — pass the entire args object as a positional param.// Handles functions like upsertPart(client, part) where the caller// passes flat fields instead of nesting under the param name.functionArgs.push(- enrichWithAuthContext({ ...normalizedArgs }, context, injectAuth)+ enrichWithAuthContext(+ { ...normalizedArgs },+ context,+ injectAuth,+ operation+ ));} else {// Skip optional parametersdiff --git a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.jsonindex 9d5f58bf3f..46ed8f2ede 100644--- a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json@@ -1,5 +1,5 @@{- "generated": "2026-08-11T11:05:29.792Z",+ "generated": "2026-08-12T05:30:07.628Z","totalTools": 1431,"modules": 15,"tools": [@@ -2352,10 +2352,19 @@"schema": {"type": "object","properties": {- "account": {}+ "account": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "account"+ "account",+ "_operation"]}},@@ -2391,10 +2400,19 @@},"historicalExchangeRate": {"type": "number"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "code"+ "code",+ "_operation"]}},@@ -2433,11 +2451,20 @@},"calculationMethod": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["name",- "calculationMethod"+ "calculationMethod",+ "_operation"]}},@@ -2595,11 +2622,20 @@},"ownerId": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["name",- "ownerId"+ "ownerId",+ "_operation"]}},@@ -2692,10 +2728,19 @@"items": {"type": "string"}+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "dimension"+ "dimension",+ "_operation"]}},@@ -3433,10 +3478,19 @@"schema": {"type": "object","properties": {- "data": {}+ "data": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "data"+ "data",+ "_operation"]}},@@ -3785,10 +3839,19 @@"schema": {"type": "object","properties": {- "data": {}+ "data": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "data"+ "data",+ "_operation"]}},@@ -4403,13 +4466,22 @@},"writeGroups": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["id","name","readGroups",- "writeGroups"+ "writeGroups",+ "_operation"]}},@@ -7190,10 +7262,19 @@"schema": {"type": "object","properties": {- "kanban": {}+ "kanban": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "kanban"+ "kanban",+ "_operation"]}},@@ -7238,11 +7319,20 @@},"supplierId": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["id",- "receiptId"+ "receiptId",+ "_operation"]}},@@ -7284,11 +7374,20 @@},"storageTypeIds": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["name",- "locationId"+ "locationId",+ "_operation"]}},@@ -7318,10 +7417,19 @@},"carrier": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -7369,11 +7477,20 @@},"customerId": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["id",- "shipmentId"+ "shipmentId",+ "_operation"]}},@@ -7395,10 +7512,19 @@"schema": {"type": "object","properties": {- "stockTransfer": {}+ "stockTransfer": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "stockTransfer"+ "stockTransfer",+ "_operation"]}},@@ -7420,10 +7546,19 @@"schema": {"type": "object","properties": {- "stockTransferLine": {}+ "stockTransferLine": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "stockTransferLine"+ "stockTransferLine",+ "_operation"]}},@@ -7478,10 +7613,19 @@"schema": {"type": "object","properties": {- "transfer": {}+ "transfer": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "transfer"+ "transfer",+ "_operation"]}},@@ -7807,10 +7951,19 @@},"name": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -8154,10 +8307,19 @@},"notes": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "locationId"+ "locationId",+ "_operation"]}},@@ -8258,13 +8420,22 @@},"storageUnitId": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["pickingListId","jobId","jobMaterialId",- "itemId"+ "itemId",+ "_operation"]}},@@ -10175,10 +10346,19 @@"schema": {"type": "object","properties": {- "payment": {}+ "payment": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "payment"+ "payment",+ "_operation"]}},@@ -10225,10 +10405,19 @@"schema": {"type": "object","properties": {- "app": {}+ "app": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "app"+ "app",+ "_operation"]}},@@ -10399,10 +10588,19 @@"schema": {"type": "object","properties": {- "memo": {}+ "memo": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "memo"+ "memo",+ "_operation"]}},@@ -14219,10 +14417,19 @@"schema": {"type": "object","properties": {- "consumable": {}+ "consumable": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "consumable"+ "consumable",+ "_operation"]}},@@ -14295,10 +14502,19 @@"schema": {"type": "object","properties": {- "part": {}+ "part": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "part"+ "part",+ "_operation"]}},@@ -14405,11 +14621,20 @@},"sortMethod": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["itemId",- "locationId"+ "locationId",+ "_operation"]}},@@ -14470,10 +14695,19 @@"schema": {"type": "object","properties": {- "partPlanning": {}+ "partPlanning": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "partPlanning"+ "partPlanning",+ "_operation"]}},@@ -14567,10 +14801,19 @@},"description": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -14618,11 +14861,20 @@},"unitPrice": {"type": "number"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["itemId",- "supplierId"+ "supplierId",+ "_operation"]}},@@ -14759,11 +15011,20 @@},"itemType": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["id",- "makeMethodId"+ "makeMethodId",+ "_operation"]}},@@ -14785,10 +15046,19 @@"schema": {"type": "object","properties": {- "methodOperation": {}+ "methodOperation": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "methodOperation"+ "methodOperation",+ "_operation"]}},@@ -14810,10 +15080,19 @@"schema": {"type": "object","properties": {- "methodOperationStep": {}+ "methodOperationStep": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "methodOperationStep"+ "methodOperationStep",+ "_operation"]}},@@ -14862,10 +15141,19 @@"schema": {"type": "object","properties": {- "slide": {}+ "slide": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "slide"+ "slide",+ "_operation"]}},@@ -14887,10 +15175,19 @@"schema": {"type": "object","properties": {- "methodOperationParameter": {}+ "methodOperationParameter": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "methodOperationParameter"+ "methodOperationParameter",+ "_operation"]}},@@ -14912,10 +15209,19 @@"schema": {"type": "object","properties": {- "methodOperationTool": {}+ "methodOperationTool": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "methodOperationTool"+ "methodOperationTool",+ "_operation"]}},@@ -15038,10 +15344,19 @@"schema": {"type": "object","properties": {- "material": {}+ "material": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "material"+ "material",+ "_operation"]}},@@ -15139,11 +15454,20 @@},"code": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["name",- "code"+ "code",+ "_operation"]}},@@ -15369,11 +15693,20 @@},"code": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["name",- "code"+ "code",+ "_operation"]}},@@ -15395,10 +15728,19 @@"schema": {"type": "object","properties": {- "service": {}+ "service": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "service"+ "service",+ "_operation"]}},@@ -15454,10 +15796,19 @@"schema": {"type": "object","properties": {- "tool": {}+ "tool": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "tool"+ "tool",+ "_operation"]}},@@ -15907,10 +16258,19 @@"schema": {"type": "object","properties": {- "changeNoticeType": {}+ "changeNoticeType": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "changeNoticeType"+ "changeNoticeType",+ "_operation"]}},@@ -17609,11 +17969,20 @@},"date": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["name",- "date"+ "date",+ "_operation"]}},@@ -17670,6 +18039,14 @@},"sunday": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [@@ -17683,7 +18060,8 @@"thursday","friday","saturday",- "sunday"+ "sunday",+ "_operation"]}},@@ -21191,10 +21569,19 @@"schema": {"type": "object","properties": {- "productionEvent": {}+ "productionEvent": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "productionEvent"+ "productionEvent",+ "_operation"]}},@@ -21544,10 +21931,19 @@"schema": {"type": "object","properties": {- "jobOperation": {}+ "jobOperation": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "jobOperation"+ "jobOperation",+ "_operation"]}},@@ -21569,10 +21965,19 @@"schema": {"type": "object","properties": {- "jobOperationStep": {}+ "jobOperationStep": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "jobOperationStep"+ "jobOperationStep",+ "_operation"]}},@@ -21621,10 +22026,19 @@"schema": {"type": "object","properties": {- "slide": {}+ "slide": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "slide"+ "slide",+ "_operation"]}},@@ -21646,10 +22060,19 @@"schema": {"type": "object","properties": {- "jobOperationParameter": {}+ "jobOperationParameter": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "jobOperationParameter"+ "jobOperationParameter",+ "_operation"]}},@@ -21671,10 +22094,19 @@"schema": {"type": "object","properties": {- "jobOperationTool": {}+ "jobOperationTool": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "jobOperationTool"+ "jobOperationTool",+ "_operation"]}},@@ -22203,10 +22635,19 @@},"name": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -22233,10 +22674,19 @@},"name": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -22293,11 +22743,20 @@},"content": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["status",- "priority"+ "priority",+ "_operation"]}},@@ -22327,11 +22786,20 @@},"comment": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["maintenanceDispatchId",- "comment"+ "comment",+ "_operation"]}},@@ -22353,10 +22821,19 @@"schema": {"type": "object","properties": {- "event": {}+ "event": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "event"+ "event",+ "_operation"]}},@@ -22395,12 +22872,21 @@},"unitCost": {"type": "number"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["maintenanceDispatchId","itemId",- "unitOfMeasureCode"+ "unitOfMeasureCode",+ "_operation"]}},@@ -22430,11 +22916,20 @@},"workCenterId": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["maintenanceDispatchId",- "workCenterId"+ "workCenterId",+ "_operation"]}},@@ -22479,6 +22974,14 @@},"active": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [@@ -22486,7 +22989,8 @@"workCenterId","frequency","priority",- "active"+ "active",+ "_operation"]}},@@ -22522,12 +23026,21 @@},"unitOfMeasureCode": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["maintenanceScheduleId","itemId",- "unitOfMeasureCode"+ "unitOfMeasureCode",+ "_operation"]}},@@ -23292,10 +23805,19 @@"schema": {"type": "object","properties": {- "slide": {}+ "slide": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "slide"+ "slide",+ "_operation"]}},@@ -26865,11 +27387,20 @@},"supplierStatus": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["name",- "supplierStatus"+ "supplierStatus",+ "_operation"]}},@@ -26905,11 +27436,20 @@},"leadTime": {"type": "number"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["supplierId",- "processId"+ "processId",+ "_operation"]}},@@ -27050,10 +27590,19 @@"schema": {"type": "object","properties": {- "supplierQuote": {}+ "supplierQuote": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "supplierQuote"+ "supplierQuote",+ "_operation"]}},@@ -27135,10 +27684,19 @@},"name": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -29687,11 +30245,20 @@},"calibrationIntervalInMonths": {"type": "number"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["gaugeTypeId",- "gaugeRole"+ "gaugeRole",+ "_operation"]}},@@ -29751,6 +30318,14 @@},"notes": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [@@ -29760,7 +30335,8 @@"requiresAction","requiresAdjustment","requiresRepair",- "calibrationAttempts"+ "calibrationAttempts",+ "_operation"]}},@@ -29787,10 +30363,19 @@},"name": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -30073,6 +30658,14 @@},"operationSupplierProcessId": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [@@ -30081,7 +30674,8 @@"name","locationId","nonConformanceTypeId",- "openDate"+ "openDate",+ "_operation"]}},@@ -30111,10 +30705,19 @@},"content": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -30141,10 +30744,19 @@},"name": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -30171,10 +30783,19 @@},"name": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -32712,10 +33333,19 @@"schema": {"type": "object","properties": {- "contractorWithAbilities": {}+ "contractorWithAbilities": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "contractorWithAbilities"+ "contractorWithAbilities",+ "_operation"]}},@@ -32786,11 +33416,20 @@},"type": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["name",- "type"+ "type",+ "_operation"]}},@@ -33047,12 +33686,21 @@},"content": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["status","priority",- "locationId"+ "locationId",+ "_operation"]}},@@ -33082,11 +33730,20 @@},"comment": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["maintenanceDispatchId",- "comment"+ "comment",+ "_operation"]}},@@ -33108,10 +33765,19 @@"schema": {"type": "object","properties": {- "event": {}+ "event": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "event"+ "event",+ "_operation"]}},@@ -33150,12 +33816,21 @@},"unitCost": {"type": "number"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["maintenanceDispatchId","itemId",- "unitOfMeasureCode"+ "unitOfMeasureCode",+ "_operation"]}},@@ -33185,11 +33860,20 @@},"workCenterId": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["maintenanceDispatchId",- "workCenterId"+ "workCenterId",+ "_operation"]}},@@ -33258,6 +33942,14 @@},"sunday": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [@@ -33272,7 +33964,8 @@"thursday","friday","saturday",- "sunday"+ "sunday",+ "_operation"]}},@@ -33308,12 +34001,21 @@},"unitOfMeasureCode": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["maintenanceScheduleId","itemId",- "unitOfMeasureCode"+ "unitOfMeasureCode",+ "_operation"]}},@@ -33368,10 +34070,19 @@"schema": {"type": "object","properties": {- "process": {}+ "process": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "process"+ "process",+ "_operation"]}},@@ -33499,11 +34210,20 @@},"defaultStandardFactor": {"type": "number"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["name",- "description"+ "description",+ "_operation"]}},@@ -36884,10 +37604,19 @@},"website": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -37291,10 +38020,19 @@},"name": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -37321,10 +38059,19 @@},"name": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -37351,10 +38098,19 @@},"name": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -38025,11 +38781,20 @@},"digitalQuoteAcceptedByEmail": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["customerId",- "locationId"+ "locationId",+ "_operation"]}},@@ -38675,10 +39440,19 @@"schema": {"type": "object","properties": {- "operation": {}+ "operation": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "operation"+ "operation",+ "_operation"]}},@@ -38700,10 +39474,19 @@"schema": {"type": "object","properties": {- "quoteOperationStep": {}+ "quoteOperationStep": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "quoteOperationStep"+ "quoteOperationStep",+ "_operation"]}},@@ -38725,10 +39508,19 @@"schema": {"type": "object","properties": {- "quoteOperationParameter": {}+ "quoteOperationParameter": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "quoteOperationParameter"+ "quoteOperationParameter",+ "_operation"]}},@@ -38750,10 +39542,19 @@"schema": {"type": "object","properties": {- "quoteOperationTool": {}+ "quoteOperationTool": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "quoteOperationTool"+ "quoteOperationTool",+ "_operation"]}},@@ -39484,11 +40285,20 @@},"salesPersonId": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["customerId",- "rfqDate"+ "rfqDate",+ "_operation"]}},@@ -39539,13 +40349,22 @@},"modelUploadId": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": ["salesRfqId","customerPartId","quantity",- "unitOfMeasureCode"+ "unitOfMeasureCode",+ "_operation"]}},@@ -40400,10 +41219,19 @@},"size": {"type": "number"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "itemId"+ "itemId",+ "_operation"]}},@@ -40683,13 +41511,22 @@"placement": {},"content": {},"config": {},- "} & ({ createdBy": {}+ "} & ({ createdBy": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": ["name","placement","content",- "} & ({ createdBy"+ "} & ({ createdBy",+ "_operation"]}},@@ -41872,10 +42709,19 @@},"expiresAt": {"type": "string"+ },+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."}},"required": [- "name"+ "name",+ "_operation"]}},@@ -42098,10 +42944,19 @@"schema": {"type": "object","properties": {- "webhook": {}+ "webhook": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "webhook"+ "webhook",+ "_operation"]}},@@ -43218,10 +44073,19 @@"schema": {"type": "object","properties": {- "upload": {}+ "upload": {},+ "_operation": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ],+ "description": "Required. 'create' inserts a new record, 'update' modifies the existing record with this id."+ }},"required": [- "upload"+ "upload",+ "_operation"]}},diff --git a/scripts/generate-mcp.ts b/scripts/generate-mcp.tsindex 98b98086fd..55914806d4 100644--- a/scripts/generate-mcp.ts+++ b/scripts/generate-mcp.ts@@ -469,6 +469,49 @@ function computeInjectAuth(return ["companyId"];}+// Services that pick insert-vs-update this way are the only ones MCP can't infer.+function usesCreatedByDiscriminator(+ content: string,+ funcName: string+): boolean {+ const regex = new RegExp(+ `export\\s+(?:async\\s+)?function\\s+${funcName}\\s*\\(`+ );+ const match = regex.exec(content);+ if (!match) return false;+ const closeParen = findMatchingBrace(+ content,+ match.index + match[0].length - 1+ );+ const nextExport = content.indexOf("\nexport ", closeParen);+ const body = content.substring(+ closeParen,+ nextExport === -1 ? content.length : nextExport+ );+ return stripComments(body).includes('"createdBy" in');+}++// The `:` guard keeps `https://` intact.+function stripComments(source: string): string {+ return source+ .replace(/\/\*[\s\S]*?\*\//g, "")+ .replace(/(^|[^:])\/\/.*$/gm, "$1");+}++function addOperationArg(schema: Record<string, unknown>): void {+ const properties = (schema.properties ?? {}) as Record<string, unknown>;+ properties._operation = {+ type: "string",+ enum: ["create", "update"],+ description:+ "Required. 'create' inserts a new record, 'update' modifies the existing record with this id.",+ };+ schema.properties = properties;+ const required = ((schema.required as string[] | undefined) ?? []).slice();+ if (!required.includes("_operation")) required.push("_operation");+ schema.required = required;+}+function generateDescription(funcName: string): string {return funcName.replace(/([A-Z])/g, " $1")@@ -606,6 +649,12 @@ export function generateToolMetadata(): void {DESCRIPTION_OVERRIDES[toolName] || generateDescription(func.name);const serviceParams = func.params.map((p) => p.name);const { schema, paramCount } = buildToolSchema(func, modelsContent);+ if (+ injectAuth.includes("createdBy") &&+ usesCreatedByDiscriminator(content, func.name)+ ) {+ addOperationArg(schema);+ }allTools.push({name: toolName,