<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/i-built-a-code-ast-mcp-that-saves-70-tokens-and-went-viral-54k-views--a57bmlkp3" -->

---
title: I Built a Code AST MCP That Saves 70% Tokens and Went...
description: An open-source MCP server called cocoindex-code uses tree-sitter AST parsing and local semantic embeddings to give AI coding agents (Claude Code, Codex,...
canonical: https://daily.dev/posts/i-built-a-code-ast-mcp-that-saves-70-tokens-and-went-viral-54k-views--a57bmlkp3
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: I Built a Code AST MCP That Saves 70% Tokens and Went Viral (54K+ Views) | daily.dev
og:description: An open-source MCP server called cocoindex-code uses tree-sitter AST parsing and local semantic embeddings to give AI coding agents (Claude Code, Codex,...
og:url: https://daily.dev/posts/i-built-a-code-ast-mcp-that-saves-70-tokens-and-went-viral-54k-views--a57bmlkp3
og:image: https://api.daily.dev/og/posts/A57BmLkP3.png
og:image:alt: I Built a Code AST MCP That Saves 70% Tokens and Went Viral (54K+ Views)
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# I Built a Code AST MCP That Saves 70% Tokens and Went Viral (54K+ Views)

**[AI](https://daily.dev/sources/ai)** · [@badmonster0](https://daily.dev/badmonster0) · 3 min read · 6 upvotes · 2 comments

## Summary

An open-source MCP server called cocoindex-code uses tree-sitter AST parsing and local semantic embeddings to give AI coding agents (Claude Code, Codex, Cursor) structured understanding of codebases instead of dumping entire files into context. It claims 70% token savings, requires no API keys or config, installs in one command, supports 20+ languages, and stores everything locally via SQLite. Built on a Rust-based incremental indexing engine, it only re-processes changed files. The project reached 54K+ views on X and 520+ stars on GitHub shortly after launch.

## Content

Last week, I open-sourced a lightweight Code MCP server [https://github.com/cocoindex-io/cocoindex](https://github.com/cocoindex-io/cocoindex) that uses AST (Abstract Syntax Tree) parsing to give coding agents semantic understanding of your codebase. It went viral on X with 54K+ views.

Here's the tweet that started it all:

{% embed [https://x.com/RoundtableSpace/status/2031366453153157139](https://x.com/RoundtableSpace/status/2031366453153157139) %}

## The Problem: Coding Agents Are Burning Tokens

If you've used Claude Code, Codex, Cursor, or any AI coding agent on a real codebase, you've probably noticed: they dump entire files into context just to understand your code structure. That's expensive, slow, and wasteful.

The agent doesn't need your whole file. It needs to know _what functions exist, what classes are defined, and how they relate to each other_.

## The Solution: AST-Based Semantic Code Search

I built [cocoindex-code](https://github.com/cocoindex-io/cocoindex-code) - a super lightweight embedded MCP that:

- **Parses your code into ASTs** using tree-sitter, extracting meaningful chunks (functions, classes, methods)
- **Creates semantic embeddings** of those chunks
- **Lets your coding agent search by meaning**, not just text matching
- **Only re-indexes changed files** - built on a Rust-based incremental indexing engine

The result? **70% token savings** and noticeably faster coding agent responses.

## 1-Minute Setup - No Config Needed

For Claude Code:

```
pipx install cocoindex-code
claude mcp add cocoindex-code -- cocoindex-code
```

For Codex:

```
codex mcp add cocoindex-code -- cocoindex-code
```

That's it. No database, no API keys, no config files. It just works.

## How It Works Under the Hood

1. **Tree-sitter parsing** breaks your code into semantic chunks (functions, classes, etc.) across 20+ languages
2. **Local embedding model** (SentenceTransformers) creates vector representations - completely free, no API key needed
3. **SQLite + vector search** stores everything locally and portably
4. **Incremental indexing** via [CocoIndex](https://github.com/cocoindex-io/cocoindex) (Rust engine) means only changed files get re-processed

When your agent needs to find code, it calls the `search` MCP tool with a natural language query and gets back exactly the relevant code chunks with file paths and line numbers.

## Why It Went Viral

I think people resonated with a few things:

1. **Real pain point** - everyone using coding agents feels the token burn
2. **Zero friction** - one pip install and one MCP add command
3. **No vendor lock-in** - works with Claude, Codex, Cursor, or any MCP-compatible agent
4. **Open source (Apache 2.0)** - you can inspect every line of code
5. **No API keys required** - the default embedding model runs locally for free

## Supported Languages

Python, JavaScript/TypeScript, Rust, Go, Java, C/C++, C#, Ruby, Kotlin, Swift, SQL, Shell, and more. It uses tree-sitter grammars so adding new languages is straightforward.

## What's Next

We're actively working on:

- Better embedding models optimized for code (try `nomic-ai/CodeRankEmbed` with a GPU)
- Enterprise features for large codebases and shared indexing across teams
- More MCP tools beyond search

The repo is at **[github.com/cocoindex-io/cocoindex-code](https://github.com/cocoindex-io/cocoindex-code)** - 520+ stars and growing fast.

Built with [CocoIndex](https://github.com/cocoindex-io/cocoindex), our open-source Rust-based data indexing framework.

Would love to hear your experience if you try it out. Drop a comment or open an issue on GitHub!

## Similar posts on daily.dev

- [AI-Powered Code Editor Cursor Introduces Dynamic Context Discovery to Improve Token-Efficiency](https://daily.dev/posts/ai-powered-code-editor-cursor-introduces-dynamic-context-discovery-to-improve-token-efficiency-nggcllbtk) · InfoQ · 1 upvotes · 0 comments
- [I Made MCP 94% Cheaper \(And It Only Took One Command\)](https://daily.dev/posts/i-made-mcp-94-cheaper-and-it-only-took-one-command--hafutjzqd) · Hacker News · 3 upvotes · 0 comments
- [Why use so many tokens when a few do the trick?](https://daily.dev/posts/why-use-so-many-tokens-when-a-few-do-the-trick--uvekb2vuw) · Product Hunt · 4 upvotes · 1 comments
- [How We Cut Our Claude Code Token Usage 2.8x\!](https://daily.dev/posts/how-we-cut-our-claude-code-token-usage-2-8x--p2fzdwf2l) · Daily Dose of Data Science \| Avi Chawla \| Substack · 0 upvotes · 0 comments

---

Tags: [#vector-search](https://daily.dev/tags/vector-search), [#mcp](https://daily.dev/tags/mcp)

[View this post on daily.dev](https://daily.dev/posts/i-built-a-code-ast-mcp-that-saves-70-tokens-and-went-viral-54k-views--a57bmlkp3)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/i-built-a-code-ast-mcp-that-saves-70-tokens-and-went-viral-54k-views--a57bmlkp3","headline":"I Built a Code AST MCP That Saves 70% Tokens and Went Viral (54K+ Views)","text":"An open-source MCP server called cocoindex-code uses tree-sitter AST parsing and local semantic embeddings to give AI coding agents (Claude Code, Codex, Cursor) structured understanding of codebases instead of dumping entire files into context. It claims 70% token savings, requires no API keys or config, installs in one command, supports 20+ languages, and stores everything locally via SQLite. Built on a Rust-based incremental indexing engine, it only re-processes changed files. The project reached 54K+ views on X and 520+ stars on GitHub shortly after launch.","url":"https://daily.dev/posts/i-built-a-code-ast-mcp-that-saves-70-tokens-and-went-viral-54k-views--a57bmlkp3","datePublished":"2026-03-12T00:32:00.511Z","dateModified":"2026-03-12T00:32:19.382Z","author":{"@type":"Person","name":"LJ","url":"https://daily.dev/badmonster0","image":"https://avatars.githubusercontent.com/u/1772842?v=4","description":"data for ai","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":1450}},"image":"https://media.daily.dev/image/upload/s--PE9YTsYT--/f_auto/v1773273488/posts/UrmTjRYU6?_a=BAMAMiiu0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":6},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":2}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/squads/ai","name":"AI"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"AI","item":"https://daily.dev/squads/ai"},{"@type":"ListItem","position":3,"name":"I Built a Code AST MCP That Saves 70% Tokens and Went Viral (54K+ Views)"}]}
```

