Code Analysis MCP Server

Local setup required. This server has to be cloned and prepared on your machine before you register it in Claude Code.
1

Set the server up locally

Run this once to clone and prepare the server before adding it to Claude Code.

Run in terminal
git clone https://github.com/zeocax/code-mcp.git
cd code-mcp
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
2

Register it in Claude Code

After the local setup is done, run this command to point Claude Code at the built server.

Run in terminal
claude mcp add code-analysis -- python "<FULL_PATH_TO_CODE_MCP>/dist/index.js"

Replace <FULL_PATH_TO_CODE_MCP>/dist/index.js with the actual folder you prepared in step 1.

README.md

Modular MCP server for code analysis, file operations, and structural insights.

Code Analysis MCP Server

A modular MCP (Model Context Protocol) server for code analysis with file operations, code search, and structure analysis capabilities.

Features

📁 File Operations

  • read_file: Read contents of any code file
  • list_files: List files in directories with pattern matching
  • file_info: Get detailed file information (size, type, line count)

🔍 Code Search

  • search_code: Search for patterns in code using regex
  • find_definition: Find symbol definitions (functions, classes, variables)

📊 Code Analysis

  • analyze_structure: Analyze code structure (imports, classes, functions)

Installation

# Clone the repository
git clone https://github.com/yourusername/code-mcp.git
cd code-mcp

# Create virtual environment
python -m venv venv

# Activate environment
source venv/bin/activate  # On Unix/macOS
venv\Scripts\activate     # On Windows

# Install dependencies
pip install -r requirements.txt

Usage

1. With Claude Desktop

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "code-analyzer": {
      "command": "python",
      "args": ["/absolute/path/to/code-mcp/server.py"]
    }
  }
}

Then restart Claude Desktop.

2. With Continue.dev (VS Code)

Add to your Continue configuration:

{
  "models": [...],
  "mcpServers": {
    "code-analyzer": {
      "command": "python",
      "args": ["/absolute/path/to/code-mcp/server.py"]
    }
  }
}

3. With Other MCP Clients

Any MCP-compatible client can use this server by pointing to the server.py file.

Available Tools

📖 read_file

Read the contents of a file.

{
  "tool": "read_file",
  "arguments": {
    "path": "src/main.py",
    "encoding": "utf-8"  // optional, default: utf-8
  }
}

📂 list_files

List files in a directory with optional pattern matching.

{
  "tool": "list_files",
  "arguments": {
    "directory": "./src",      // optional, default: current dir
    "pattern": "*.py",         // optional, default: *
    "recursive": true          // optional, default: false
  }
}

ℹ️ file_info

Get detailed information about a file.

{
  "tool": "file_info",
  "arguments": {
    "path": "src/main.py"
  }
}

🔍 search_code

Search for patterns in code files using regex.

{
  "tool": "search_code",
  "arguments": {
    "pattern": "def.*test",        // regex pattern
    "directory": "./src",          // optional
    "file_pattern": "*.py",        // optional
    "case_sensitive": false        // optional, default: true
  }
}

🎯 find_definition

Find where a symbol is defined.

{
  "tool": "find_definition",
  "arguments": {
    "symbol": "MyClass",
    "directory": "./src",          // optional
    "language": "python"           // optional: python, javascript
  }
}

🏗️ analyze_structure

Analyze the structure of a code file.

{
  "tool": "analyze_structure",
  "arguments": {
    "path": "src/main.py",
    "include_docstrings": true     // optional, default: false
  }
}

🤖 update_with_architecture

Compare old and new architecture versions and intelligently update the new file.

{
  "tool": "update_with_architecture",
  "arguments": {
    "old_file": "src/legacy/module.py",    // Reference file (old architecture)
    "new_file": "src/modern/module.py",    // Target file (will be updated)
    "backup": true                         // optional, default: true
  }
}

AI Configuration

To use the AI-powered tools, you need to configure your API keys:

  1. Copy .env.example to .env:

    cp .env.example .env
    
  2. Edit .env and add your API keys:

    AI_PROVIDER=openai
    OPENAI_API_KEY=your-openai-api-key
    # or
    AI_PROVIDER=anthropic  
    ANTHROPIC_API_KEY=your-anthropic-api-key
    

Thinking Models Support

The tool automatically handles "thinking" models (like o1, o1-preview) that include reasoning in their responses:

  • Thinking sections are automatically removed
  • Only the actual code is extracted
  • Supports various thinking formats: <think>, [thinking], etc.
  1. Install AI dependencies:

    pip install openai anthropic
    
  2. Test LLM connectivity:

    ./test_llm.sh
    # or
    python tests/test_llm.py
    

Examples

In Claude Desktop

After configuring, you can ask Claude:

  • "Read the file src/main.py"
  • "Search for all functions that contain 'test' in the src directory"
  • "Find where the class 'UserModel' is defined"
  • "Analyze the structure of app.py"
  • "List all Python files in the project"

Programmatic Usage

# Example of calling tools programmatically
import asyncio
from mcp import Client

async def main():
    client = Client()
    
    # Read a file
    result = await client.call_tool("read

Tools (7)

read_fileRead the contents of a file.
list_filesList files in a directory with optional pattern matching.
file_infoGet detailed information about a file.
search_codeSearch for patterns in code files using regex.
find_definitionFind where a symbol is defined.
analyze_structureAnalyze the structure of a code file.
update_with_architectureCompare old and new architecture versions and intelligently update the new file.

Environment Variables

AI_PROVIDERThe AI provider to use (openai or anthropic)
OPENAI_API_KEYAPI key for OpenAI
ANTHROPIC_API_KEYAPI key for Anthropic

Configuration

claude_desktop_config.json
{"mcpServers": {"code-analyzer": {"command": "python", "args": ["/absolute/path/to/code-mcp/server.py"]}}}

Try it

Read the file src/main.py
Search for all functions that contain 'test' in the src directory
Find where the class 'UserModel' is defined
Analyze the structure of app.py
List all Python files in the project

Frequently Asked Questions

What are the key features of Code Analysis MCP Server?

File operations including reading and listing with pattern matching. Regex-based code searching across directories. Symbol definition lookup for functions and classes. Structural analysis of code files including imports and docstrings. AI-powered architectural updates between file versions.

What can I use Code Analysis MCP Server for?

Quickly navigating and searching large codebases using natural language. Automating the migration of code patterns from legacy to modern architecture. Generating summaries of code structure for documentation purposes. Locating specific class or function definitions across multiple files.

How do I install Code Analysis MCP Server?

Install Code Analysis MCP Server by running: git clone https://github.com/zeocax/code-mcp.git && cd code-mcp && python -m venv venv && source venv/bin/activate && pip install -r requirements.txt

What MCP clients work with Code Analysis MCP Server?

Code Analysis MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Code Analysis MCP Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare