Filescopemcp(模型上下文协议)服务器
分析您的代码库,根据依赖关系识别重要文件。生成每个文件的图表和重要性评分,帮助 AI 助手理解代码库。自动解析流行的编程语言,如 Python、C、C++、Rust、Zig、Lua。
概览
什么是 FileScopeMCP?
FileScopeMCP 是一个强大的工具,旨在通过识别文件之间的依赖关系来分析代码库。它生成有洞察力的图表和每个文件的重要性评分,帮助 AI 助手更有效地理解代码库。该工具支持自动解析流行的编程语言,如 Python、C、C++、Rust、Zig 和 Lua,使其在各种开发环境中都具有多功能性。
FileScopeMCP 的特点
- 依赖分析:自动分析代码库,以识别基于相互依赖关系的关键文件。
- 可视化图表:生成图表,直观地表示文件之间的关系,增强理解。
- 重要性评分:为文件分配重要性评分,帮助开发人员优先关注关键组件。
- 多语言支持:兼容多种编程语言,包括 Python、C、C++、Rust、Zig 和 Lua。
- 用户友好界面:设计时考虑到易用性,使开发人员能够快速导航并利用其功能。
如何使用 FileScopeMCP
- 安装:首先从其代码库下载并安装 FileScopeMCP。
- 代码库输入:将您的代码库加载到工具中。FileScopeMCP 将自动解析文件。
- 运行分析:启动分析过程,让工具评估依赖关系并生成结果。
- 审查结果:检查生成的图表和重要性评分,以了解代码库的结构和关键组件。
- 整合洞察:利用获得的洞察来优化开发过程,专注于最重要的文件和关系。
常见问题解答
FileScopeMCP 支持哪些编程语言?
FileScopeMCP 支持多种编程语言,包括 Python、C、C++、Rust、Zig 和 Lua。
FileScopeMCP 如何确定文件的重要性?
该工具分析文件之间的依赖关系,并根据它们在代码库中的连接性和相关性分配评分。
我可以在大型项目中使用 FileScopeMCP 吗?
是的,FileScopeMCP 旨在高效处理大型代码库,无论项目大小,都能提供有价值的洞察。
FileScopeMCP 是开源的吗?
是的,FileScopeMCP 作为一个开源项目提供,允许开发人员根据自己的需求进行贡献和定制。
我如何能为 FileScopeMCP 贡献?
您可以通过分叉代码库、进行改进并提交拉取请求到主项目来进行贡献。
详情
FileScopeMCP (Model Context Protocol) Server
✨ Instantly understand and visualize your codebase structure & dependencies! ✨
<!-- Add Badges Here (e.g., License, Version, Build Status) --> <!-- Add other badges -->A TypeScript-based tool for ranking files in your codebase by importance, tracking dependencies, and providing summaries to help understand code structure.
Overview
This MCP server analyzes your codebase to identify the most important files based on dependency relationships. It generates importance scores (0-10) for each file, tracks bidirectional dependencies, and allows you to add custom summaries for files. All this information is made available to AI tools through Cursor's Model Context Protocol.
Features
🚀 Supercharge your Code Understanding! FileScopeMCP provides insights directly to your AI assistant:
-
🎯 File Importance Analysis
- Rank files on a 0-10 scale based on their role in the codebase.
- Calculate importance using incoming/outgoing dependencies.
- Instantly pinpoint the most critical files in your project.
- Smart calculation considers file type, location, and name significance.
-
🔗 Dependency Tracking
- Map bidirectional dependency relationships between files.
- Identify which files import a given file (dependents).
- See which files are imported by a given file (dependencies).
- Distinguish between local and package dependencies.
- Multi-language support: Python, JavaScript, TypeScript, C/C++, Rust, Lua, Zig, C#, Java.
-
📊 Visualization
- Generate Mermaid diagrams to visualize file relationships.
- Color-coded visualization based on importance scores.
- Support for dependency graphs, directory trees, or hybrid views.
- HTML output with embedded rendering including theme toggle and responsive design.
- Customize diagram depth, filter by importance, and adjust layout options.
-
📝 File Summaries
- Add human or AI-generated summaries to any file.
- Retrieve stored summaries to quickly grasp file purpose.
- Summaries persist across server restarts.
-
📚 Multiple Project Support
- Create and manage multiple file trees for different project areas.
- Configure separate trees with distinct base directories.
- Switch between different file trees effortlessly.
- Cached trees for faster subsequent operations.
-
💾 Persistent Storage
- All data automatically saved to disk in JSON format.
- Load existing file trees without rescanning the filesystem.
- Track when file trees were last updated.
Installation
-
Clone this repository
-
Build the project:
The build script will install all node dependencies and generate mcp.json for you.
Windows:
build.bat
Copy the generated mcp.json configuration to your project's
.cursor
directory:{ "mcpServers": { "FileScopeMCP": { "command": "node", "args": ["<build script sets this>/mcp-server.js","--base-dir=C:/Users/admica/my/project/base"], "transport": "stdio", "disabled": false, "alwaysAllow": [] } } }
Linux: (Cursor in Windows, but your project is in Linux WSL, then put the MCP in Linux and build)
build.sh
{ "mcpServers": { "FileScopeMCP": { "command": "wsl", "args": ["-d", "Ubuntu-24.04", "/home/admica/FileScopeMCP/run.sh"], "transport": "stdio", "disabled": false, "alwaysAllow": [] } } }
-
Update the arg path --base-dir to your project's base path.
How It Works
Dependency Detection
The tool scans source code for import statements and other language-specific patterns:
- Python:
import
andfrom ... import
statements - JavaScript/TypeScript:
import
statements andrequire()
calls - C/C++:
#include
directives - Rust:
use
andmod
statements - Lua:
require
statements - Zig:
@import
directives - C#:
using
directives - Java:
import
statements
Importance Calculation
Files are assigned importance scores (0-10) based on a weighted formula that considers:
- Number of files that import this file (dependents)
- Number of files this file imports (dependencies)
- File type and extension (with TypeScript/JavaScript files getting higher base scores)
- Location in the project structure (files in
src/
are weighted higher) - File naming (files like 'index', 'main', 'server', etc. get additional points)
A file that is central to the codebase (imported by many files) will have a higher score.
Diagram Generation
The system uses a three-phase approach to generate valid Mermaid syntax:
- Collection Phase: Register all nodes and relationships
- Node Definition Phase: Generate definitions for all nodes before any references
- Edge Generation Phase: Create edges between defined nodes
This ensures all diagrams have valid syntax and render correctly. HTML output includes:
- Responsive design that works on any device
- Light/dark theme toggle with system preference detection
- Client-side Mermaid rendering for optimal performance
- Timestamp of generation
Path Normalization
The system handles various path formats to ensure consistent file identification:
- Windows and Unix path formats
- Absolute and relative paths
- URL-encoded paths
- Cross-platform compatibility
File Storage
All file tree data is stored in JSON files with the following structure:
- Configuration metadata (filename, base directory, last updated timestamp)
- Complete file tree with dependencies, dependents, importance scores, and summaries
Technical Details
- TypeScript/Node.js: Built with TypeScript for type safety and modern JavaScript features
- Model Context Protocol: Implements the MCP specification for integration with Cursor
- Mermaid.js: Uses Mermaid syntax for diagram generation
- JSON Storage: Uses simple JSON files for persistence
- Path Normalization: Cross-platform path handling to support Windows and Unix
- Caching: Implements caching for faster repeated operations
Available Tools
The MCP server exposes the following tools:
File Tree Management
- list_saved_trees: List all saved file trees
- create_file_tree: Create a new file tree configuration for a specific directory
- select_file_tree: Select an existing file tree to work with
- delete_file_tree: Delete a file tree configuration
File Analysis
- list_files: List all files in the project with their importance rankings
- get_file_importance: Get detailed information about a specific file, including dependencies and dependents
- find_important_files: Find the most important files in the project based on configurable criteria
- read_file_content: Read the content of a specific file
- recalculate_importance: Recalculate importance values for all files based on dependencies
File Summaries
- get_file_summary: Get the stored summary of a specific file
- set_file_summary: Set or update the summary of a specific file
File Watching
- toggle_file_watching: Toggle file watching on/off
- get_file_watching_status: Get the current status of file watching
- update_file_watching_config: Update file watching configuration
Diagram Generation
- generate_diagram: Create Mermaid diagrams with customizable options
- Output formats: Mermaid text (
.mmd
) or HTML with embedded rendering - Diagram styles: default, dependency, directory, or hybrid views
- Filter options: max depth, minimum importance threshold
- Layout options: direction (TB, BT, LR, RL), node spacing, rank spacing
- Output formats: Mermaid text (
Usage Examples
The easiest way to get started is to enable this mcp in cursor and tell cursor to figure it out and use it. As soon as the mcp starts, it builds an initial json tree. Tell an LLM to make summaries of all your important files and use the mcp's set_file_summary to add them.
Analyzing a Project
-
Create a file tree for your project:
create_file_tree(filename: "my-project.json", baseDirectory: "/path/to/project")
-
Find the most important files:
find_important_files(limit: 5, minImportance: 5)
-
Get detailed information about a specific file:
get_file_importance(filepath: "/path/to/project/src/main.ts")
Working with Summaries
-
Read a file's content to understand it:
read_file_content(filepath: "/path/to/project/src/main.ts")
-
Add a summary to the file:
set_file_summary(filepath: "/path/to/project/src/main.ts", summary: "Main entry point that initializes the application, sets up routing, and starts the server.")
-
Retrieve the summary later:
get_file_summary(filepath: "/path/to/project/src/main.ts")
Generating Diagrams
-
Create a basic project structure diagram:
generate_diagram(style: "directory", maxDepth: 3, outputPath: "diagrams/project-structure", outputFormat: "mmd")
-
Generate an HTML diagram with dependency relationships:
generate_diagram(style: "hybrid", maxDepth: 2, minImportance: 5, showDependencies: true, outputPath: "diagrams/important-files", outputFormat: "html")
-
Customize the diagram layout:
generate_diagram(style: "dependency", layout: { direction: "LR", nodeSpacing: 50, rankSpacing: 70 }, outputPath: "diagrams/dependencies", outputFormat: "html")
Using File Watching
-
Enable file watching for your project:
toggle_file_watching()
-
Check the current file watching status:
get_file_watching_status()
-
Update file watching configuration:
update_file_watching_config(config: { debounceMs: 500, autoRebuildTree: true, watchForNewFiles: true, watchForDeleted: true, watchForChanged: true })
Testing
A testing framework (Vitest) is now included. Initial unit tests cover path normalization, glob-to-regexp conversion, and platform-specific path handling.
To run tests and check coverage:
npm test
npm run coverage
Recent Improvements
- Improved exclusions logic, ignoring hidden virtual environments (e.g.,
.venv
) and other common unwanted directories. This helps keep dependency graphs clean and relevant. - Testing framework
- Added more programming languages
Future Improvements
- Add more sophisticated importance calculation algorithms
- Enhance diagram customization options
- Support for exporting diagrams to additional formats
License
This project is licensed under the GNU General Public License v3 (GPL-3.0). See the LICENSE file for the full license text.
Server配置
{
"mcpServers": {
"file-scope-mcp": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/metorial/mcp-container--admica--filescopemcp--file-scope-mcp",
"npm run start --base-dir base-dir"
],
"env": {}
}
}
}