A list endpoint should answer with an object, not a bare array, and that object should carry total: the number of rows that matched the filters, not the number on this page. That is the rule Mosaic's local API follows for every collection. We arrived at it the usual way, by shipping three different shapes first.
Three shapes in version 1
The first version of /api/v1 answered a list in whichever shape the route's author reached for:
- a bare array from
/projects,/tagsand/proxies { total, profiles }from/profiles- a bare
{ engines }, with no count, from/engines
A caller had to remember which was which. Worse, the bare arrays were stuck. A JSON array has no room for a second field, so the day a count or a page was needed on /proxies, every script reading it as an array would have broken.
Every collection is now { total, <items> }, with the list under a key named for what it holds:
{ "total": 12, "proxies": [ ... ] }
{ "total": 3, "projects": [ ... ] }
{ "total": 2, "engines": [ ... ], "install": { ... } }
The key is the noun, not a generic items, because a response read in a log or pasted into a chat should say what it is. The fixed part is that total sits at the top of every list and the list itself is never the whole body. A route that needs to say more adds a field beside them, as /engines does with the install state, and nobody's parser breaks.
Everything the window does, from a script on your own computerIn Mosaic: REST API. Everything the window does, from your own scripts. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.
Mosaic is a desktop app
Email yourself the link and open it on your computer.
Why the total count in a list response counts every match
/profiles is the collection that grows. Libraries run to hundreds of profiles, and before paging the only way to read one was all of it on every poll. So it takes limit and offset:
GET /api/v1/profiles?projectId=p_shop&limit=50&offset=100
and answers:
{ "total": 344, "limit": 50, "offset": 100, "profiles": [ ... 50 rows ... ] }
total is 344 there, not 50. The caller can already count the rows it got. What it cannot see from the page is whether there is a next one. With total counting every row that matched the project, search and tag filters, the loop is plain arithmetic: keep going while offset + limit < total. If total meant the page, the only way to find the end would be to ask for a page past it and get nothing back, which is one wasted request on every full read.
Some APIs answer this with a hasMore flag or a cursor instead, usually because counting a huge table is expensive. Our store is on the same computer and counting a few thousand profiles in memory costs next to nothing, so we give the full number and the caller gets both answers from it.
What paging refuses
Two choices in pageOf, the one function every paged route uses:
- Absent means everything. With no
limit, REST returns the whole collection. Adding paging did not change what an existing script received. A cap of 1,000 per request stops one call from serialising an unbounded library. - Wrong means a 400.
?limit=abc,-1or2.5is refused withlimit must be a whole number of 0 or more.Treating an unreadable value as absent would hand back every row, and the caller would believe its paging worked.
The same rule, on the surface nobody asked
The rule was written for REST, and a check (check:api-behaviour) held REST to it. MCP is the other public door to the same store, the one an AI assistant calls, and nothing had asked it the same question. When we did, against the running app with the same data in the same minute, seven tools disagreed with their REST twins:
| Tool | REST | MCP |
|---|---|---|
list_projects | { total, projects } | bare array |
list_profiles | { total, profiles } | bare array, no paging |
list_proxies | { total, proxies } | bare array |
list_folders | { total, folders } | bare array |
list_scenarios | { total, scenarios } | bare array |
list_engines | { total, engines } | bare array |
list_running | none | bare array |
list_profiles was the one that cost something. With no total a model paging a library could not tell whether there was more, and with no limit it received every row at once: eight hundred profiles into one context window, because the REST route had grown paging and its twin had not. Warm-up presets drifted on both surfaces together, a bare { presets, defaults } with no count, so there was no correct copy to compare the wrong one against.
All of them carry total now. list_profiles takes limit and offset with a default of 100 and a maximum of 500, and its own description tells the model that total counts every match. How an assistant uses that over a real library is in letting an AI assistant run profiles over MCP.
A rule nobody checks drifts
The check now walks fourteen tools plus the paging contract on both surfaces. We put each fault back to watch it fire, and the two lines it printed were the right ones:
MCP list_engines returns a bare array; every collection returns { total, engines }.
MCP list_profiles limit=1 returned 40 profiles.
If you are designing a list response, the short version is what we would have saved ourselves: an object from day one, the list under a named key, total for every match, and a 400 for a limit you cannot read. The full route list for Mosaic is on the REST API page, the tools on the MCP server page, and a worked script in the local API guide.






