CodeAgent MCP

CodeAgent MCP

An autonomous code-reasoning agent that parses repositories using tree-sitter, indexes symbols into SQLite, and answers questions about the codebase through an agentic loop powered by Claude via OpenRouter.

Category
Visit Server

README

CodeAgent MCP

An autonomous code-reasoning agent built on the Model Context Protocol (MCP). It parses your repository using tree-sitter, indexes all symbols into SQLite, and drives an agentic loop powered by Claude via OpenRouter to answer questions about your codebase.


Architecture

┌──────────────────────────────────────────────────┐
│  CLI  (typer + rich)                             │
│  codeagent ask "what does Foo.bar() do?"         │
└──────────────┬───────────────────────────────────┘
               │
┌──────────────▼───────────────────────────────────┐
│  Agent Server  (agent_server/)                   │
│  • Agentic loop — OpenRouter API (Claude)         │
│  • Tool dispatch ↔ Code Server via MCP           │
│  • Conversation history manager                  │
└──────────────┬───────────────────────────────────┘
               │  MCP (stdio / SSE)
┌──────────────▼───────────────────────────────────┐
│  Code Server  (code_server/)                     │
│  • FastMCP server                                │
│  • tree-sitter AST indexer → SQLite              │
│  • Tools: search_symbols, find_callers,          │
│           read_code, get_imports                 │
│  • watchdog file watcher (auto-reindex)          │
└──────────────────────────────────────────────────┘

Setup Instructions

  1. Clone the repository:

    git clone <repo-url> && cd codeagent
    
  2. Set up virtual environment & install:

    python3 -m venv .venv
    source .venv/bin/activate
    pip install -e .
    
  3. Configure environment variables:

    cp .env.example .env
    # Open .env and set your OPENROUTER_API_KEY
    
  4. Index the repository:

    codeagent index .
    
  5. Ask questions:

    codeagent ask "How is the AST indexed into SQLite?"
    

Example Queries

  • Find all functions:
    codeagent ask "What functions are defined in this codebase?"
    
  • Trace function execution flow:
    codeagent ask "Which components call start_watcher()?"
    
  • Explain architectural design:
    codeagent ask "How does the file watching indexing system work?"
    

Environment Variables

Variable Required Description
OPENROUTER_API_KEY ✅ Your OpenRouter API key (sk-or-...)
CODEAGENT_REPO optional Default repo path (defaults to .)

Tech Stack

Layer Library
LLM openai SDK → OpenRouter (anthropic/claude-sonnet-4-5)
MCP mcp (FastMCP)
Code parsing tree-sitter ≥0.22 + tree-sitter-python + tree-sitter-javascript
Database aiosqlite (async SQLite, no ORM)
File watching watchdog
CLI typer + rich
Testing pytest + pytest-asyncio

Development

# Run all tests
pytest -v

# Run only indexer tests
pytest tests/test_indexer.py -v

# Index a repo manually (Python API)
python3 -c "
import asyncio
from code_server.indexer import index_repo
asyncio.run(index_repo('/path/to/repo'))
"

Project Structure

codeagent/
├── code_server/
│   ├── indexer.py      # tree-sitter AST → SQLite (Phase 1 ✅)
│   ├── tools.py        # MCP tools: search_symbols, find_callers, read_code, get_imports
│   ├── server.py       # FastMCP server
│   └── watcher.py      # watchdog file watcher
├── agent_server/
│   ├── loop.py         # agentic loop (OpenRouter + tool use)
│   └── history.py      # conversation history manager
├── cli/
│   └── main.py         # typer CLI
├── tests/
│   ├── test_indexer.py ✅ 6 passing
│   ├── test_tools.py
│   └── test_loop.py
├── .env.example
└── pyproject.toml

Build Phases

  • [x] Phase 0 — Project scaffold, pyproject.toml, venv, package installs
  • [x] Phase 1 — AST indexer (indexer.py)
  • [x] Phase 2 — Code tools (tools.py)
  • [x] Phase 3 — FastMCP server (server.py)
  • [x] Phase 4 — Conversation history manager (history.py)
  • [x] Phase 5 — Core Agentic loop (loop.py)
  • [x] Phase 6 — Rich CLI (main.py)
  • [x] Phase 7 — Watchdog file watcher (watcher.py)
  • [x] Phase 8 — Verification & Test suite (36/36 tests passing)
  • [x] Phase 9 — Complete README documentation

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured