{"record":{"id":"d302f17a2d52acae","repo":"Hmbown/CodeWhale","slug":"exceeded-the-byte-aggregate-catalogue-limit","errorCode":null,"errorMessage":"{} exceeded the {}-byte aggregate catalogue limit","messagePattern":"(.+?) exceeded the (.+?)-byte aggregate catalogue limit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp.rs","lineNumber":1505,"sourceCode":"        self.pages = self.pages.saturating_add(1);\n        self.items = self.items.saturating_add(item_count);\n        self.bytes = self.bytes.saturating_add(serde_json::to_vec(result)?.len());\n        if self.pages > MAX_MCP_CATALOG_PAGES {\n            anyhow::bail!(\n                \"{} exceeded the {}-page catalogue limit\",\n                self.method,\n                MAX_MCP_CATALOG_PAGES\n            );\n        }\n        if self.items > MAX_MCP_CATALOG_ITEMS {\n            anyhow::bail!(\n                \"{} exceeded the {}-item catalogue limit\",\n                self.method,\n                MAX_MCP_CATALOG_ITEMS\n            );\n        }\n        if self.bytes > MAX_MCP_CATALOG_BYTES {\n            anyhow::bail!(\n                \"{} exceeded the {}-byte aggregate catalogue limit\",\n                self.method,\n                MAX_MCP_CATALOG_BYTES\n            );\n        }\n        let cursor = result\n            .get(\"nextCursor\")\n            .and_then(|value| value.as_str())\n            .map(str::to_owned);\n        if let Some(cursor) = cursor.as_ref()\n            && !self.seen_cursors.insert(cursor.clone())\n        {\n            anyhow::bail!(\"{} repeated pagination cursor; aborting\", self.method);\n        }\n        Ok(cursor)\n    }\n}\n","sourceCodeStart":1487,"sourceCodeEnd":1523,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp.rs#L1487-L1523","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reduce the number of tools exposed by the MCP server (configure it to expose fewer tools or disable unused tool groups)","Shorten tool descriptions/JSON schemas on the server side","Enable any tool filtering/allowlist in the MCP server config so only needed tools are catalogued","If the limit itself is the constraint, raise MAX_MCP_CATALOG_BYTES in a fork, understanding the context-window cost"],"exampleFix":"// before (server exposes 500 tools)\n{ \"mcpServers\": { \"everything\": { \"command\": \"npx\", \"args\": [\"-y\", \"@modelcontextprotocol/server-everything\"] } } }\n// after (expose only what you need)\n{ \"mcpServers\": { \"fs\": { \"command\": \"npx\", \"args\": [\"-y\", \"@modelcontextprotocol/server-filesystem\", \"--tools\", \"read_file,write_file\"] } } }","handlingStrategy":"validation","validationCode":"const MAX_MCP_CATALOG_BYTES: usize = 1_048_576;\n// sum serialized sizes of tools before handing the catalogue to the client\nlet total: usize = tools.iter().map(|t| serde_json::to_string(t).unwrap().len()).sum();\nif total > MAX_MCP_CATALOG_BYTES {\n    tools.truncate_while(|t| running + size(t) > MAX_MCP_CATALOG_BYTES);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep per-server tool counts small; prefer focused servers","Monitor catalogue sizes when adding new MCP servers","Use tool allowlists in server config"],"tags":["mcp","resource-limit","catalogue"],"backgroundTag":"payload-too-large","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}