{"record":{"id":"35ed2a53c9440e67","repo":"ComposioHQ/composio","slug":"file-size-content-length-bytes-exceeds-maximum","errorCode":null,"errorMessage":"File size ({content_length} bytes) exceeds maximum allowed size ({max_size} bytes)","messagePattern":"File size \\((.+?) bytes\\) exceeds maximum allowed size \\((.+?) bytes\\)","errorType":"exception","errorClass":"ResponseTooLargeError","httpStatus":null,"severity":"error","filePath":"python/composio/core/models/_files.py","lineNumber":444,"sourceCode":"            f\"Please provide a direct URL to the file.\"\n        )\n\n    # Check for successful response\n    if not response.ok:\n        response.close()\n        raise ErrorUploadingFile(\n            f\"Failed to fetch file from URL: {_sanitize_url_for_logging(url)}. \"\n            f\"Status: {response.status_code}\"\n        )\n\n    # Check Content-Length header first (early abort for oversized files).\n    # The header is a hint from the remote server: `parse_content_length`\n    # returns None for anything untrustworthy, and the streaming guard below\n    # is the authoritative limit.\n    content_length = parse_content_length(response.headers.get(\"Content-Length\"))\n    if content_length is not None and content_length > max_size:\n        response.close()\n        raise ResponseTooLargeError(\n            f\"File size ({content_length} bytes) exceeds maximum allowed \"\n            f\"size ({max_size} bytes)\"\n        )\n\n    # Stream response with size tracking\n    chunks: t.List[bytes] = []\n    total_bytes = 0\n    chunk_size = 8192  # 8 KB chunks\n\n    try:\n        for chunk in response.iter_content(chunk_size=chunk_size):\n            if chunk:\n                total_bytes += len(chunk)\n                if total_bytes > max_size:\n                    response.close()\n                    raise ResponseTooLargeError(\n                        f\"Response size exceeds maximum allowed size ({max_size} bytes)\"\n                    )","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/python/composio/core/models/_files.py#L426-L462","documentation":"MCPServer.create wraps any unexpected exception from the underlying MCP server creation API call into a generic ValidationError('Failed to create MCP server'). The original cause is chained via `from e`, so inspect __cause__ to find the real problem (auth, network, invalid toolkit slug, backend error).","triggerScenarios":"Any exception raised inside MCPServer.create's try block: invalid API key, unknown toolkit slug, network failure to the Composio backend, malformed MCPToolkitConfig, or a 4xx/5xx response during server creation.","commonSituations":"Expired or missing COMPOSIO_API_KEY; typo'd toolkit string; transient backend outage; passing config fields the backend rejects.","solutions":["Inspect exc.__cause__ (or the full traceback) to identify the underlying error","Verify COMPOSIO_API_KEY is set and valid","Confirm each toolkit slug/config is correct and supported for MCP servers","Retry after transient network/backend failures; check Composio status if it persists"],"exampleFix":"# before\nmcp = server.create(toolkits=['github'])\n# after\ntry:\n    mcp = server.create(toolkits=['github'])\nexcept ValidationError as e:\n    cause = e.__cause__ or e\n    print(f'MCP create failed: {cause}')\n    raise","handlingStrategy":"try-catch","validationCode":"from composio import Composio\nclient = Composio()  # raises early if COMPOSIO_API_KEY missing/invalid\nvalid = ['github', 'slack']  # confirm slugs exist before calling\nmcp = server.create(toolkits=valid)","typeGuard":"def is_supported_toolkit(slug: str, client) -> bool:\n    return any(tk.slug == slug or tk.name == slug for tk in client.tools.get_list())","tryCatchPattern":"from composio.core.errors import ValidationError\nimport time\n\nfor attempt in range(3):\n    try:\n        mcp = server.create(toolkits=['github'])\n        break\n    except ValidationError as e:\n        cause = str(e.__cause__ or e)\n        if attempt < 2 and ('timeout' in cause.lower() or 'connection' in cause.lower()):\n            time.sleep(2 ** attempt)\n            continue\n        raise RuntimeError(f'MCP server creation failed: {cause}') from e","preventionTips":["Always inspect __cause__ on this wrapped error before debugging blindly","Validate API key and toolkit slugs up front","Retry transient network/backend causes with backoff"],"tags":["python","mcp","wrapped-error","api","server"],"backgroundTag":"wrapped-api-request-failure","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}