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.

fix: claude strips the path from registration_endpoint and always hits /register on the issuer base URL

Brad Barbinb6453c6dcb9e
diff --git a/apps/erp/app/routes/[.]well-known.oauth-authorization-server.ts b/apps/erp/app/routes/[.]well-known.oauth-authorization-server.ts
index 4623357330..ccac19c426 100644
--- a/apps/erp/app/routes/[.]well-known.oauth-authorization-server.ts
+++ b/apps/erp/app/routes/[.]well-known.oauth-authorization-server.ts
@@ -7,9 +7,9 @@ export async function loader({ request }: LoaderFunctionArgs) {
const metadata = {
issuer,
- authorization_endpoint: `${issuer}/oauth/authorize`,
- token_endpoint: `${issuer}/oauth/token`,
- registration_endpoint: `${issuer}/oauth/register`,
+ authorization_endpoint: `${issuer}/authorize`,
+ token_endpoint: `${issuer}/token`,
+ registration_endpoint: `${issuer}/register`,
token_endpoint_auth_methods_supported: ["client_secret_post", "none"],
grant_types_supported: ["authorization_code", "refresh_token"],
response_types_supported: ["code"],
diff --git a/apps/erp/app/routes/oauth+/authorize.tsx b/apps/erp/app/routes/_oauth+/authorize.tsx
similarity index 100%
rename from apps/erp/app/routes/oauth+/authorize.tsx
rename to apps/erp/app/routes/_oauth+/authorize.tsx
diff --git a/apps/erp/app/routes/oauth+/register.ts b/apps/erp/app/routes/_oauth+/register.ts
similarity index 97%
rename from apps/erp/app/routes/oauth+/register.ts
rename to apps/erp/app/routes/_oauth+/register.ts
index 0ee8d7c0c8..7e67c62c75 100644
--- a/apps/erp/app/routes/oauth+/register.ts
+++ b/apps/erp/app/routes/_oauth+/register.ts
@@ -116,6 +116,7 @@ export async function action({ request }: ActionFunctionArgs) {
const response: Record<string, unknown> = {
client_id: clientId,
+ client_id_issued_at: Math.floor(Date.now() / 1000),
client_name,
redirect_uris,
grant_types,
@@ -125,6 +126,7 @@ export async function action({ request }: ActionFunctionArgs) {
if (rawClientSecret) {
response.client_secret = rawClientSecret;
+ response.client_secret_expires_at = 0;
}
if (client_uri) response.client_uri = client_uri;
diff --git a/apps/erp/app/routes/oauth+/token.tsx b/apps/erp/app/routes/_oauth+/token.tsx
similarity index 100%
rename from apps/erp/app/routes/oauth+/token.tsx
rename to apps/erp/app/routes/_oauth+/token.tsx
diff --git a/apps/erp/app/routes/api+/mcp+/_index.ts b/apps/erp/app/routes/api+/mcp+/_index.ts
index aac1642b65..db47022fff 100644
--- a/apps/erp/app/routes/api+/mcp+/_index.ts
+++ b/apps/erp/app/routes/api+/mcp+/_index.ts
@@ -3,6 +3,7 @@ import {
getCarbonServiceRole,
getUserScopedClient
} from "@carbon/auth/client.server";
+import { getAppUrl } from "@carbon/env";
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
import type { SupabaseClient } from "@supabase/supabase-js";
import type { ActionFunctionArgs } from "react-router";
@@ -52,6 +53,17 @@ async function authenticateOAuthToken(
};
}
+function make401Response(request: Request): Response {
+ const origin = getAppUrl() || new URL(request.url).origin;
+ return new Response(null, {
+ status: 401,
+ headers: {
+ "WWW-Authenticate": `Bearer resource_metadata="${origin}/.well-known/oauth-protected-resource"`,
+ ...corsHeaders
+ }
+ });
+}
+
async function resolveAuth(request: Request): Promise<{
ctx: McpContext;
request: Request;
@@ -85,15 +97,7 @@ async function resolveAuth(request: Request): Promise<{
};
}
- // 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
- }
- });
+ throw make401Response(request);
}
// Fall back to carbon-key auth
@@ -104,13 +108,7 @@ async function resolveAuth(request: Request): Promise<{
// 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
- }
- });
+ throw make401Response(request);
}
const { client, companyId, companyGroupId, userId } =