> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magpiedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Magpie is a trace store for AI agents, used as a library (crate `magpiedb`, npm `magpiedb`, PyPI `magpiedb`) or as `magpie-server`, which takes OpenTelemetry (OTLP over HTTP on 127.0.0.1:4318 and gRPC on 127.0.0.1:4317 by default).
> Use only the commands, flags, routes and JSON shapes that these pages show. Do not guess a flag or a query field: if a page does not show it, say that the docs do not show it.
> Install the library with `cargo add magpiedb`, `npm install magpiedb` or `pip install magpiedb`. Get the server from the GitHub Releases download or the Docker image `ghcr.io/intojhanurag/magpie-server`, as the quick start shows.
> Only one process may write to a store folder at a time. For many apps, send traces to one `magpie-server`.
> `magpie-server doctor` checks a running server. An AI agent can query the traces over MCP at `/mcp` on the HTTP port (page guides/mcp).

# Lists and cursors

> sort, limit and cursor: how magpie-server returns long lists of spans, traces and sessions in pages.

Four routes return lists in pages: [`/v1/search`](https://docs.magpiedb.com/reference/api/search), [`/v1/traces/find`](https://docs.magpiedb.com/reference/api/traces-find), [`/v1/sessions/find`](https://docs.magpiedb.com/reference/api/sessions#find-sessions) and [`GET /v1/traces/:id/spans`](https://docs.magpiedb.com/reference/api/read-trace#list-the-spans-of-a-trace-in-pages). Give the `nextCursor` of one page as the `cursor` of the next.

```sh Request theme={null}
curl -s localhost:4318/v1/traces/find -d '{"limit": 2}'
```

```json 200 theme={null}
{"count":3,"traces":[{"traceId":"t3","rootSpanId":"r3","startedAt":3000,"endedAt":3200,"name":null,"userId":"u1","sessionId":null,"spanCount":2,"errorCount":0,"inputTokens":0,"outputTokens":0,"costNanos":0},{"traceId":"t2","rootSpanId":"r2","startedAt":2000,"endedAt":3000,"name":null,"userId":"u2","sessionId":null,"spanCount":2,"errorCount":0,"inputTokens":10,"outputTokens":5,"costNanos":100000}],"nextCursor":"eyJsaXN0IjoidHJhY2VzIiwic29ydCI6Im5ld2VzdCIsInRpbWUiOjIwMDAsImlkIjoidDIiLCJpZDIiOiIiLCJuIjoxfQ"}
```

## Fields

**sort** `string` (default: newest)

`"newest"` or `"oldest"`, by start time. Ties: `spanId`, then `traceId` (spans); `traceId` (traces); the session id (sessions). The span list of one trace is always oldest first.

**limit** `integer` (default: 50)

The most rows of one page, at most 10,000 (more: `400`). `0` returns only the count, on the routes that have a `count`.

**cursor** `string`

The `nextCursor` of the page before. Leave it out for the first page.

**nextCursor** `string | null`

Give it back as `cursor` for the next page. `null` on the last page.

## What a cursor promises

* A cursor is a position in the sort order (the key of the last row), not a saved result. The server reads each page as of its own call.
* Each page costs about as much as page 1. There is no offset.
* A row whose sort key does not change comes back once, in order, also while writes go on.
* A new row that sorts before the position is not returned, and does not shift later pages. With `"newest"`, that is a row newer than page 1. A new row that sorts after the position comes on a later page.
* A trace whose start moves during the walk (an earlier span arrives) can come twice or not at all.
* A cursor given with another `sort`, or to another list, is an error. So is a string that is not a cursor.

> [card] [Find traces](https://docs.magpiedb.com/reference/api/traces-find.md)
>
> The trace list, with its count and previews.

> [card] [Read pages of a trace](https://docs.magpiedb.com/queries/traces.md#read-the-next-page)
>
> A guide with page 1 and page 2.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.