You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace FileResource.is_binary with an encoding field
FileResource guessed is_binary from mime_type with a text/* prefix check,
and because False doubled as the "not given" sentinel an explicit
is_binary=False could never take effect, so application/json files were
always served as base64 blobs. Text reads also used Path.read_text()
with no encoding, i.e. the platform locale.
The field is now encoding: str | None. A string decodes the file and
serves it as text; None reads bytes and serves a blob. When omitted the
default comes from mime_type: the declared charset if present, else
utf-8 for textual types (text/*, +json/+xml suffixes, application/json,
xml, javascript), else None.
Resource models now reject unknown keyword arguments, so passing the
removed is_binary= fails at construction instead of being ignored.
Copy file name to clipboardExpand all lines: docs/migration.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -826,6 +826,31 @@ Reading a missing resource now returns JSON-RPC error code `-32602` (invalid par
826
826
827
827
The underlying lookups now raise typed exceptions instead of `ValueError`. `ResourceManager.get_resource()` raises `ResourceNotFoundError` when no resource or template matches the URI, and `ResourceTemplate.create_resource()` raises `ResourceError` when the template function fails. Neither subclasses `ValueError`, so callers catching `ValueError` should switch to `ResourceNotFoundError` / `ResourceError` (both importable from `mcp.server.mcpserver.exceptions`; `ResourceNotFoundError` subclasses `ResourceError`).
828
828
829
+
### `FileResource.is_binary` replaced by `encoding`
830
+
831
+
`FileResource` used to take `is_binary: bool` and guess its default from `mime_type` (`text/*` → text, anything else → bytes). Two problems fell out of that: `is_binary=False` could not actually be set — `False` doubled as the "not given" sentinel, so `mime_type="application/json"` always came back as a base64 blob — and text reads used `Path.read_text()` with no encoding, i.e. the platform locale (cp1252 on Windows).
832
+
833
+
The field is now `encoding: str | None`. A string means "decode with this encoding and serve as text"; `None` means "read bytes and serve as a blob". When omitted it defaults to the `charset` declared in `mime_type` if there is one, otherwise `"utf-8"` for textual mime types (`text/*`, `application/json`, `application/xml`, `application/javascript`, and any `+json`/`+xml` suffix) and `None` for everything else, so JSON and XML files are now served as text without any configuration.
834
+
835
+
Passing the removed `is_binary=` argument raises a `ValidationError` at construction rather than being silently ignored — all `Resource` classes now reject unknown keyword arguments.
0 commit comments