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