Hmbown/CodeWhale · error

exceeded the -byte aggregate catalogue limit

Error message

{} exceeded the {}-byte aggregate catalogue limit

What it means

MCP catalogue construction is capped by an aggregate byte budget (MAX_MCP_CATALOG_BYTES) as well as an item count. After each catalogue addition the builder re-checks its running totals and aborts with anyhow::bail! once the accumulated serialized size of all discovered tools/resources exceeds the limit. This protects the model context from being flooded by one runaway MCP server's catalogue.

Solutions

  1. Reduce the number of tools exposed by the MCP server (configure it to expose fewer tools or disable unused tool groups)
  2. Shorten tool descriptions/JSON schemas on the server side
  3. Enable any tool filtering/allowlist in the MCP server config so only needed tools are catalogued
  4. If the limit itself is the constraint, raise MAX_MCP_CATALOG_BYTES in a fork, understanding the context-window cost

Example fix

// before (server exposes 500 tools)
{ "mcpServers": { "everything": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-everything"] } } }
// after (expose only what you need)
{ "mcpServers": { "fs": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "--tools", "read_file,write_file"] } } }
Defensive patterns

Strategy: validation

Validate before calling

const MAX_MCP_CATALOG_BYTES: usize = 1_048_576;
// sum serialized sizes of tools before handing the catalogue to the client
let total: usize = tools.iter().map(|t| serde_json::to_string(t).unwrap().len()).sum();
if total > MAX_MCP_CATALOG_BYTES {
    tools.truncate_while(|t| running + size(t) > MAX_MCP_CATALOG_BYTES);
}

Prevention

When it happens

Trigger: Calling catalogue discovery (tools/list with pagination) on an MCP server whose cumulative serialized tool/resource metadata exceeds MAX_MCP_CATALOG_BYTES across all pages; common when a server exposes hundreds of tools with long descriptions.

Common situations: Connecting a general-purpose MCP server (e.g. a filesystem or search server) that exposes very many tools with verbose schemas; aggregating catalogues from multiple large servers under one session budget.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/d302f17a2d52acae. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/mcp.rs:1505

        self.pages = self.pages.saturating_add(1);
        self.items = self.items.saturating_add(item_count);
        self.bytes = self.bytes.saturating_add(serde_json::to_vec(result)?.len());
        if self.pages > MAX_MCP_CATALOG_PAGES {
            anyhow::bail!(
                "{} exceeded the {}-page catalogue limit",
                self.method,
                MAX_MCP_CATALOG_PAGES
            );
        }
        if self.items > MAX_MCP_CATALOG_ITEMS {
            anyhow::bail!(
                "{} exceeded the {}-item catalogue limit",
                self.method,
                MAX_MCP_CATALOG_ITEMS
            );
        }
        if self.bytes > MAX_MCP_CATALOG_BYTES {
            anyhow::bail!(
                "{} exceeded the {}-byte aggregate catalogue limit",
                self.method,
                MAX_MCP_CATALOG_BYTES
            );
        }
        let cursor = result
            .get("nextCursor")
            .and_then(|value| value.as_str())
            .map(str::to_owned);
        if let Some(cursor) = cursor.as_ref()
            && !self.seen_cursors.insert(cursor.clone())
        {
            anyhow::bail!("{} repeated pagination cursor; aborting", self.method);
        }
        Ok(cursor)
    }
}

View on GitHub (pinned to 73e0f67d83)