The Code Scanner Server is a versatile tool for analyzing codebases to extract structural information with the following capabilities:
- Code Definition Extraction: Identifies functions, classes, variables, methods, interfaces and more with line numbers
- Multi-Language Support: Parses JavaScript, TypeScript, C#, PHP, CSS, and Python using Tree-sitter
- .gitignore Aware: Respects exclusion rules to skip specified files and directories
- Flexible Filtering: Filter by definition type, modifiers (e.g.,
public
,private
), name patterns (regex), and file paths - Multiple Output Formats: Generates results in XML, Markdown, or JSON
- Configurable Detail Levels: Choose between
minimal
,standard
, ordetailed
output verbosity - Dual Operation Modes: Functions as both an MCP server for integration with AI assistants and other clients, and as a CLI tool for direct scanning
Provides parsing and definition extraction for CSS files, identifying selectors, rules, and structure
Respects .gitignore rules when scanning codebases, ensuring ignored files are excluded from analysis
Offers parsing and code structure analysis for JavaScript files, including JSX, extracting functions, classes and other definitions
Provides output formatting in Markdown for human-readable documentation and integration with documentation systems
Built on Node.js platform for code scanning and analysis capabilities across multiple programming languages
Offers parsing and code structure analysis for PHP files, extracting functions, classes and other definitions
Provides parsing and code structure analysis for Python files, extracting functions, classes and other definitions
Offers parsing and code structure analysis for TypeScript files, including TSX, extracting functions, classes, interfaces and other definitions
Supports output formatting in XML for integration with other tools and services
code-scanner-server
A CLI tool and MCP server that scans code files for definitions (classes, functions, etc.), respects .gitignore, provides line numbers, and outputs LLM-friendly formats (XML/Markdown).
This project provides a versatile code scanning tool built with TypeScript and Node.js. It leverages the Tree-sitter parsing library to analyze source code and extract structural information. It can operate both as a command-line interface (CLI) tool and as an MCP (Model Context Protocol) server.
Note: This tool is under active development. While core functionality is operational, some features or specific language parsers may not be fully tested and might contain bugs or limitations.
Features
- Code Definition Extraction: Identifies functions, classes, variables, interfaces, methods, etc.
- Multi-Language Support: Parses JavaScript (
.js
,.jsx
), TypeScript (.ts
,.tsx
), C# (.cs
), PHP (.php
), CSS (.css
), and Python (.py
) via Tree-sitter. - .gitignore Aware: Automatically respects rules defined in
.gitignore
files. - Flexible Filtering: Filter results by definition type, modifiers (
public
,private
), name patterns (regex), and file path patterns. - Multiple Output Formats: Generates results in Markdown (default), XML, or JSON.
- Configurable Detail Levels: Output verbosity:
minimal
,standard
(default),detailed
. - Dual Mode Operation: Run as a standalone CLI tool or as an integrated MCP server.
Usage Modes
1. Command-Line Interface (CLI)
Run the scanner directly from your terminal. This mode requires the --directory
argument specifying the target codebase.
Basic Usage:
Common Options:
-d, --directory <path>
: (Required) Absolute or relative path to the directory to scan.-p, --patterns <patterns...>
: Glob patterns for file extensions (e.g.,"**/*.ts"
"**/*.js"
). Defaults to JS, TSX, CS, PHP, CSS, PY files.-f, --format <format>
: Output format (xml
,markdown
,json
). Default:markdown
.-l, --detail <level>
: Level of detail (minimal
,standard
,detailed
). Default:standard
.--include-types <types...>
: Only include specific definition types (e.g.,class
,method
).--exclude-types <types...>
: Exclude specific definition types.--include-modifiers <modifiers...>
: Only include definitions with specific modifiers (e.g.,public
).--exclude-modifiers <modifiers...>
: Exclude definitions with specific modifiers.--name-pattern <regex>
: Include definitions matching a JavaScript regex pattern.--exclude-name-pattern <regex>
: Exclude definitions matching a JavaScript regex pattern.--include-paths <paths...>
: Additional file path patterns (glob) to include.--exclude-paths <paths...>
: File path patterns (glob) to exclude.-h, --help
: Display detailed help information for all options.
Example (Scan TypeScript files in src
, output detailed JSON):
2. MCP Server Mode (scan_code
tool)
If run without the --directory
argument, the tool starts as an MCP server, listening for requests via standard input/output. This allows integration with MCP clients like AI assistants.
- Tool Name:
scan_code
- Description: Scans a specified directory for code files and returns a list of definitions according to the provided filters.
- Input Schema: Accepts arguments corresponding to the CLI options. The
directory
property is required. - Example Usage with AI Assistant: "Use code-scanner-server scan_code on directory /path/to/project outputting xml format."
Installation
- Prerequisites: Ensure you have Node.js and npm installed.
- Clone (Optional): If you don't have the code, clone the repository.
- Install Dependencies:
- Build: Compile the TypeScript code.This creates the executable JavaScript file at
build/index.js
.
Configuration (MCP Server)
To use the MCP server mode, add it to your MCP client's configuration file (e.g., claude_desktop_config.json
for the desktop app or cline_mcp_settings.json
for the VS Code extension).
Important: Replace /path/to/code-scanner-server
in the example below with the absolute path to this project's directory on your system.
Example (claude_desktop_config.json
/ cline_mcp_settings.json
):
Remember to restart your MCP client application (IDE, Desktop App) after modifying the configuration for changes to take effect.
Development
- Watch Mode: Automatically rebuild the project when source files change:
- Debugging (MCP Mode): Debugging MCP servers over stdio can be complex. Use the MCP Inspector tool for easier debugging:This starts the server with the Node.js inspector attached and provides a URL to connect debugging tools (like Chrome DevTools).
Acknowledgments
This project was significantly developed with the assistance of AI, primarily using Google's Gemini 2.5 Pro model accessed via the Roo Code extension for Visual Studio Code.
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Tools
An MCP server that scans codebases to extract structural information (classes, functions, etc.) with flexible filtering options and outputs in LLM-friendly formats.
Related MCP Servers
- AsecurityFlicenseAqualityAn MCP server that enables LLMs to understand and analyze code structure through function call graphs, allowing AI assistants to explore relationships between functions and analyze dependencies in Python repositories.Last updated -67Python
Semgrep MCP Serverofficial
AsecurityAlicenseAqualityAn MCP server that provides a comprehensive interface to Semgrep, enabling users to scan code for security vulnerabilities, create custom rules, and analyze scan results through the Model Context Protocol.Last updated -6207PythonMIT License- -securityAlicense-qualityAn MCP server that provides tools to load and fetch documentation from any llms.txt source, giving users full control over context retrieval for LLMs in IDE agents and applications.Last updated -177PythonMIT License
- -securityFlicense-qualityAn MCP server that enables language models to access code intelligence features like completions, definitions, and references across multiple programming languages through the Language Server Protocol.Last updated -Python