read¶
Reads file contents, optionally a byte range.
Signature¶
read(path: string, opts?: {
offset?: uint64 // default 0
length?: uint64 // default: whole file from offset
}) -> {
bytes: bytes // transport-specific representation
content_type: string // MUST match Entry.content_type
eof: boolean // true iff bytes[bytes.length-1] is the last byte of the file
} | Error
Parameters¶
| Field | Type | Required | Notes |
|---|---|---|---|
path |
string | yes | Must resolve to a file (type: "file") |
opts.offset |
uint64 | no | Byte offset to start reading from |
opts.length |
uint64 | no | Max bytes to return. Providers MAY cap. |
Response¶
Error codes¶
| Code | When |
|---|---|
not_found |
Path does not exist OR caller lacks access |
invalid_path |
Path is a directory or symlink, or syntactically invalid |
internal |
Backing store failed to serve the byte range |
Example¶
Request:
Response (over HTTP):
HTTP/1.1 200 OK
Content-Type: text/markdown
Content-Length: 4096
Content-Range: bytes 0-4095/4213
# Create Customer
Creates a new customer in your account. ...
Semantics¶
readMUST NOT succeed on a directory. ReturnError{code: "invalid_path"}.readon a symlink MUST returnError{code: "invalid_path"}— clients shouldstatthe symlink first andreaditstargetexplicitly.content_typeMUST match thecontent_typereturned bystaton the same path.eof: trueMUST be set iff the returned bytes include the last byte of the file. Whenoffset + bytes.length == file.size,eofistrue; otherwisefalse.- If
offsetexceeds the file size,readMUST return an emptybyteswitheof: true— not an error. - If
lengthis0,readMUST return an emptybyteswitheofreflecting whetheroffsetis at end-of-file.
Transport notes¶
Over HTTP, read returns raw bytes as the response body with the
Content-Type header set from the response's content_type field.
When a range is requested, the provider MUST also set Content-Range and
Accept-Ranges: bytes.
Over MCP, bytes is base64-encoded in the tool result. The MCP tool
result MAY set a MIME hint on the tool response so downstream tooling
displays it correctly.