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

# Delete a user's data

> Delete every trace of one user for a privacy request, then purge the bytes from the disk.

```sh theme={null}
curl -s localhost:4318/v1/traces/delete -H 'content-type: application/json' -d '{"userId": "user-42"}'
curl -s -X POST localhost:4318/v1/purge -H 'content-type: application/json'
```

A person asks you to delete their data (a GDPR request). The delete removes every trace of that user from all answers. The purge then takes the bytes off the disk.

## Try it

```sh theme={null}
magpie-server --dir ./traces
```

```sh theme={null}
"$REPO/scripts/send-trace.sh" --url http://127.0.0.1:4318 --user user-42 > /dev/null
"$REPO/scripts/send-trace.sh" --url http://127.0.0.1:4318 --user user-7 > /dev/null
curl -s localhost:4318/v1/traces/delete -H 'content-type: application/json' -d '{"userId": "user-42"}'; echo
curl -s -X POST localhost:4318/v1/purge -H 'content-type: application/json' | jq -c '{segmentsWithDeleted}'
curl -s localhost:4318/v1/traces/find -d '{"filter": {"userId": "user-42"}, "limit": 0}'
```

```text theme={null}
{"tracesDeleted":1,"spansDeleted":3,"scoresDeleted":0,"segmentsTouched":...,"segmentsWithDeleted":...}
{"segmentsWithDeleted":0}
{"count":0,"traces":[],"nextCursor":null}
```

`segmentsTouched` and `segmentsWithDeleted` count files of the store, so they depend on the commits before.

## How the two routes work

| | `POST /v1/traces/delete` | `POST /v1/purge` |
| - | - | - |
| takes | one of `{"userId": ...}`, `{"sessionId": ...}`, `{"traceIds": [...]}`, `{"filter": traceFilter}` (the filters of the [query guide](https://docs.magpiedb.com/queries/overview.md)) | nothing |
| does | Deletes whole traces: every span, the summary and the scores. A trace with spans of two users goes whole. | Writes again the files that still hold deleted bytes. With `"segmentsWithDeleted": 0`, no file of the store holds data deleted before the call. |
| answers | After the commit: from then on no query returns the data. A crash leaves the store before the delete or after it. | It can take minutes on a large store: give the client a long timeout. |
| needs | the `write` right, and `Content-Type: application/json` (`curl -d` alone sends another type: `415`) | the same |

Delete all the users of one request first, then purge once. A span that arrives after the delete is kept, also of the same user.

> [!WARNING]
>
> A delete and a purge do not touch copies outside the store folder: backups, exports, S3. Delete those by your own rule.

> [card] [Retention](https://docs.magpiedb.com/operations/data-lifecycle.md)
>
> Drop old spans by themselves.

> [card] [Masking](https://docs.magpiedb.com/operations/masking.md)
>
> Keep private data out of the store.


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