A repo called claude-context just crossed 7,260 stars on GitHub. It gained 873 stars today alone. The project does one thing and does it well: it uses semantic search via the Model Context Protocol to inject only the relevant code snippets into an AI agent's prompt, instead of loading entire directories.

That single idea, selective context via tool calls, is a pattern that changes how we build with AI coding agents. This piece covers what MCP is, how claude-context works, why this pattern matters more than the specific tool, and how to set it up yourself.


The Problem: Token Bloat From Wholesale Context

Here is how most people use AI coding agents today. You open a large codebase. You tell the agent "fix the auth bug." The agent needs context. So it reads files. Then more files. Then the imports in those files. Pretty soon, 200,000 tokens of source code sit in the context window.

That approach has three problems.

Cost. Token pricing is linear. A 200K-token prompt at GPT-4-class pricing runs real money per query. Do that dozens of times a day and your API bill hurts.

Noise. Most of the code you loaded has nothing to do with auth. The agent wades through database migration scripts and CSS files looking for the one function that validates JWTs. Irrelevant tokens distract the model. Accuracy drops.

Window exhaustion. Context windows are finite. Load 150K tokens of code and you have little room left for the agent's reasoning, your instructions, or the response. The agent hits the ceiling and starts truncating or losing track of its own work.

The root cause is the same in every case. You gave the agent everything instead of what it needed. Wholesale context loading is the default because it is easy. The agent can just glob a directory. But easy and correct are different things.


What Is the Model Context Protocol

The Model Context Protocol, or MCP, is an open standard Anthropic released in November 2024. It defines a structured way for AI applications to connect to external data sources and tools.

MCP uses JSON-RPC 2.0 messages over a stateful connection. Three roles exist in every MCP setup.

  • Hosts. The LLM application that starts the connection. Claude Code, Cursor, VS Code with Copilot, Gemini CLI. These are the hosts.
  • Clients. Connectors inside the host that manage individual server connections.
  • Servers. Services that provide context and capabilities to the AI model.

Servers expose three kinds of features.

  • Resources. Data the model reads. File contents, database rows, API responses.
  • Tools. Functions the model can call. Search, compute, transform.
  • Prompts. Templated messages and workflows.

The architecture mirrors the Language Server Protocol. LSP standardized how editors talk to language servers. MCP standardizes how AI applications talk to data and tool providers. One protocol, many integrations. No more bespoke connectors for every data source.

MCP takes inspiration from LSP in another way. Before LSP, every editor needed a custom plugin for every language. After LSP, one language server served them all. MCP aims for the same network effect. One MCP server can serve Claude Code, Cursor, Windsurf, Gemini CLI, Codex CLI, VS Code, and any future MCP-compatible client.


How claude-context Works

Claude-context is an MCP server built by Zilliz, the company behind the Milvus vector database. It gives AI coding agents semantic code search over your entire codebase.

The flow has two phases.

Phase 1: Indexing

When you run claude-context for the first time in a project, you tell the agent "index this codebase." The MCP server walks your source tree. It reads every file. It chunks each file into segments. It sends each segment to an embedding model, by default OpenAI's text-embedding-3-small. The model converts each chunk into a vector, a fixed-length array of floating-point numbers that captures the semantic meaning of the code.

Those vectors go into Milvus, a vector database that runs on Zilliz Cloud. Milvus indexes the vectors using approximate nearest neighbor search algorithms. The result is a searchable representation of your entire codebase, stored by meaning rather than by filename.

The indexing step runs once per codebase. After that, the vector database holds your code's semantic map.

Phase 2: Search at Query Time

When you ask the agent a question like "find functions that handle user authentication," the agent calls the claude-context MCP tool. The tool takes your natural-language query, embeds it with the same model, and searches the vector database for the closest matching code chunks.

Only the top results come back. Maybe 5 to 20 code snippets, totaling a few thousand tokens instead of hundreds of thousands. The agent gets precisely the context it needs, nothing more.

This is the core pattern. The agent does not read the whole directory. It asks a tool to find the relevant parts. The tool, powered by vector search, returns a small, focused context window. The agent reasons over that targeted context instead of wading through noise.

What the Agent Sees

From the agent's perspective, claude-context registers as a set of MCP tools. The key ones are:

  • index_codebase or similar. Walks the project, chunks files, embeds them, stores in Milvus.
  • search_code. Takes a natural language query, searches the vector database, returns matching code snippets with file paths and line numbers.
  • checkindexingstatus. Reports whether the codebase has been indexed and whether indexing is complete.

The agent calls these tools like it calls any other tool. No special handling required. The MCP protocol makes the tool discoverable and callable through the standard interface.


Why This Pattern Matters

Claude-context is one implementation. The pattern it demonstrates is bigger than any single tool. The pattern is this: tool-provided selective context beats prompt-stuffed wholesale context.

Here is why.

Cost Drops Dramatically

A large monorepo might contain 2 million lines of code. At roughly 1 token per 4 characters, that is roughly 10 million tokens. Loading all of it into a prompt is impossible for current context windows and absurdly expensive even if it were possible.

With selective context injection, you embed the query and retrieve the top 10 to 20 chunks. You pay for maybe 5,000 tokens of code context per query instead of millions. That is a cost reduction of 99% or more on the code-context portion of your bill.

Signal-to-Noise Ratio Improves

When you load an entire directory, the model sees everything. Utility functions unrelated to your task. Test fixtures. Configuration files for services you are not touching. Every irrelevant token is noise that can mislead the model or dilute its attention on the relevant code.

Semantic search filters for relevance before the model ever sees the code. The model receives a context window full of signal, not a haystack with a needle buried somewhere inside.

Context Window Stays Open

Current top-tier models have context windows of 128K to 200K tokens. That sounds large until you load a big codebase and discover you have 15K tokens left for the model's own reasoning.

Selective context injection uses a small fraction of the window. The rest is available for the agent's chain-of-thought reasoning, your instructions, conversation history, and the output you actually want.

It Scales

A 10,000-line project works fine with wholesale context loading. A 100,000-line project starts to strain. A million-line project breaks the approach entirely.

Selective context injection scales linearly on the query side. The embedding and search cost grows with codebase size during indexing. But at query time, you always retrieve a bounded number of chunks. Whether your codebase is 10K lines or 10M lines, the token cost of the retrieved context stays the same.

It Composes With Other Tools

MCP tools are composable. Your agent can call claude-context to find relevant code, then call a different MCP server to query your production logs, then call another to run tests. Each tool provides targeted context for its domain. The agent assembles a focused, multi-source context instead of a bloated, single-source dump.


The Broader Pattern: RAG for Agents

If you have worked with Retrieval-Augmented Generation, you recognize this pattern. RAG embeds a document corpus, searches it at query time, and feeds the top results to the model. Claude-context applies the same idea to source code, delivered through MCP tool calls instead of prompt engineering.

The innovation is not the retrieval. The innovation is the delivery mechanism. MCP tool calls let the agent decide when it needs context and what to search for. The agent drives the retrieval. It calls the search tool with a specific query, gets specific results, and reasons over them. Then it can call again with a refined query if needed.

This is more flexible than pre-loading context. It is more targeted than loading a directory. It is more dynamic than static RAG pipelines that run outside the agent loop.

The pattern generalizes beyond code search. Any MCP server that provides selective context, whether from documentation, tickets, logs, or databases, follows the same principle. Tool-provided context, called on demand, beats prompt-stuffed context loaded wholesale.


Practical Setup: Getting Started With claude-context

Here is how to set up claude-context for Claude Code. The process is similar for other MCP clients.

Prerequisites

  • Node.js version 20 or later (but below 24.0.0, which is incompatible)
  • An OpenAI API key for the embedding model
  • A Zilliz Cloud account for the vector database (free tier available)

Step 1: Get Your API Keys

Sign up at Zilliz Cloud and copy your API key. Sign up at OpenAI and copy your API key.

Step 2: Add the MCP Server

Run this command in your terminal:

claude mcp add claude-context \
  -e OPENAI_API_KEY=sk-your-openai-api-key \
  -e MILVUS_ADDRESS=your-zilliz-cloud-public-endpoint \
  -e MILVUS_TOKEN=your-zilliz-cloud-api-key \
  -- npx @zilliz/claude-context-mcp@latest

This tells Claude Code to register a new MCP server named claude-context. When Claude Code starts a session, it will launch this server as a subprocess using stdio transport.

Step 3: Index Your Codebase

Open your project directory and start Claude Code:

cd your-project-directory
claude

Tell the agent:

Index this codebase

The agent will call the index tool. Wait for indexing to complete. You can check with:

Check the indexing status

Step 4: Search

Now ask natural-language questions about your code:

Find functions that handle user authentication
Where is the database connection pool configured?
Show me the API route handlers for the payments module

The agent calls the search tool, gets back targeted code snippets, and works with those instead of reading every file.

Other Clients

The same MCP server works with Cursor, Windsurf, VS Code, Gemini CLI, Codex CLI, Cline, Roo Code, Augment, Claude Desktop, and any MCP-compatible client. The configuration format varies slightly between clients. The pattern is always the same: register the server command, provide the environment variables, restart the client.

For Cursor, add this to ~/.cursor/mcp.json:

{
  "mcpServers": {
    "claude-context": {
      "command": "npx",
      "args": ["-y", "@zilliz/claude-context-mcp@latest"],
      "env": {
        "OPENAI_API_KEY": "your-openai-api-key",
        "MILVUS_ADDRESS": "your-zilliz-cloud-public-endpoint",
        "MILVUS_TOKEN": "your-zilliz-cloud-api-key"
      }
    }
  }
}

For Gemini CLI, add this to ~/.gemini/settings.json:

{
  "mcpServers": {
    "claude-context": {
      "command": "npx",
      "args": ["@zilliz/claude-context-mcp@latest"],
      "env": {
        "OPENAI_API_KEY": "your-openai-api-key",
        "MILVUS_TOKEN": "your-zilliz-cloud-api-key"
      }
    }
  }
}

For Codex CLI, add this to ~/.codex/config.toml:

[mcp_servers.claude-context]
command = "npx"
args = ["@zilliz/claude-context-mcp@latest"]
env = { "OPENAI_API_KEY" = "your-openai-api-key", "MILVUS_TOKEN" = "your-zilliz-cloud-api-key" }
startup_timeout_ms = 20000

Custom Embedding Models

The default embedding model is OpenAI's text-embedding-3-small. You can switch to text-embedding-3-large for better retrieval quality, or to Voyage AI's voyage-code-3 for code-specific embeddings. Set the appropriate environment variables when you register the MCP server.


Limitations and Tradeoffs

No approach is free of tradeoffs. Here are the ones that matter.

Indexing is not free. You pay for embedding API calls when you index. For a large codebase, this can be significant. You also pay for Zilliz Cloud storage. The free tier covers small projects. Larger codebases need a paid plan.

Index staleness. Your code changes. The index does not update automatically. You need to re-index when you make significant changes. Some workflows solve this with git hooks that trigger re-indexing on push or merge.

Embedding quality matters. The search is only as good as the embeddings. Generic text embeddings miss code-specific patterns. Code-specific embeddings like voyage-code-3 perform better but cost more. Test both on your codebase.

Latency. Each search call adds a network round trip to the embedding API and the vector database. For a single query, this is 200 to 500 milliseconds. For an agent making many search calls in a loop, latency compounds.

Not a replacement for understanding project structure. Semantic search finds relevant code. It does not give the agent a mental model of your project's architecture, dependency graph, or module boundaries. You still need to provide high-level context about how the project is organized.


The Pattern Beyond claude-context

Claude-context is one implementation of a broader idea. Other projects are emerging with similar approaches.

code-context (also by Zilliz, a lighter variant) does the same thing with a simplified setup. jcodemunch-mcp uses tree-sitter AST parsing instead of vector search for a different take on efficient context retrieval. context-mode sandboxes tool output and claims 98% reduction in context usage.

The common thread is the same. Stop stuffing the prompt with everything. Start giving the agent tools to find what it needs.

This pattern will compound as the MCP ecosystem grows. Today we have code search. Tomorrow we will have MCP servers for documentation search, ticket search, log search, config search. Each one provides targeted context on demand. The agent assembles a precise, focused context window by calling the right tools for the job.


What to Take Away

Three things.

First, the problem is real. Wholesale context loading is expensive, noisy, and does not scale. If you are working with large codebases and AI agents, you have already hit these walls.

Second, the pattern works. Selective context injection via MCP tool calls reduces cost, improves signal-to-noise ratio, preserves context window space, and scales to arbitrarily large codebases. Claude-context's rapid star growth confirms that developers are hitting this problem and finding value in this solution.

Third, the pattern generalizes. It is not about claude-context or Milvus or any specific tool. It is about the architectural shift from "load everything into the prompt" to "give the agent tools to find what it needs." That shift applies to every domain where AI agents interact with large data sources.

If you are building with AI coding agents, try the selective context pattern. Set up claude-context or a similar MCP server. Run a few queries. Compare the token counts and the quality of the agent's responses against your current approach. The difference is visible from the first query.


The repository for claude-context is at github.com/zilliztech/claude-context. The MCP specification is at modelcontextprotocol.io.