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

# Errors and input rules

> What Node.js, Python and Rust raise when a call fails, the rules every span and query must follow, and what happens on a full disk.

```js Node.js theme={null}
try {
  await store.write([{ traceId: 't1', spanId: 's1', kind: 'agent_run', startedAt: Date.now(), inputToken: 5 }])
} catch (err) {
  console.error(err.message) // span 0: unknown field `inputToken`, expected one of ...
}
```

```python Python theme={null}
from magpiedb import MagpieError

try:
    store.write([{"traceId": "t1", "spanId": "s1", "kind": "agent_run", "startedAt": 1764547200000, "inputToken": 5}])
except MagpieError as err:
    print(err)  # span 0: unknown field `inputToken`, expected one of ...
```

```rust Rust theme={null}
match store.write(vec![Span::new("t1", "s1", "agent_run", 1_764_547_200_000)]) {
    Ok(n) => println!("{n} spans written"),
    Err(e) if e.disk_full() => eprintln!("no room on the disk: {e}"),
    Err(e) => return Err(e.into()),
}
```

The examples use an open `store` ([open a store](https://docs.magpiedb.com/libraries/overview.md#open-a-store)).

## What each language raises

| | Node.js | Python | Rust |
| - | - | - | - |
| An error of the engine (bad input, a closed or read-only store, a failed disk write) | The Promise rejects with an `Error` that has the engine's message. | `magpiedb.MagpieError`, a subclass of `Exception`, with the engine's message. | `magpiedb::Error`: `InvalidSpan`, `InvalidQuery`, `InvalidMask`, `ReadOnly`, `Io` or `Index`. |
| A value that JSON cannot hold | `NaN` becomes `null`, so it means "not set". | Raised before the engine sees the call: `ValueError` for NaN and infinity, `TypeError` for an object such as a `datetime`. | The types of the structs. |
| A call after `close` | Rejected. | `MagpieError`. | `close` takes the store. |
| A full disk | The message starts with `io: DISK_FULL:`. | The message starts with `io: DISK_FULL:`. | `err.disk_full()` is `true`. |

## Input rules

| Rule | What happens |
| - | - |
| A field the package does not know | An error, not ignored: a typo like `inputToken` must not lose data or widen a filter. The error names the field. |
| `null` or `None` | Means "not set". |
| Times | Unix milliseconds, as integers. Python: send times as `int` milliseconds, not as a `datetime`. |
| Integers in Node.js | Exact up to 2^53. A sum, a percentile or a whole-number group key above 2^53 is an error, because a JavaScript number cannot hold it exactly. |
| Integers in Python | Exact at every size the engine stores: 64-bit unsigned for tokens and sums, 64-bit signed for times. Larger numbers are an error. |
| Half of a UTF-16 surrogate pair | A string with one (`text.slice(0, n)` that cuts an emoji, or `"\ud83d"` in Python) is stored with U+FFFD for the half. The rest of the call is stored as it is. |
| One bad span or score in a batch | The whole batch is refused. |
| Depth | A span has at most 64 levels, a filter at most 32. In `attributes` and `events`, each list or object is one level deeper. In a filter, each `and`, `or`, `not`, and each span condition of a trace filter (`root`, `anySpan`), is one level deeper. A deeper span or filter is refused. |
| A long phrase | A phrase of 4,096 positions or more is refused. A position is a word, or a word of 256 bytes or more between two words. |
| A short piece in `contains` or `prefix` | A text of several pieces whose pieces match more than 16,384 different words in one segment is an error. Make the first or the last piece longer. |
| A write to a read-only store | An error (Rust: `Error::ReadOnly`). |
| A wrong mask rule | `open` fails. A write never fails for the policy. |

More rules of text search: [text search](https://docs.magpiedb.com/queries/text-search.md).

## When the disk is full

The store keeps free space on its volume: 5% of it, at least 16 MiB and at most 1 GiB. In Rust, the option `min_free_bytes` sets it; `Some(0)` turns it off.

When the free space is below the reserve, `write`, `upsert` and `writeScores` fail before the disk is full. Queries, commits, deletes, drops and the purge still work. Writes pass again when there is room.

## When the writer fails

If the writer fails, every write is refused and queries answer from the last commit, until the store is closed and opened again. No accepted write is lost: the open applies the write log again. In Rust, `health()` gives `Failed` with the reason.

> [card] [Write spans](https://docs.magpiedb.com/libraries/write-spans.md)
>
> The fields of a span, cost and masking.

> [card] [Errors and memory](https://docs.magpiedb.com/operations/errors-memory.md)
>
> What an error means when you run the server.


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