> ## 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).

# Find spans

> POST /v1/search: the spans that match a filter, newest first, in pages, with optional previews of their input and output.

`POST /v1/search` returns the ids of the spans that match a filter, in pages. Right: `read`.

```sh Request theme={null}
curl -s localhost:4318/v1/search -d '{"filter": {"text": {"words": "refund"}}, "limit": 3}'
```

```json 200 theme={null}
{"spans":[{"traceId":"t3","spanId":"tl3","startedAt":3100},{"traceId":"t3","spanId":"r3","startedAt":3000},{"traceId":"t2","spanId":"m2","startedAt":2100}],"nextCursor":"eyJsaXN0Ijoic3BhbnMiLCJzb3J0IjoibmV3ZXN0IiwidGltZSI6MjEwMCwiaWQiOiJtMiIsImlkMiI6InQyIiwibiI6MX0"}
```

## Body

**filter** `object` (default: \{})

A [span filter](https://docs.magpiedb.com/reference/api/filters.md#span-filter). Left out: every span.

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

`"newest"` or `"oldest"`, by `startedAt`. Ties: `spanId`, then `traceId`.

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

At most 10,000.

**cursor** `string`

The `nextCursor` of the page before ([Lists and cursors](https://docs.magpiedb.com/reference/api/pagination.md)).

**previewChars** `integer`

Adds `inputPreview` and `outputPreview` to each row: the first `previewChars` characters of the span's `input` and `output`. The server reads the stored span of each row for this. Left out: rows have no such fields.

## Answer

**spans** `object[]`

The matching spans of this page.

**properties**

**traceId** `string`

**spanId** `string`

**startedAt** `integer`

Start time, Unix ms.

**inputPreview** `string`

Only with `previewChars`.

**outputPreview** `string`

Only with `previewChars`.

**nextCursor** `string | null`

The `cursor` of the next page. `null` on the last page.

To read a whole span, use [`GET /v1/traces/:id/spans/:spanId`](https://docs.magpiedb.com/reference/api/read-trace#get-one-span).

> [card] [Count spans](https://docs.magpiedb.com/reference/api/count.md)
>
> Only the number of matches.

> [card] [Find text](https://docs.magpiedb.com/queries/text-search.md)
>
> A guide to words, phrases and pieces of words.


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