Code Scanner Server
code-scanner-server
コード ファイルの定義 (クラス、関数など) をスキャンし、.gitignore を尊重し、行番号を提供し、LLM 対応形式 (XML/Markdown) を出力する CLI ツールおよび MCP サーバー。
このプロジェクトは、TypeScriptとNode.jsで構築された多用途のコードスキャンツールを提供します。Tree-sitter解析ライブラリを活用してソースコードを解析し、構造情報を抽出します。コマンドラインインターフェース(CLI)ツールとしても、MCP(Model Context Protocol)サーバーとしても動作します。
**注:**このツールは現在開発中です。コア機能は動作しますが、一部の機能や特定の言語パーサーは完全にテストされておらず、バグや制限が含まれている可能性があります。
特徴
**コード定義の抽出:**関数、クラス、変数、インターフェース、メソッドなどを識別します。
多言語サポート: Tree-sitter を介して JavaScript (
.js、.jsx)、TypeScript (.ts、.tsx)、C# (.cs)、PHP (.php)、CSS (.css)、および Python (.py) を解析します。.gitignore 対応:
.gitignoreファイルで定義されたルールを自動的に尊重します。**柔軟なフィルタリング:**定義タイプ、修飾子 (
public、private)、名前パターン (正規表現)、およびファイル パス パターンで結果をフィルタリングします。複数の出力形式: Markdown (デフォルト)、XML、または JSON で結果を生成します。
**設定可能な詳細レベル:**出力の詳細度:
minimal、standard(デフォルト)、detailed。**デュアル モード操作:**スタンドアロン CLI ツールとして、または統合された MCP サーバーとして実行します。
Related MCP server: Axon.MCP.Server
使用モード
1. コマンドラインインターフェース(CLI)
ターミナルから直接スキャナーを実行します。このモードでは、ターゲットのコードベースを指定する--directory引数が必要です。
基本的な使用方法:
node build/index.js --directory /path/to/your/codebase一般的なオプション:
-d, --directory <path>: (必須) スキャンするディレクトリへの絶対パスまたは相対パス。-p, --patterns <patterns...>: ファイル拡張子のglobパターン(例:"**/*.ts"``"**/*.js")。デフォルトはJS、TSX、CS、PHP、CSS、PYファイルです。-f, --format <format>: 出力形式(xml、markdown、json)。デフォルト:markdown。-l, --detail <level>: 詳細レベル(minimal、standard、detailed)。デフォルト:standard。--include-types <types...>: 特定の定義タイプ (例:class、method) のみを含めます。--exclude-types <types...>: 特定の定義タイプを除外します。--include-modifiers <modifiers...>: 特定の修飾子 (例:public) を持つ定義のみを含めます。--exclude-modifiers <modifiers...>: 特定の修飾子を持つ定義を除外します。--name-pattern <regex>: JavaScript 正規表現パターンに一致する定義を含めます。--exclude-name-pattern <regex>: JavaScript 正規表現パターンに一致する定義を除外します。--include-paths <paths...>: 含める追加のファイル パス パターン (glob)。--exclude-paths <paths...>: 除外するファイル パス パターン (glob)。-h, --help: すべてのオプションの詳細なヘルプ情報を表示します。
例 ( src内の TypeScript ファイルをスキャンし、詳細な JSON を出力する):
node build/index.js -d ./src -p "**/*.ts" -f json -l detailed2. MCPサーバーモード( scan_codeツール)
--directory引数を指定せずに実行すると、ツールはMCPサーバーとして起動し、標準入出力を介してリクエストをリッスンします。これにより、AIアシスタントなどのMCPクライアントとの統合が可能になります。
ツール名:
scan_code**説明:**指定されたディレクトリでコード ファイルをスキャンし、指定されたフィルターに従って定義のリストを返します。
入力スキーマ: CLIオプションに対応する引数を受け入れます。
directoryプロパティは必須です。{ "type": "object", "properties": { "directory": { "type": "string", "description": "Absolute path to the directory to scan." }, "filePatterns": { "type": "array", "items": { "type": "string" }, "description": "Glob patterns for files.", "default": ["**/*.js", ..., "**/*.py"] }, "outputFormat": { "type": "string", "enum": ["xml", "markdown", "json"], "default": "markdown" }, "detailLevel": { "type": "string", "enum": ["minimal", "standard", "detailed"], "default": "standard" }, "includeTypes": { "type": "array", "items": { "type": "string" } }, "excludeTypes": { "type": "array", "items": { "type": "string" } }, "includeModifiers": { "type": "array", "items": { "type": "string" } }, "excludeModifiers": { "type": "array", "items": { "type": "string" } }, "namePattern": { "type": "string", "description": "Regex pattern for names." }, "excludeNamePattern": { "type": "string", "description": "Regex pattern to exclude names." }, "includePaths": { "type": "array", "items": { "type": "string" } }, "excludePaths": { "type": "array", "items": { "type": "string" } } }, "required": ["directory"] }AI アシスタントでの使用例: 「ディレクトリ /path/to/project で code-scanner-server scan_code を使用して、xml 形式を出力します。」
インストール
前提条件: Node.js と npm がインストールされていることを確認してください。
**クローン (オプション):**コードがない場合は、リポジトリをクローンします。
# git clone <repository_url> # cd code-scanner-server依存関係をインストールします:
npm installビルド: TypeScript コードをコンパイルします。
npm run buildこれにより
build/index.jsに実行可能な JavaScript ファイルが作成されます。
構成(MCP サーバー)
MCP サーバー モードを使用するには、MCP クライアントの構成ファイル (デスクトップ アプリの場合はclaude_desktop_config.json 、VS Code 拡張機能の場合はcline_mcp_settings.json ) に追加します。
重要:以下の例の/path/to/code-scanner-serverシステム上のこのプロジェクトのディレクトリへの絶対パスに置き換えてください。
例 ( claude_desktop_config.json / cline_mcp_settings.json ):
{
"mcpServers": {
"code-scanner-server": {
"command": "node",
"args": [
"/absolute/path/to/your/code-scanner-server/build/index.js" // <-- Replace this path! (e.g., "C:\\Users\\YourUser\\Projects\\code-scanner-server\\build\\index.js" on Windows)
],
"env": {},
"disabled": false,
"autoApprove": [] // Add tool names here for auto-approval if desired
}
}
}変更を有効にするには、構成を変更した後、必ず MCP クライアント アプリケーション (IDE、デスクトップ アプリ) を再起動してください。
発達
**監視モード:**ソース ファイルが変更されたときにプロジェクトを自動的に再構築します。
npm run watchデバッグ(MCPモード): stdio経由のMCPサーバーのデバッグは複雑になる場合があります。MCP Inspectorツールを使用すると、デバッグが容易になります。
npm run inspectorこれにより、Node.js インスペクターがアタッチされた状態でサーバーが起動し、デバッグ ツール (Chrome DevTools など) に接続するための URL が提供されます。
謝辞
このプロジェクトは、主に Visual Studio Code の Roo Code 拡張機能を介してアクセスした Google の Gemini 2.5 Pro モデルを使用して、AI の支援を受けて大幅に開発されました。
ライセンス
このプロジェクトは、GNU General Public License v3.0 に基づいてライセンスされています。詳細については、 LICENSEファイルを参照してください。
Available Tools
1 toolscan_codeA
Scans a directory for code files (JS, TS, C#, PHP, CSS, respecting .gitignore) and lists definitions (functions, classes, etc.) with line numbers. Supports XML, Markdown, and JSON output.
| Name | Required | Description | Default |
|---|---|---|---|
| detailLevel | No | Level of detail to include in the output. | standard |
| directory | Yes | The absolute path to the directory to scan. Relative paths are not supported. | |
| excludeModifiers | No | Modifiers to exclude. | |
| excludeNamePattern | No | Regex pattern to exclude element names. | |
| excludePaths | No | File path patterns to exclude. | |
| excludeTypes | No | Element types to exclude. | |
| filePatterns | No | Glob patterns for file extensions to include. | |
| includeModifiers | No | Modifiers to include (e.g., public, private). | |
| includePaths | No | Additional file path patterns to include. | |
| includeTypes | No | Element types to include (e.g., class, method). | |
| namePattern | No | Regex pattern to match element names. | |
| outputFormat | No | Output format for the results. | markdown |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: it scans directories, respects .gitignore, lists definitions with line numbers, and supports multiple output formats. However, it does not mention performance aspects (e.g., speed, memory usage), error handling, or whether it's read-only (implied but not stated). The description adds substantial value beyond the schema.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is appropriately sized and front-loaded, with a single sentence that efficiently conveys the core functionality (scanning, listing definitions) and key features (supported languages, .gitignore respect, output formats). Every part earns its place without redundancy or unnecessary detail.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the complexity (12 parameters, no output schema, no annotations), the description is reasonably complete. It covers the main action, supported file types, filtering behavior (.gitignore), and output options. However, it lacks details on return values (since no output schema) and could mention more about error cases or limitations. It's sufficient but not exhaustive.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema description coverage is 100%, so the schema already documents all 12 parameters thoroughly. The description does not add specific parameter semantics beyond what the schema provides (e.g., it mentions output formats but doesn't elaborate on parameter interactions). Baseline score of 3 is appropriate as the schema does the heavy lifting, and the description does not compensate with extra insights.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's purpose with specific verbs ('scans', 'lists') and resources ('directory for code files', 'definitions with line numbers'). It distinguishes what it does by specifying supported languages (JS, TS, C#, PHP, CSS), respect for .gitignore, and output formats (XML, Markdown, JSON). No sibling tools exist, but the description is comprehensive enough to stand alone.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage context by mentioning 'scans a directory for code files' and output formats, but does not explicitly state when to use this tool versus alternatives. Since there are no sibling tools, this is less critical, but it lacks guidance on prerequisites (e.g., directory accessibility) or exclusions. The implied context is adequate but not explicit.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
1 tool update
v1.0.0- First observed
scan_code
TDQS
Scored across 1 tool
With only one tool, there is no possibility of ambiguity or overlap between tools. The tool 'scan_code' has a clear, distinct purpose focused on scanning code files and listing definitions, making it impossible for an agent to misselect between non-existent alternatives.
The single tool name 'scan_code' follows a verb_noun pattern, which is consistent and predictable. Since there is only one tool, there are no deviations or mixed conventions to evaluate, resulting in perfect naming consistency.
A single tool is too few for a server named 'Code Scanner Server', which implies a broader scope of code analysis operations. While 'scan_code' is comprehensive, the lack of additional tools (e.g., for filtering results, analyzing specific file types, or managing scans) makes the set feel thin and underdeveloped for the apparent domain.
The tool set is severely incomplete for a code scanning domain. It covers scanning and listing definitions but lacks essential operations such as filtering results, analyzing code quality, detecting vulnerabilities, or integrating with version control. This creates significant gaps that will likely cause agent failures when trying to perform comprehensive code analysis tasks.
Maintenance
Related MCP Connectors
Repository knowledge graph MCP server for codebase understanding and debugging.
An MCP server that gives your AI access to the source code and docs of all public github repos
Security scanner for MCP servers. Detect vulnerabilities, prompt injection, and tool poisoning.
Related MCP Servers
- AlicenseCqualityDmaintenanceA MCP server that transforms code repositories from GitHub, GitLab, or local directories into LLM-friendly formats, preserving context and structure for better AI processing.311Apache 2.0
- FlicenseNot gradedqualityCmaintenanceAn MCP server that transforms codebases into intelligent, queryable knowledge bases, enabling AI assistants to perform semantic search, explore architecture, and analyze code relationships.167-
- AlicenseNot gradedqualityCmaintenanceAn MCP server that provides ultra-efficient code exploration through AST analysis, reducing LLM token usage by up to 95% while enabling instant call graph generation and dependency analysis for massive codebases.MIT
- AlicenseAqualityDmaintenanceUniversal MCP server that analyzes any codebase and provides structured context to AI assistants. Dynamic, accurate, and token-efficient.187 npmMIT