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

# How Magpie works

> The path of a trace from your app to the store, and the parts of the data: span, trace, session and score.

## From your app to the store

![An agent app sends traces with OpenTelemetry (HTTP port 4318 or gRPC port 4317) to magpie-server, the one writer, which stores them in one folder. The web viewer, the query API and MCP for AI agents read them.](https://mintcdn.com/magpie-f30b9567/Fvcn517wdKNPM8zZ/images/data-flow-light.png?fit=max\&auto=format\&n=Fvcn517wdKNPM8zZ\&q=85\&s=60dfbed6288353001a7cc557ba363e71)

With the server, a trace goes this way:

1. Your app or its framework makes spans with an OpenTelemetry SDK.
2. The app sends the spans over OTLP: HTTP on port 4318, gRPC on port 4317.
3. `magpie-server` maps each span to a Magpie span. With a mask policy (`--mask`, off by default), it replaces private data before it stores anything.
4. The server writes the spans to the store: one folder of files.
5. You ask questions in JSON over the query API, on port 4318. The read-only web viewer at `/` uses the same API.

With the library (`magpiedb` in Rust, Node.js or Python), there is no network part. Your app opens the store folder itself, then writes and queries it. Both ways use the same engine and write the same kind of store.

> [!WARNING]
>
> **One writer per store.** Only one process may write to a store folder at a time. A second writer is refused; read-only opens are fine. For many apps, send traces to one `magpie-server`.

New data is searchable after the next commit. The store commits 0.5 s after the first write that waits.

## The parts of the data

![A trace is one agent run. Each row is a span: the agent run, two model calls and a failed tool call. Magpie can ask about the whole run, search the text of prompts and replies, and add up tokens and cost per model, user or time range.](https://mintcdn.com/magpie-f30b9567/k2zClx60tU8szBgF/images/trace-anatomy-light.png?fit=max\&auto=format\&n=k2zClx60tU8szBgF\&q=85\&s=bb2210cd56e55ee386101e3407d5be91)

| Part | What it is | Main fields |
| - | - | - |
| Span | One step of a run: a model call, a tool call, an agent step. the ids, `kind`, `name`, `model`, `input`, `output`, `error`, tokens, cost, times, user, session, `attributes`, `events` | |
| Trace | One run of an agent: the spans with one `traceId`, a tree by `parentSpanId`. | the root span, the span count, the error count, the sums of tokens and cost |
| Session | A conversation: the traces with one `sessionId`. | its traces, sums, the first input and the last output |
| Score | A number, a yes/no or a label on a trace, a span or a session. It can come long after the trace: from a person, an LLM judge or a test. | `name`, `value`, `label`, `source`, `comment`, `at` |

A span with the same trace id and span id replaces the one before. So a retry makes no copy, and you can write a span again when it ends.

## Span kinds

`kind` tells what a step did. From OpenTelemetry, Magpie takes it from `gen_ai.operation.name`. With the library, you set it yourself.

| `kind` | The step | `gen_ai.operation.name` |
| - | - | - |
| `model_generation` | a model call | `chat`, `generate_content`, `text_completion`, `realtime_inference` |
| `tool_call` | a tool call | `execute_tool` |
| `agent_run` | an agent step | `invoke_agent` |
| the name as it is | other operations, for example `embeddings`, `retrieval`, `invoke_workflow` | the same name |

## What you can search and sum

| You want to | Fields |
| - | - |
| Find text by word, phrase, prefix or part of a word | `input` and `output` (`text`); the error message (`errorText`) |
| Match an exact value | `traceId`, `kind`, `model`, `userId`, `sessionId`, `name`, `service`, `environment`, `tag`, attribute values |
| Add up numbers, or get percentiles | tokens (input, output, cached, reasoning), cost, duration, errors, time to first token |
| Group the sums | model, kind, user, session, trace, name, tag, an attribute, or a time bucket |

Tokens and cost come from model calls and embeddings only. An agent span reports the sum of the model calls under it, so Magpie does not count those tokens twice.

Attribute values have no text search: an attribute filter matches a whole value.

> [card] [Quick start](https://docs.magpiedb.com/quickstart.md)
>
> Start the server, send a trace and ask questions.

> [card] [Queries](https://docs.magpiedb.com/queries/overview.md)
>
> Every query type, with examples.

> [card] [Send traces with OpenTelemetry](https://docs.magpiedb.com/guides/opentelemetry.md)
>
> The setup for your framework, and how Magpie maps a span.


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