# MCP row tools (/reference/mcp-row-tools)

The arguments of the two MCP tools that read and write the rows of an item's table, their limits, and how an agent reads an answer that didn't fit.



Every [MCP endpoint](/reference/marfa-mcp-server#endpoints) serves `marfa_read_rows` to a credential that may read a type, and `marfa_write_rows` to one that may write a type. Each works on one [table](/build/tables) of one item, named in `id` and `table`. **A call is the API call it names,** so a refusal carries the code the API answers. `marfa_get` lists an item's tables without their rows. The rules are in the contract's [tables chapter](https://github.com/withmarfa/marfa/blob/main/conformance/spec/tables.md#rows-through-mcp).

## Read rows [#read-rows]

`marfa_read_rows` answers `rows` as [List table rows](/reference/api/tables/listTableRows) does, in the same order, with a `next_cursor` or `null`.

| Argument | What it does |
| - | - |
| `limit` | How many rows at most, from 1 to 1,000. 50 when left out |
| `cursor` | The `next_cursor` of the answer before, for the rows that follow |
| `filter` | Which rows, such as `values.amount gt 10`. A column is `values.<column>`, and `id` and `updated_at` are the row's own |
| `sort`, `direction` | `id`, `updated_at` or `values.<column>`, and `asc` or `desc`. The table's own order when left out |
| `columns` | A list of up to 64 column names. Each row's `values` and `withheld` then hold only those. `id` and `updated_at` always come back |
| `totals` | `true` adds `row_count` and `totals`, as [Get table totals](/reference/api/tables/getTableTotals) answers them for the `filter` |
| `group`, `time_zone` | One or two groupings of `by` and an optional `bucket`. Adds `row_count`, `totals` and `groups`, as [Get table totals by group](/reference/api/tables/getTableGroups) answers them |
| `row`, `column`, `offset` | Reads one row's text in one column from `offset`, in characters |

`filter` and `sort` may name a column that `columns` leaves out. Without `totals` or `group`, the answer holds no `row_count` or `totals`.

## A read that doesn't fit [#a-read-that-doesnt-fit]

**`marfa_read_rows` keeps every answer within 40,000 characters,** whatever `limit` says, so a page of long rows holds fewer rows than it asked for.

| When | The answer | To read the rest |
| - | - | - |
| The rows don't all fit | Fewer rows, a `next_cursor` after the last of them, and a `hint` that the answer stopped early | Send `next_cursor` as `cursor` |
| The first row doesn't fit alone | That row alone, its longest text values cut. `cut` names each by `id`, `column` and `next_offset` | Call with `row`, `column` and `offset` set to `next_offset`, until `next_offset` is `null` |
| The `groups` leave no room for a row | The groups with no rows, the call's own `cursor` as `next_cursor`, and a `hint` | Read the rows without `group` |
| The `groups` alone don't fit | A tool error. Groups are never cut | Narrow the `filter`, or group by less |

Name `columns` to fit more rows in one answer.

## Write rows [#write-rows]

`marfa_write_rows` takes `operations`, a list of 1 to 200, and applies them in order as [Write table rows](/reference/api/tables/writeTableRows) applies a batch: **all of them or none.** It answers the `batch`, `last_activity_at` and each operation's outcome in `results`.

| Operation | What it does |
| - | - |
| `{ "op": "put", "id"?, "values" }` | Creates a row, or replaces the whole row its `id` names |
| `{ "op": "patch", "id", "values", "expect"? }` | Sets the columns named and keeps the rest. `null` clears a column |
| `{ "op": "delete", "id", "expect"? }` | Removes a row |

* **`expect` holds the values the agent read,** keyed by column. If the row holds another value, the batch is refused `row_changed` and nothing is written. The error's `details.row` holds the row's values now.
* **A row's values are at most 64 KiB as JSON.** The refusal says to keep a long text in a file item and name it in an `item` column.
* **More than 200 operations** is a `validation_error` naming `operations`.

[Write a table's rows](/build/write-rows) explains each rule.
