MCP server for AI agents to record and query their reasoning steps. SQLite-backed, zero-dependency beyond mcp SDK.
Project description
SciTrace
An MCP server that moves AI agents' reasoning chains out of the context window and into a database.
One line of MCP config. Two tools. The agent calls build_trace to record each reasoning step and query_trace to pull history back on demand. Data lives in SQLite, not in the context window.
๐ See it in 30 seconds:
pip install scitrace
scitrace-demo --viz # writes a perovskite research demo chain + renders the visualization
Open the generated scitrace-demo.html in a browser: hover nodes for summaries, click for the detail panel, double-click to collapse subtrees โ find the purple dashed edge (backtrack), the most interesting moment of a reasoning chain.
Why not prompts or skills?
Prompts and skills can force an agent to emit structured reasoning, but they cannot do the following five things.
1. The context window is a scarce resource, not a warehouse
| Prompt-instructed output | SciTrace | |
|---|---|---|
| Context after 10 steps | 10 full JSON blocks (500โ1500 tokens) stacked in the window | 10 short call records; data lives in SQLite |
| After 50 steps | The agent starts "forgetting" earlier steps โ the window fills with history | Context stays clean; query_trace fetches exactly what's needed |
| Across sessions | New session = everything lost | SQLite persists; new sessions query directly |
With prompts, reasoning chains accumulate and steal token budget from the real task. SciTrace moves the data out โ the context window is for thinking, SQLite is for storage.
2. Prompts only write; SciTrace can query
Prompt: "What was that earlier hypothesis again?" โ agent rummages through 3000 tokens of chat history โ maybe finds it, maybe not
SciTrace: query_trace(type="hypothesis") โ exact result, no chat history involved.
Structured queries = type=backtrack finds every failed backtrack point, type=experiment lists all experiments, trace_id=xxx returns the full chain. Prompts cannot do this.
3. A DAG is not flat
Prompts force agents to output sequential lists. But scientific reasoning is not linear โ it forks, backtracks, and has dependencies.
h1 (hypothesis) โ a1 (analysis) โ e1 (experiment) โ b1 (backtrack) โ e2 (revision) โ v1 (verification) โ c1 (conclusion)
โ
parent_id declares the dependency explicitly
parent_id turns a flat list into a directed acyclic graph. This graph structure doesn't consume context โ it lives in SQLite foreign-key relationships.
4. Write once, every agent can use it
| Prompt | Skill | SciTrace | |
|---|---|---|---|
| Claude | One per agent | One per agent | โ Same MCP config |
| Cursor | One per agent | โ | โ Same MCP config |
| Hermes | One per agent | One per agent | โ Same MCP config |
| Codex | One per agent | โ | โ Same MCP config |
MCP is a protocol standard. Write the server once and every MCP-compatible agent gets reasoning tracing automatically. No need to port prompts per agent.
5. Data can be consumed by programs
Structured output produced by prompts is readable only by an LLM. SciTrace's data lives in SQLite โ any tool can read it:
Python analysis scripts โ read SQLite directly
Visualization โ scitrace-viz renders an HTML report
CI/CD pipelines โ sqlite3 CLI queries
Jupyter โ import sqlite3 and analyze
No LLM required โ the consumer of the data can be code.
Architecture
Agent (Claude/Cursor/Hermes/Codex)
โ
โ MCP protocol (stdio)
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SciTrace MCP Server โ
โ โ
โ build_trace โ writes โ
โ query_trace โ reads โ
โ โ
โ โ SQLite โ
โ steps table โ
โ - id, parent_id (DAG) โ
โ - type (6 step types) โ
โ - summary, artifacts โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
Quick start
pip install scitrace
Add to your MCP client config:
{
"mcpServers": {
"scitrace": {
"command": "python",
"args": ["-m", "scitrace"]
}
}
}
The agent can now call build_trace and query_trace.
Storage
| Item | Default | Override |
|---|---|---|
| Database path | ~/.scitrace/traces.db |
SCITRACE_DB env var, or --db <path> in MCP args |
| Visualization output dir | current working directory | SCITRACE_OUTPUT env var |
{
"mcpServers": {
"scitrace": {
"command": "python",
"args": ["-m", "scitrace", "--db", "/path/to/custom.db"]
}
}
}
Visualization
pip install ships a scitrace-viz command โ it renders a reasoning chain as fully offline, interactive HTML (hand-drawn SVG DAG, zero external dependencies, works in air-gapped environments):
scitrace-viz # visualize the most recent trace
scitrace-viz <trace_id> # visualize a specific trace
scitrace-viz --out ./viz # specify the output directory
scitrace-viz --index # generate an overview index.html for all traces
scitrace-viz --theme dark # set the initial theme (switchable in-page)
- Hover a node for the full summary; click for a detail panel (parent/children, artifact file links)
- Double-click to collapse subtrees; wheel zoom, drag pan, one-click fit
- Light/dark theme toggle (remembered in localStorage); cyclic reasoning chains automatically fall back to a timeline layout
- Databases from v0.1.x are migrated automatically on first open; the original file is backed up as
traces.db.bak-<date>
Make the agent actually record
Installing the MCP server is only the first step: agents won't call build_trace on their own until you tell them to in their config. Official drop-in templates (โค10 lines each):
| Client | Template | Where to put it |
|---|---|---|
| Claude Desktop | prompts/claude-desktop.md |
Project Instructions / CLAUDE.md |
| Cursor | prompts/cursor.md |
.cursor/rules/scitrace.mdc |
| Codex CLI | prompts/codex-agents.md |
AGENTS.md in the project root |
| Hermes | prompts/hermes.md |
system prompt / skill |
Four conventions are enough:
- When to record: call
build_traceafter each verifiable reasoning subtask โ not after every sentence - ID conventions:
step_idonly needs to be unique within a trace; use a meaningfultrace_id(e.g.perovskite-2026) - Record dead ends explicitly as
type=backtrackโ the most valuable node when reviewing - Cross-session recovery: start a new session with
query_trace(trace_id=...)instead of asking the user to re-explain
The two tools
build_trace
Records a reasoning step. The agent calls it after each verifiable subtask.
| Parameter | Description |
|---|---|
step_id |
Unique identifier for this step |
trace_id |
Which reasoning chain this step belongs to |
type |
hypothesis / analysis / experiment / verification / conclusion / backtrack |
summary |
One-line summary of what this step did |
parent_id |
Which step this depends on (builds the DAG) |
artifacts |
Associated file paths |
query_trace
Queries historical reasoning steps.
| Parameter | Description |
|---|---|
trace_id |
Filter by reasoning chain |
type |
Filter by step type |
limit |
Max steps returned (default 50, max 1000) |
Example
A complete reasoning chain:
build_trace: { "step_id": "h1", "trace_id": "exp-001", "type": "hypothesis", "summary": "Assume P != NP" }
build_trace: { "step_id": "a1", "trace_id": "exp-001", "type": "analysis", "summary": "SAT is hard", "parent_id": "h1" }
build_trace: { "step_id": "e1", "trace_id": "exp-001", "type": "experiment", "summary": "Run benchmarks", "parent_id": "a1", "artifacts": ["results.csv"] }
build_trace: { "step_id": "c1", "trace_id": "exp-001", "type": "conclusion", "summary": "Conclusion: ...", "parent_id": "e1" }
query_trace: { "trace_id": "exp-001" } โ the full chain
query_trace: { "type": "experiment" } โ all experiment steps
query_trace: { "limit": 10 } โ the 10 most recent steps
Development
git clone https://github.com/Mobai-read/scitrace
cd scitrace
pip install -e ".[dev]"
pytest
See CONTRIBUTING.md for the full contribution workflow.
Summary comparison
| Prompt | Skill | SciTrace | |
|---|---|---|---|
| Data location | context window | context window | SQLite |
| Cross-session persistence | โ | โ | โ |
| Structured queries | โ | โ | โ |
| DAG dependencies | โ | โ | โ (parent_id) |
| Program-readable | โ | โ | โ (SQLite) |
| Multi-agent | one per agent | one per agent | โ one config |
| Long reasoning chains | blows up the context | blows up the context | context stays clean |
Documentation
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scitrace-0.2.0.tar.gz.
File metadata
- Download URL: scitrace-0.2.0.tar.gz
- Upload date:
- Size: 35.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8978f717c3dce0f2a3bbf204cc5d0fb60ab0ca267d53ceaa0ca868cf73f389e
|
|
| MD5 |
a42368c71970b7e7989b33787336273e
|
|
| BLAKE2b-256 |
cc72a52ad23c0f233b15a2beb6b90116889ad7a19c071f479950877f1220178f
|
File details
Details for the file scitrace-0.2.0-py3-none-any.whl.
File metadata
- Download URL: scitrace-0.2.0-py3-none-any.whl
- Upload date:
- Size: 22.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
349ec0b0cce8a2f76d7803535c2ed6724dbf67e94064326f36afd440d4f81199
|
|
| MD5 |
787e7fea5f7820320cbdcab09ce166f4
|
|
| BLAKE2b-256 |
437d97c5cdcfb0b7a86e13cf28c1f63e6f167661369e601da1498b9ffb61718c
|