The DependencyMCP Server is a Model Context Protocol server that analyzes codebases to generate dependency graphs and architectural insights. It helps you understand code structure, dependencies, and architectural patterns across multiple programming languages.
Follow these steps to install the DependencyMCP server:
npm install
npm run build
Add the server to your MCP settings file (usually located at ~/.config/cline/mcp_settings.json
or equivalent):
{
"mcpServers": {
"DependencyMCP": {
"command": "node",
"args": ["path/to/dependency-mcp/dist/index.js"],
"env": {
"MAX_LINES_TO_READ": "1000",
"CACHE_DIR": "path/to/dependency-mcp/.dependency-cache",
"CACHE_TTL": "3600000"
}
}
}
}
The DependencyMCP server provides several tools you can use to analyze your codebase.
Analyzes dependencies in a codebase and generates a dependency graph.
const result = await client.callTool("DependencyMCP", "analyze_dependencies", {
path: "/path/to/project",
excludePatterns: ["node_modules", "dist"], // optional
maxDepth: 10, // optional
fileTypes: [".ts", ".js", ".cs"] // optional
});
Gets the dependency graph for a codebase in JSON or DOT format.
const result = await client.callTool("DependencyMCP", "get_dependency_graph", {
path: "/path/to/project",
format: "dot" // or "json" (default)
});
Gets detailed metadata about a specific file.
const result = await client.callTool("DependencyMCP", "get_file_metadata", {
path: "/path/to/file.ts"
});
Scores the codebase against architectural rules and patterns.
const result = await client.callTool("DependencyMCP", "get_architectural_score", {
path: "/path/to/project",
rules: [
{
pattern: "src/domain/**/*",
allowed: ["src/domain/**/*"],
forbidden: ["src/infrastructure/**/*"]
}
]
});
Here are examples of the output you can expect from the tools.
{
"src/index.ts": {
"path": "src/index.ts",
"imports": ["./utils", "./services/parser"],
"exports": ["analyze", "generateGraph"],
"namespaces": [],
"architecturalLayer": "Infrastructure",
"dependencies": ["src/utils.ts", "src/services/parser.ts"],
"dependents": []
}
}
{
"score": 85,
"violations": [
"src/domain/user.ts -> src/infrastructure/database.ts violates architectural rules"
],
"details": "Score starts at 100 and deducts 5 points per violation"
}
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "DependencyMCP" '{"command":"node","args":["path/to/dependency-mcp/dist/index.js"],"env":{"MAX_LINES_TO_READ":"1000","CACHE_DIR":"path/to/dependency-mcp/.dependency-cache","CACHE_TTL":"3600000"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"DependencyMCP": {
"command": "node",
"args": [
"path/to/dependency-mcp/dist/index.js"
],
"env": {
"MAX_LINES_TO_READ": "1000",
"CACHE_DIR": "path/to/dependency-mcp/.dependency-cache",
"CACHE_TTL": "3600000"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"DependencyMCP": {
"command": "node",
"args": [
"path/to/dependency-mcp/dist/index.js"
],
"env": {
"MAX_LINES_TO_READ": "1000",
"CACHE_DIR": "path/to/dependency-mcp/.dependency-cache",
"CACHE_TTL": "3600000"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect