Skip to content

Latest commit

 

History

History
120 lines (78 loc) · 3.23 KB

File metadata and controls

120 lines (78 loc) · 3.23 KB

🧠 Code Analysis MCP Server

This is a modular MCP agent for analyzing local code repositories.
It exposes tools to inspect a project’s file structure, read files (with language detection), and guide the user through code exploration via structured prompts.

Powered by Model Context Protocol TypeScript SDK with Streamable HTTP as Transport Type.


🚀 Features

  • 🗂️ Initializes and inspects code repositories (with .gitignore support)
  • 📁 Traverses directory trees with depth control
  • 📄 Reads file content (up to 1MB / 1000 lines)
  • 💬 Provides prompt-guided codebase analysis for LLMs
  • ✅ Fully compatible with MCP Inspector

📦 Prerequisites

  • Node.js >= 18.x
  • MCP-compatible client (e.g., MCP Inspector)
  • Local repo access via allowed roots

🛠 Installation

git clone https://github.com/sur950/mcp-server-examples.git
cd mcp-server-examples

npm install

▶️ Running the Server

  1. Start the MCP server:

    npm run dev
  2. Open a second terminal and run:

    npm run debug

This opens the MCP Inspector UI at http://127.0.0.1:6274.

🎯 In the Inspector, make sure to select Streamable HTTP as the transport type, then set the URL to: http://localhost:3000/mcp


🧪 Example Usage via MCP Inspector

🛠 List of Tools

Tools list in Inspector

🧭 Running init_repo

init_repo tool in Inspector

🧱 Running get_repo_structure

get_repo_structure tool


🛠 Tools

Tool Description
init_repo Initialize a repo path (must be allowed)
get_repo_info Return .gitignore and path details
get_repo_structure Show directory tree by depth/subpath
read_file Read file contents with language detection

💬 Prompt

Prompt Description
analyze_code_repository Guided exploration of repo for LLM use

The prompt walks the LLM through:

  • Initialization → Structure → File reading
  • Forming and verifying hypotheses
  • Producing structured, evidence-based conclusions

📚 Resources

Resource Name URI Pattern Description
repo-schema schema://main Returns tree structure of initialized repo

📁 Internal Folder Structure

code-analysis/
├── tools.ts       # Tool implementations (init, structure, file)
├── prompt.ts      # Prompt definition for LLM agents
├── utils.ts       # Gitignore parsing, reader helpers
├── server.ts      # MCP server with registration logic
├── resource.ts    # Resources registered (e.g., file://, schema://)
├── assets/        # Screenshots for demo
└── README.md