Token-Optimized Syntax Tree String IR Generator
Project description
Frontloading Agentic AI Code Context
Tostr is a CLI and MCP agent context engine which greatly reduces token costs and context bloat for agentic LLM coding assistants by pre-computing an llm-described AST with outputs in the highly-efficient .tost format.
Features
🌴 Pre-computed Abstract Syntax Tree
Tostr scrapes your project when you parse it, building a comprehensive Abstract Syntax Tree IR (Intermediate Representation) of the entire OOP code structure and stores it in a local SQLite database.
⛓️ Heuristic Dependency Graph Resolution
Tostr resolves dependencies between structures in your code, building a dependency graph to allow agents to traverse inbound or outbound method calls efficiently.
🔌 MCP and CLI interfaces
Tostr has both a CLI and MCP interface, allowing llms to boot up the mcp server for larger development sessions, while allowing agents or human developers to utilize the CLI for individual actions or quick, manual AST traversals.
⛓️💥 Automatic Incremental Change Diffs
While the MCP server is running, Tostr identifies the subtree of the AST which was updated on file save, add, or delete, then re-scrapes and re-describes exactly the section that was updated, ensuring that the AST is instantly up-to-date during development.
🗄️ Lightweight SQLite Cache
The AST IR and Dependency Graph is cached to an on-drive SQLite .db file to vastly increase efficiency of agent AST traversals, as well as allow the AST to be directly queried via sql commands.
💭 Semantic Vector Embedding
Using local ONNX (Open Neural Network Exchange) weights from the all-MiniLM-L6-v2 embedding model, Tostr embeds the descriptions of each struct, allowing for far more accurate semantic search of specific structs than the traditional line blocking approach.
🌍 Language Support Matrix
Tostr is designed to map the macro-architecture of your codebase. While all supported languages receive high-density Structural AST Skeletons and AI Semantic Descriptions, multi-hop cross-file dependency resolution is currently optimized specifically for deep backend monoliths (Java).
| Language | Structural AST Parsing | AI Semantic Descriptions | Cross-File Dependency Graph |
|---|---|---|---|
| ☕ Java | ✅ | ✅ | ✅ |
| 🐍 Python | ✅ | ✅ | ✅ |
| 🔷 TypeScript | 🚧 Coming Soon | 🚧 Coming Soon | 🚧 Coming Soon |
| 🎯 C# | 🚧 Coming Soon | 🚧 Coming Soon | 🚧 Coming Soon |
| 🐹 Go | 🚧 Coming Soon | 🚧 Coming Soon | 🚧 Coming Soon |
Tostr is still in active development, so this list will quickly expand and grow with more language support. If you want to add support for your favorite language, you can also take a look at CONTRIBUTING.md to help us out!
Note for AI Agents: For languages where dependency tracking is marked "Coming Soon," the MCP server will cleanly omit the dependency fields. Agents should rely on
tostr skeletonand semanticsearchto navigate these codebases.
60 Second Quickstart
Zero config required. Paste these into a terminal — shown for Claude Code; other agents below.
pipx install tostr # Installing the CLI onto your PATH
tostr add-agent claude --global # Tells the agent to prefer Tostr for navigation
claude mcp add tostr -- tostr start-mcp # connect the MCP server
cd path/to/project # Navigate to your project repository root
tostr parse . --no-llm # build the local AST cache (no API key needed)
tostr status . # confirm the parse succeeded
# now explore from the CLI — or just ask your agent:
tostr skeleton . --files-only
tostr search "authentication" --filter class
For richer descriptions and sharper semantic search, add a GEMINI_API_KEY and drop --no-llm — see Getting Started.
Getting Started
Prerequisites
- Requires Python 3.12+
- Requires a Google Gemini API Key for descriptions
Installation
Tostr is available on PyPI and can be installed via pip or pipx. Due to its dependencies, it is highly recommended to install it using pipx to keep it in an isolated environment:
pipx install tostr
If you don't have pipx, you can download it easily via
brew install pipxon mac orpython -m pip install --user pipx; python -m pipx ensurepathon windows.
Alternatively, you can install it via standard pip:
pip install tostr
If you wish to utilize tostr's struct descriptions, you will also need to configure a Google Gemini API key and save it as an environment variable. This is optional, as the embedding will just fall back to using code bodies and UIDs when a description isnt generated.
To create a new API key:
- Go to the Google AI Studio and log in with your google email.
- Once logged in, in the bottom left click the
Get API Keybutton. - In the top right, click
Create API Key. You may need to create a new project before making an API key. You can just name ittostr - Name the key something like
Tostr API Key. This name does not matter for the rest of the steps. - Click the button next to the new key that says
copy API keyto copy the string to your clipboard. It should be a long random string with 39 characters. - Save this key as an environment variable called
GEMINI_API_KEYon your computer.
DISCLAIMER: While tostr does not use any gemini features that require a payment method, you will very quickly hit rate limits on a free tier.
I would suggest setting up a payment method in the Google AI Studio so you can get the limits of the Tier 1 payment tier. Once set up, using tostr should cost only a couple cents per project if anything, since it uses the Gemini Flash-Lite model for all its description generation. You can very easily set a spend limit in Google's UI if you like by going to the Spend tab after creating your key.
Installing Environment Variables on Mac:
To expose your API key to tostr in a specific terminal session, run this command:
export GEMINI_API_KEY=[your api key]
This will only save the key in the current session. To save the key permanently and system-wide, follow the instructions here
Installing Environment Variables on Windows:
In order to save environment variables on Windows, follow these steps.
- Press the windows key and type
environment variables - Click
Edit the system environment variablesto open the System Properties window. - Decide where to store your variable.
- User variables: Only accessible by your specific Windows account.
- System variables: Accessible by all users on the computer (requires Administrator privileges).
- Click
New...under the chosen section - Enter
GEMINI_API_KEYin the name, and paste your API key from the Google AI Studio - Click OK on all open windows to save the settings.
Note: You must restart any open command prompts for them to recognize the new variable.
Connecting the MCP to your agent
Tostr can be used as an MCP (Model Context Protocol) server, allowing your favorite AI coding agent to interact directly with your project's AST and dependency graph.
Generic Configuration
Most MCP-compatible agents use a JSON configuration file. You can generally add Tostr by adding the following to your mcpServers configuration:
{
"mcpServers": {
"tostr": {
"command": "tostr",
"args": ["start-mcp"],
"env": {
"GEMINI_API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}
Note: If
tostris not in your system PATH, you may need to provide the absolute path to the executable (e.g.,/Users/YOUR_NAME/.local/bin/tostr). You can find this path by runningwhich tostron macOS/Linux orwhere tostron Windows.
Claude Code: one-line install
If you're on Claude Code, skip the JSON entirely — paste this into your terminal and you're connected:
claude mcp add tostr --env GEMINI_API_KEY=YOUR_API_KEY_HERE -- tostr start-mcp
or even simpler, if you configure your projects to use no-llm:
claude mcp add tostr -- tostr start-mcp
Claude Code's CLI writes the config for you, no file editing required.
Popular Agents with MCP Support
Below are instructions and links for setting up MCP servers in common AI coding environments:
- Claude Desktop: Official Setup Guide
- Cursor: Cursor MCP Documentation
- Cline (VS Code): Cline Documentation
- Codex: Codex Documentation
tostr add-agent — teach your agent to prefer Tostr
Connecting the MCP server gives your agent the Tostr tools; it doesn't tell it when to reach for them over raw read/grep. add-agent installs that guidance into your agent's instructions file (CLAUDE.md, .clinerules, etc.) so the agent defaults to skeleton/search/inspect for code navigation.
tostr add-agent claude # install into ./CLAUDE.md
tostr add-agent cursor # install into ./.cursor/rules/tostr.mdc
tostr add-agent all # install into every supported agent
tostr add-agent claude -g # install into your global ~/.claude/CLAUDE.md instead
tostr add-agent --list # show supported agents and their config paths
Supported agents: claude, cline, copilot, codex, cursor.
It is safe to re-run and non-destructive: the guidance is written between managed markers, so installing into a file that already has your own content just upserts that block and leaves everything else untouched (re-running an unchanged install is a no-op). Agents whose config is a dedicated file (Cursor's tostr.mdc) are written whole.
To uninstall, use tostr remove-agent — it strips the managed block (deleting the file only if it becomes empty) or removes the dedicated file:
tostr remove-agent claude
tostr remove-agent all
Available Flags (add-agent):
--global,-g: Install into the agent's global config instead of the current project. Only some agents have a global location (e.g.claude,codex). Default isFalse--force,-f: Overwrite a dedicated agent file (e.g. Cursor'stostr.mdc) even if it isn't Tostr-managed. Default isFalse--list,-l: List supported agents and where they install, then exit.--debug,--no-debug/-d,-nd: Enable debug logging. Default isFalse
Setting up Tostr
Tostr separates authoring configuration from building the cache:
tostr.toml(project root, committed) holds your project settings, and.tostrignore(project root, committed) holds your ignore rules. These are yours — you edit them and they survive any cache wipe..tostr/(hidden, gitignored) is generated and disposable.tostr parserebuilds it from scratch;tostr cleanremoves it.tostr.lock.json(project root, generated-but-committed) is an optional third category — the AST equivalent of apackage-lock.json. You produce it withtostr export, commit it, and it lets a teammate's firsttostr parsereuse your LLM-generated descriptions instead of paying to regenerate them. Seetostr exportbelow.
tostr init — scaffold project files (optional)
tostr init .
This lays down the editable project files so you have something concrete to configure:
- creates
tostr.tomlat the root, pre-filled with documented defaults; - creates
.tostrignoreat the root, materialized from the default templates (environment files, build artifacts,node_modules/,venv/,target/, etc.) for your language(s); - creates the empty
.tostr/directory and adds it to your.gitignore.
init does not parse and never needs an API key. It is also idempotent: it never overwrites an existing tostr.toml or .tostrignore (pass --force to overwrite). init is entirely optional — if you're happy with the defaults you can skip straight to tostr parse, which falls back to the same built-in defaults without writing any files.
Available Flags:
--force,-f: Overwrite existing authored files (tostr.toml,.tostrignore) instead of leaving them untouched. Default isFalse--debug,--no-debug/-d,-nd: Enable debug logging. Default isFalse
tostr parse — build the database
tostr parse .
This does the actual work: it parses the AST, resolves dependencies, generates descriptions, embeds them, and writes .tostr/cache.db. It reads your configuration (or the built-in defaults) and authors nothing. Run it whenever you want to (re)build the cache.
The --language flag overrides the configured language for this run only. If omitted, parse uses the language from tostr.toml (defaulting to auto, which parses every file with a supported extension and treats them all as valid dependency nodes). Choosing a specific language parses only that extension.
Tostr currently supports
.javaand.py, so the options for--languagearejavaandpython.
If you are running tostr on a project that already has an existing database but you want to reparse from the start, use the --no-cache flag.
If a committed tostr.lock.json is present (see tostr export), parse automatically seeds descriptions from it: for any struct whose code is unchanged since the lockfile was written (matched on a content hash), it reuses the committed description instead of calling the LLM, then re-embeds locally for free. This is what lets a teammate run git clone && tostr parse and get the shared descriptions without an API key for the unchanged majority of the code — only genuinely new or changed code hits the LLM.
The --llm flag selects which LLM strategy generates descriptions for this run only. Resolution is --llm > the strategy configured in tostr.toml > the gemini default. Gemini is the only built-in default and reads GEMINI_API_KEY from the environment; if that key is missing and no other strategy is configured, parse stops and tells you to configure a binding or set the key (use --no-llm to skip descriptions entirely). Pass --llm ollama to describe against a local Ollama model instead, or --llm none to disable description generation (equivalent to --no-llm).
Configuring a strategy's details (model name, host, etc.) is done per-strategy in
tostr.toml; see the strategy configuration docs for the available keys.
Available Flags:
--use-cache,--no-cache: Load the existing cache if it exists (use--no-cacheto force a full reparse from scratch). Default isTrue--language,-l: Override the configured language for this run (e.g.,java,python). Omit to usetostr.toml(defaults toauto).--llm: Override the LLM strategy for this run (gemini,ollama, ornoneto disable). Trumpstostr.toml. Omit to use the configured strategy (defaultgemini).--no-llm: Skip LLM-generated descriptions (no API key required); equivalent to--llm none. Embeddings still run, falling back to code context. Default isFalse--debug,--no-debug/-d,-nd: Enable debug logging. Default isFalse
Traversing the graph
Once the project is parsed, Tostr is ready to go! The CLI provides a rich, interactive way to explore your project's structure.
Project Skeleton
To see the high-level structure of your project, run:
tostr skeleton . --depth 1
Tostr will print a beautiful tree structure of your root and its direct children.
Available Flags:
--pretty,--raw: Pretty format output with line wrapping and indentation (disable for raw output). Default isTrue--depth,-d: Depth to traverse for skeleton generation. Default is4--files-only,-f: Only generate the skeleton for files, skipping individual classes/methods. Default isFalse--max-lines,-m: Maximum number of lines to include in the output. Default is500--debug,--no-debug: Enable debug logging. Default isFalse
Searching Structs
You can search for specific code components using semantic natural language queries:
tostr search "PID controller"
Tostr uses the llm described descriptions instead of source code for its vector embeddings, avoiding one of the major downfalls of codebase semantic search; raw code does not encapsulate surrounding context or intent, but the descriptions do, making for a far more consistent semantic search. Available Flags:
--filter,-f: Filter results by struct type (e.g.,class,method). Default is none (no filter)--top-k,-k: Number of results to return. Default is5--debug,--no-debug: Enable debug logging. Default isFalse
Inspecting Structs
Each struct (file, class, method, or field) can be inspected for deep detail, including its LLM-generated description and dependency graph:
tostr inspect C-c7766e98fa .
tostr inspect M-bc1cb7aeff --body .
Available Flags:
--body,--no-body: Attach the syntax-highlighted source code of the struct being inspected. Default isFalse--pretty,--raw: Pretty format output with line wrapping and indentation (disable for raw output). Default isTrue--max-lines,-m: Maximum number of lines to include in the output (useful for large classes). Default is500--debug,--no-debug: Enable debug logging. Default isFalse
Other Commands
Beyond traversing the graph, Tostr provides a handful of commands for managing the database, keeping it in sync, and running the MCP server. Every command accepts an optional path argument (defaulting to the current directory .) pointing at the project root, and every command supports --debug / --no-debug (-d / -nd) to enable debug logging.
tostr status
Show whether Tostr has built a cache for a project, along with the database location, size, last-updated time, and per-type struct counts.
tostr status .
Available Flags:
--debug,--no-debug/-d,-nd: Enable debug logging. Default isFalse
tostr watch
Watch the project for file changes and incrementally update the SQLite database as you save, add, or delete files. This runs in the foreground until interrupted (the MCP server performs the same incremental diffing automatically while running).
tostr watch .
Available Flags:
--debug,--no-debug/-d,-nd: Enable debug logging. Default isFalse
tostr clean
Remove the generated .tostr/ cache (the AST and dependency graph), so tostr parse can rebuild from scratch or to reclaim space. Your authored config (tostr.toml, .tostrignore) is preserved — clean && parse returns to a fresh build with your settings intact. Pass --purge to also delete the authored config for a full reset.
tostr clean .
Available Flags:
--purge: Also delete authored config (tostr.toml,.tostrignore), not just the generated.tostr/cache. Default isFalse--debug,--no-debug/-d,-nd: Enable debug logging. Default isFalse
tostr export
Snapshot the project's LLM-generated descriptions into a committed tostr.lock.json so teammates can reuse them instead of re-calling the LLM. Run it after a tostr parse produces descriptions, then commit the lockfile alongside your code:
tostr export .
On a teammate's machine, git clone && tostr parse then seeds those descriptions for free — every struct whose code hasn't changed (matched on a content hash) reuses your description and only re-embeds locally; no API key is needed for the unchanged majority. If the code has diverged, the affected structs simply regenerate, so a stale lockfile is self-healing.
The lockfile is only written by this command — parse reads it but never rewrites it, so running parse (or the live watcher) never dirties your git tree. Re-run tostr export whenever you want to refresh the committed descriptions. By default only descriptions are exported (vectors recompute for free from the local model); pass --with-vectors for literal zero recompute at the cost of a larger, merge-noisier file.
Available Flags:
--with-vectors: Also export embedding vectors, not just descriptions. Off by default. Default isFalse--debug,--no-debug/-d,-nd: Enable debug logging. Default isFalse
tostr start-mcp
Start the bare MCP server, which then awaits agent initialization over the Model Context Protocol. This is the command referenced in the MCP configuration above; you generally won't run it manually, as your agent launches it for you.
tostr start-mcp
This command takes no flags.
Contributing to Tostr
See CONTRIBUTING.md for instructions on how to contribute to the Tostr source code
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 tostr-0.6.0.tar.gz.
File metadata
- Download URL: tostr-0.6.0.tar.gz
- Upload date:
- Size: 90.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3375ff76a967a59b863c830023a734026cd7d64ce272372b955f8c8d822b5116
|
|
| MD5 |
c8fe8f67c900bfc14e5669f4761fe603
|
|
| BLAKE2b-256 |
253202deaa2e63939f94564dd215aec2988a0bff62e69432907de4c1f09f466f
|
Provenance
The following attestation bundles were made for tostr-0.6.0.tar.gz:
Publisher:
publish.yml on rubyTanuki/tostr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tostr-0.6.0.tar.gz -
Subject digest:
3375ff76a967a59b863c830023a734026cd7d64ce272372b955f8c8d822b5116 - Sigstore transparency entry: 1920973343
- Sigstore integration time:
-
Permalink:
rubyTanuki/tostr@0376e3f6812116ce5a9003909a3c663ac0a6b894 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/rubyTanuki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0376e3f6812116ce5a9003909a3c663ac0a6b894 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tostr-0.6.0-py3-none-any.whl.
File metadata
- Download URL: tostr-0.6.0-py3-none-any.whl
- Upload date:
- Size: 96.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6ca3e8d44f24144815223c7a7931dbafa1326422251e7f1397265ab03bc697e
|
|
| MD5 |
a9eaf349efd08bea2a9345a0517830d3
|
|
| BLAKE2b-256 |
57f3887c93e4a932849b3452b60736c4a860f3f04975ac50abfa4e5385074104
|
Provenance
The following attestation bundles were made for tostr-0.6.0-py3-none-any.whl:
Publisher:
publish.yml on rubyTanuki/tostr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tostr-0.6.0-py3-none-any.whl -
Subject digest:
a6ca3e8d44f24144815223c7a7931dbafa1326422251e7f1397265ab03bc697e - Sigstore transparency entry: 1920973446
- Sigstore integration time:
-
Permalink:
rubyTanuki/tostr@0376e3f6812116ce5a9003909a3c663ac0a6b894 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/rubyTanuki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0376e3f6812116ce5a9003909a3c663ac0a6b894 -
Trigger Event:
release
-
Statement type: