Purpose
CodebaseAgent-MCP is a token-efficient MCP server for AI coding agents. It delegates large codebase analysis to a dedicated OpenAI-compatible LLM, thereby reducing context size, latency, and token costs. Instead of forcing the main coding assistant to repeatedly scan large codebases, it performs that work separately and returns only the information needed for the current task.
It can run on local models (such as Gemma or Qwen), or on low-cost OpenAI-compatible cloud providers, reducing latency and token consumption while allowing the main assistant to focus on reasoning and code generation.
Based on the author's actual usage (analyzing large amounts of data, such as documents, collections of scientific papers, massive content saved from government websites with poor filtering/search capabilities, etc.), the project is smoothly evolving into an independent general-purpose long-horizon agent sub-framework that can connect to any CLI/GUI agent.
Main Capabilities
- Designed specifically for managing small LLMs: focused on addressing their specific behavioral characteristics and weaknesses that prevent other frameworks from working effectively.
- Precise conversation history compression.
- Recursive sub-agent tree with configurable depth.
- LLM anti-stall mechanism (prevents the model from getting stuck in infinite self-repetition loops).
- Task completion control (prevents small LLMs from terminating work prematurely).
- Complete sub-agent tree.
- Supports both STDIO and HTTP modes.
- Token-efficient code and dependency analysis for repositories with files larger than the connected model's context window.
- Optional RAG cache via one of the built-in qdrant_* plugins.
- Sandboxed filesystem access, scoped within the configured repository root.
- Pluggable external stdio MCP tools.
- Can be used with local OpenAI-compatible servers (LM Studio, llama.cpp, vLLM, Sglang, etc.) or compatible hosted APIs.
- Can be used with cloud OpenAI-compatible servers (OpenRouter, etc.).
- Asynchronous background tasks, with results persisted via SQLite.
Usage
- Install uv:https://docs.astral.sh/uv/getting-started/installation/
- Initialize and create the CodebaseAgent-MCP configuration via uvx:
uvx --from codebase-agent-mcp cb-agent-init. It will return the path to your codebase_agent.config.json configuration file. You can use this command at any time to find the configuration file location. - Update to the latest version (will not affect your configuration).
- Edit codebase_agent.config.json before starting the server:
- Define an OpenAI-compatible LLM (local or cloud).
- Define the local repositories, dependency source code, or document trees that the framework can analyze.
- Qdrant (optional): CodebaseAgent-MCP works as a Qdrant client, supporting local or cloud. qdrant_fastembed and qdrant_cloud can enable the RAG cache. The qdrant_fastembed client is installed by default.
- Register CodebaseAgent-MCP as an MCP server: configure your MCP client (ClaudeCode/Codex/OpenCode/Hermes/PiAgent, etc.) to run CodebaseAgent-MCP via uvx.
- Install sub-agents and skills into your framework (ClaudeCode/Codex, etc.): enter the project root directory and run the corresponding command; you can also use
git clone https://github.com/FI-Mihej/codebase-agent-mcp.gitManual steps after cloning the repository:- ClaudeCode: copy ./codebase_agent/data/integration_to/claude/.claude to the project root directory.
- Codex: copy ./codebase_agent/data/integration_to/codex/.agents, ./codebase_agent/data/integration_to/codex/.codex, and ./codebase_agent/data/integration_to/codex/.codex/config.toml to the project root directory.
- OpenCode: copy ./codebase_agent/data/integration_to/opencode/.opencode to the project root directory.
- Cursor: copy ./codebase_agent/data/integration_to/cursor/.cursor to the project root directory.
- Antigravity: copy ./codebase_agent/data/integration_to/antigravity/.agents to the project root directory. Antigravity lacks the agent concept, so token efficiency will be lower than with other frameworks. Be sure to enable implicit caching to achieve significant savings.
- Hermes Agent: copy ./codebase_agent/data/integration_to/hermes/skills to the project root directory.
- Pi Coding Agent: 1. Install https://github.com/nicobailon/pi-subagents or a similar solution; 2. copy ./codebase_agent/data/integration_to/pi_agent/.pi to the project root directory.
- Begin your development prompt with the phrase "Use skill libraries-analysis-skill ." to reduce costs.
Qdrant (optional) usage: before the first use of CodebaseAgent-MCP with the qdrant_* plugins enabled, and after every change to the "configuration"."model_name" field in the qdrant_* plugin configuration, the model must be initialized (downloaded). Index the dependency library codebase to add the key features of each entity (file, class, function) to the RAG store.
When to use
Modern coding agents repeatedly spend thousands (sometimes millions) of tokens re-reading repositories, dependency source code, and documentation before starting to solve an actual task. The cost is even higher when a project is actively evolving, documentation is incomplete or outdated, the source code must be inspected directly, and every new agent session starts from an empty context. CodebaseAgent-MCP delegates this exploration to a dedicated analysis model, and the main coding assistant receives only the relevant findings instead of repeatedly processing the entire codebase.
Limitations and notes
- The project intentionally focuses on the OpenAI Chat Completions API, which is historically the most fully supported interface for third-party inference servers.
- LangChain is not used, because LangChain cannot (and "has no plans to") retrieve or send unofficial but de facto reasoning custom fields in the chat history.
- The GitHub repository is the project's public mirror. The author usually does active development (including experimental code and private research notes) in a private repository and periodically publishes selected snapshots. Pull requests (not from LLMs) are welcome.
- Qdrant collection metadata requires Qdrant server 1.16 or later. Compatible pre-metadata collections are adopted without data loss; when recreate_incompatible_collections is enabled, identified legacy collections with a vectorless schema are rebuilt.
- Each provider implements caching differently, and some do not support caching at all.
- Technical details and configuration recommendations for local LLMs are in docs.
- Be on guard against prompt injection in dependency library code. Embedding prompt injection into repository code is becoming increasingly common, from repositories maintained by Meta (github.com/facebook/*) to genuinely dangerous situations that can lead to credential leaks, exposure of Social Security numbers, financial loss, and more.