different-ai/openwork · error · Error

The MCP discovery response exceeded the 1 MiB limit.

Error message

The MCP discovery response exceeded the 1 MiB limit.

What it means

boundedResponse guards discovery HTTP responses: if the advertised content-length exceeds MAX_RESPONSE_BYTES (1 MiB) it cancels the body and throws; the streamed copy also enforces the cap while reading. Discovery documents are expected to be small metadata JSON, so an oversized response is treated as hostile or misconfigured rather than parsed. It surfaces as a plain Error, not a contract error.

Source

Thrown at packages/enterprise-mcp-client/src/requirements-discovery.ts:52

  if (
    input.requirements.authentication.kind !== "oauth"
    || input.requirements.authentication.authorizationServers.length !== 1
    || input.requirements.warnings.some((warning) => warning.code === "oauth_issuer_mismatch")
  ) return undefined

  const canonicalIssuer = input.requirements.authentication.authorizationServers[0]?.issuer
  if (!canonicalIssuer || canonicalIssuer === input.selectedIssuer) return undefined
  if (isEquivalentOAuthDiscoveryAlias(input.selectedIssuer, canonicalIssuer)) return canonicalIssuer
  return isEquivalentOAuthDiscoveryAlias(input.selectedIssuer, input.requirements.authentication.resource)
    ? canonicalIssuer
    : undefined
}

function boundedResponse(response: Response): Response {
  const advertisedLength = Number(response.headers.get("content-length"))
  if (Number.isFinite(advertisedLength) && advertisedLength > MAX_RESPONSE_BYTES) {
    void response.body?.cancel()
    throw new Error("The MCP discovery response exceeded the 1 MiB limit.")
  }
  if (!response.body) return response

  const reader = response.body.getReader()
  let bytesRead = 0
  const body = new ReadableStream<Uint8Array>({
    async pull(controller) {
      const result = await reader.read()
      if (result.done) {
        controller.close()
        return
      }
      bytesRead += result.value.byteLength
      if (bytesRead > MAX_RESPONSE_BYTES) {
        await reader.cancel()
        controller.error(new Error("The MCP discovery response exceeded the 1 MiB limit."))
        return
      }

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Verify the server URL points at the real MCP discovery endpoint returning small JSON metadata.
  2. Check intervening proxies/gateways that may substitute large error pages; fix their routing.
  3. If a legitimate deployment needs bigger documents, raise the limit in the library (rebuild/patch MAX_RESPONSE_BYTES) — otherwise reduce the document size server-side.

Example fix

// before — URL that returns a full HTML app shell
serverUrl: "https://example.com/"
// after — the MCP discovery endpoint
serverUrl: "https://example.com/mcp"
Defensive patterns

Strategy: validation

Validate before calling

// Check advertised size before fetching the discovery document
const head = await fetch(url, { method: "HEAD" })
const len = Number(head.headers.get("content-length"))
const tooBig = Number.isFinite(len) && len > 1024 * 1024

Try / catch

try { const reqs = await discoverConnectionRequirements(input) }
catch (e) {
  if (e.message.includes("1 MiB limit")) {
    throw new Error(`Discovery endpoint at ${input.serverUrl} returned an oversized response; verify the URL points at the MCP discovery document`)
  }
  throw e
}

Prevention

When it happens

Trigger: Any discovery fetch (response() → boundedResponse) where content-length > 1 MiB, or where the streamed body grows past 1 MiB before completion.

Common situations: A proxy/HTML error page returned instead of the discovery document; pointing the client at a non-MCP URL that serves large content; a misbehaving or malicious server sending huge payloads.

Related errors


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