{"record":{"id":"fca26337dd836c94","repo":"different-ai/openwork","slug":"mcp-configuration-failed","errorCode":"MCP_CONFIGURATION_FAILED","errorMessage":"Enterprise MCP failed during ${phaseLabel[input.operationPhase]}${request}.","messagePattern":"Enterprise MCP failed during (.+?)(.+?)\\.","errorType":"exception","errorClass":"EnterpriseMcpClientError","httpStatus":null,"severity":"error","filePath":"packages/enterprise-mcp-client/src/enterprise-mcp-client.ts","lineNumber":130,"sourceCode":"}\n\nfunction validateRedirectUri(redirectUri: string): string {\n  const parsed = redirectUriSchema.parse(redirectUri)\n  const url = new URL(parsed)\n  if (url.protocol !== \"https:\" && url.protocol !== \"http:\") {\n    throw new Error(\"An enterprise MCP OAuth redirect URI must use HTTP or HTTPS.\")\n  }\n  if (url.username || url.password || url.hash) {\n    throw new Error(\"An enterprise MCP OAuth redirect URI cannot contain credentials or a fragment.\")\n  }\n  return parsed\n}\n\nfunction configurationValue<T>(parse: () => T): T {\n  try {\n    return parse()\n  } catch (error) {\n    throw new EnterpriseMcpClientError({\n      operationPhase: \"configuration\",\n      requestPhase: null,\n      cause: error,\n    })\n  }\n}\n\nasync function closeWithinDeadline(close: () => Promise<void>, timeoutMs: number): Promise<void> {\n  let timer: ReturnType<typeof setTimeout> | undefined\n  try {\n    await Promise.race([\n      close(),\n      new Promise<never>((_resolve, reject) => {\n        timer = setTimeout(() => reject(new Error(\"The MCP client did not close before its deadline.\")), timeoutMs)\n      }),\n    ])\n  } finally {\n    if (timer) clearTimeout(timer)","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/enterprise-mcp-client/src/enterprise-mcp-client.ts#L112-L148","documentation":"configurationValue in packages/enterprise-mcp-client/src/enterprise-mcp-client.ts wraps any throw from option/configuration parsing (zod schemas for client options, oauth configuration, connection fields, authorization ids, tool names, resource URIs) into an EnterpriseMcpClientError with operationPhase \"configuration\" and code MCP_CONFIGURATION_FAILED. The original validation error is attached as cause; the message is rendered as \"Enterprise MCP failed during configuration...\". It means setup inputs were invalid before any network call was made.","triggerScenarios":"createEnterpriseMcpClient with invalid options (e.g. negative operationTimeoutMs, empty clientName), malformed oauthConfiguration (bad clientMetadataUrl, non-URL issuer), invalid authorizationId/authorizationCode lengths, empty toolName, or oversized/malformed resource URIs — any input failing its zod schema.","commonSituations":"Env-derived config like operationTimeoutMs: Number(process.env.TIMEOUT) yielding NaN; clientMetadataUrl pointing at a bare https origin with no path (violates the https+path refine); passing an empty tool name after trimming.","solutions":["Inspect error.cause (the zod issue) to see exactly which field failed validation.","Fix the offending configuration value at its source (env var, config file, caller argument).","Provide defaults for optional numeric options or ensure they parse to positive integers.","For clientMetadataUrl, use an https URL that includes a path (e.g. https://example.com/.well-known/oauth-client)."],"exampleFix":"// before\ncreateEnterpriseMcpClient({ operationTimeoutMs: Number(process.env.TIMEOUT_MS) })\n\n// after\nconst timeout = Number(process.env.TIMEOUT_MS)\ncreateEnterpriseMcpClient({ operationTimeoutMs: Number.isFinite(timeout) && timeout > 0 ? timeout : undefined })","handlingStrategy":"try-catch","validationCode":"import { z } from \"zod\"\nconst preflight = z.object({\n  operationTimeoutMs: z.number().int().positive().optional(),\n  clientMetadataUrl: z.string().url().optional(),\n  authorizationServerIssuer: z.string().url().optional(),\n})\npreflight.parse(suppliedOptions) // surfaces zod issues before the library does","typeGuard":null,"tryCatchPattern":"try {\n  const client = createEnterpriseMcpClient(options)\n} catch (error) {\n  if (error instanceof EnterpriseMcpClientError && error.operationPhase === \"configuration\") {\n    console.error(\"invalid MCP client config:\", error.cause)\n  } else throw error\n}","preventionTips":["Validate env-derived numbers (NaN/negative) before passing them as timeouts","Ensure clientMetadataUrl is https and includes a path","Log error.cause (the zod issue list) to pinpoint the bad field"],"tags":["configuration","zod","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}