different-ai/openwork · error

An enterprise MCP server URL cannot contain a fragment.

Error message

An enterprise MCP server URL cannot contain a fragment.

What it means

validateConnection in packages/enterprise-mcp-client/src/enterprise-mcp-client.ts throws when the server URL contains a fragment (#...). Fragments are never sent to servers by HTTP clients, so a URL with one cannot identify a valid MCP endpoint and is rejected to avoid silently connecting to the wrong path.

Source

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

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 {
  try {
    return parse()

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Strip the fragment (and anything after #) from the server URL.
  2. Re-copy the endpoint URL from the MCP server's documentation without the anchor.
  3. If a query is needed, use query parameters (?key=value) which are permitted, not a fragment.

Example fix

// before
serverUrl: "https://mcp.example.com/mcp#tools"

// after
serverUrl: "https://mcp.example.com/mcp"
Defensive patterns

Strategy: validation

Validate before calling

function stripFragment(serverUrl: string): string {
  const u = new URL(serverUrl)
  if (u.hash) throw new Error(`remove fragment '${u.hash}' from serverUrl`)
  return serverUrl
}

Prevention

When it happens

Trigger: Creating a connection with serverUrl such as "https://mcp.example.com/mcp#section" or a URL copied from an HTML page that included an anchor.

Common situations: Copy-pasting a URL from documentation or a browser address bar where an anchor was included; template configs with a trailing "#" comment accidentally left in the value.

Related errors


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