{"record":{"id":"c3237d52ad6ca6cf","repo":"PrefectHQ/fastmcp","slug":"error-reading-resource-uri-r-e","errorCode":null,"errorMessage":"Error reading resource {uri!r}: {e}","messagePattern":"Error reading resource (.+?): (.+?)","errorType":"exception","errorClass":"ResourceError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/server/server.py","lineNumber":1656,"sourceCode":"                        logger.exception(f\"Error reading resource {uri!r}\")\n                        raise\n                    except Exception as e:\n                        logger.exception(f\"Error reading resource {uri!r}\")\n                        # Handle actionable errors that should reach the LLM\n                        if get_http_status_code(e) == 429:\n                            raise ResourceError(\n                                \"Rate limited by upstream API, please retry later\"\n                            ) from e\n                        if is_timeout_error(e):\n                            raise ResourceError(\n                                \"Upstream request timed out, please retry\"\n                            ) from e\n                        # Standard masking logic\n                        if self._mask_error_details:\n                            raise ResourceError(\n                                f\"Error reading resource {uri!r}\"\n                            ) from e\n                        raise ResourceError(\n                            f\"Error reading resource {uri!r}: {e}\"\n                        ) from e\n\n                # Try templates (transforms + auth via get_resource_template)\n                template = await self.get_resource_template(uri, version=version)\n                if template is None:\n                    if version is None:\n                        raise NotFoundError(f\"Unknown resource: {uri!r}\")\n                    raise NotFoundError(\n                        f\"Unknown resource: {uri!r} version {version!r}\"\n                    )\n                span.set_attributes(template.get_span_attributes())\n                params = template.matches(uri)\n                assert params is not None\n\n                # Path-security screening: reject traversal / absolute-path /\n                # null-byte payloads in extracted parameter values BEFORE the\n                # handler runs. This is the single chokepoint for every","sourceCodeStart":1638,"sourceCodeEnd":1674,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/server.py#L1638-L1674","documentation":"FastMCP raises ResourceError(\"Error reading resource {uri!r}: {e}\") when a resource read fails with an unexpected exception and error masking is disabled. The underlying exception text is appended so the caller (often an LLM) can see what went wrong; the original exception is chained as __cause__.","triggerScenarios":"`await server.read_resource(uri)` where the resource's `_read()` raises a plain Exception (not FastMCPError/MCPError, not a 429, not a timeout) on a server constructed without mask_error_details (default).","commonSituations":"Development/debugging where masking is off; resource handlers with bugs (bad paths, missing env vars, unparsed responses); integration tests surfacing handler exceptions verbatim.","solutions":["Read the ': {e}' suffix — it names the real underlying error; fix that in the resource function.","Ensure required env/config for the resource (paths, URLs, keys) are set.","If the message could leak secrets, enable mask_error_details=True or raise ResourceError yourself with a sanitized message.","Add retry/validation inside the handler for transient upstream failures."],"exampleFix":"// before\n@resource(\"api://user\")\ndef get_user():\n    return requests.get(URL).json()  # raises ConnectionError -> ResourceError(\"...: ConnectionError...\")\n// after\n@resource(\"api://user\")\ndef get_user():\n    try:\n        return requests.get(URL, timeout=10).json()\n    except requests.RequestException as e:\n        raise ResourceError(f\"User API unavailable: {e}\") from e","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = await client.read_resource(uri)\nexcept ResourceError as e:\n    logger.error(f\"Resource {uri} failed: {e}\")  # suffix names the root cause\n    raise","preventionTips":["Fix the root-cause exception named after ': ' in the message.","Validate handler inputs and config (paths, env vars) at startup.","Add timeouts and error handling around handler I/O.","Enable masking in production if messages may leak internals."],"tags":["mcp","resource","unhandled-exception","python"],"backgroundTag":"unhandled-exception-in-handler","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}