different-ai/openwork · error

An enterprise MCP server URL cannot contain embedded credent

Error message

An enterprise MCP server URL cannot contain embedded credentials.

What it means

validateConnection in packages/enterprise-mcp-client/src/enterprise-mcp-client.ts rejects server URLs containing embedded userinfo credentials (url.username or url.password set, e.g. https://user:pass@host). Embedding secrets in URLs leaks them into logs, error messages, and telemetry, so the library forbids it; credentials must be supplied through the authorization object instead.

Source

Thrown at packages/enterprise-mcp-client/src/enterprise-mcp-client.ts:108

  lifecycle: EnterpriseMcpLifecycle
}

function requestInit(authorization: EnterpriseMcpAuthorization): RequestInit | undefined {
  if (authorization.type !== "api-key") return undefined
  return { headers: { authorization: `Bearer ${authorization.token}` } }
}

function validateConnection(connection: EnterpriseMcpConnection): URL {
  const parsed = connectionSchema.parse({ id: connection.id, serverUrl: connection.serverUrl })
  if (connection.authorization.type === "api-key" && !connection.authorization.token.trim()) {
    throw new Error("An API key connection requires a non-empty token.")
  }
  const url = new URL(parsed.serverUrl)
  if (url.protocol !== "https:" && url.protocol !== "http:") {
    throw new Error("An enterprise MCP server URL must use HTTP or HTTPS.")
  }
  if (url.username || url.password) {
    throw new Error("An enterprise MCP server URL cannot contain embedded credentials.")
  }
  if (url.hash) throw new Error("An enterprise MCP server URL cannot contain a fragment.")
  return url
}

function validateRedirectUri(redirectUri: string): string {
  const parsed = redirectUriSchema.parse(redirectUri)
  const url = new URL(parsed)
  if (url.protocol !== "https:" && url.protocol !== "http:") {
    throw new Error("An enterprise MCP OAuth redirect URI must use HTTP or HTTPS.")
  }
  if (url.username || url.password || url.hash) {
    throw new Error("An enterprise MCP OAuth redirect URI cannot contain credentials or a fragment.")
  }
  return parsed
}

function configurationValue<T>(parse: () => T): T {

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Remove user:pass@ from the URL and pass credentials via the connection's authorization field (e.g. api-key token or OAuth).
  2. If the server requires basic auth at the gateway, front it with a proxy or use an authorization mechanism the client supports.
  3. Sanitize config templates so placeholders like https://USER:PASS@host are never shipped literally.

Example fix

// before
serverUrl: "https://svc:hunter2@mcp.example.com/mcp"

// after
serverUrl: "https://mcp.example.com/mcp",
authorization: { type: "api-key", token: process.env.MCP_TOKEN }
Defensive patterns

Strategy: validation

Validate before calling

function assertNoUserInfo(serverUrl: string) {
  const u = new URL(serverUrl)
  if (u.username || u.password) throw new Error("move credentials out of the URL into the authorization config")
}

Prevention

When it happens

Trigger: Creating a connection whose serverUrl looks like "https://user:secret@mcp.example.com/mcp" or "https://token@host".

Common situations: Older service configs that used basic-auth-in-URL patterns; pasting a connection string (database-style) into an MCP server URL field; curl-style URLs carried over from CLI tooling.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/546c082aaedd58f7. Report an issue: GitHub.