Dependency Analysis MCP server

Manage and analyze project dependencies, offering caching and flexible configuration for efficient tracking across complex software ecosystems.
Back to servers
Setup instructions
Provider
mkearl
Release date
Dec 26, 2024
Language
TypeScript
Stats
10 stars

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.

Features

  • Multi-Language Support: Analyzes dependencies in TypeScript, JavaScript, C#, Python, and more
  • Dependency Graph Generation: Creates detailed dependency graphs in JSON or DOT format
  • Architectural Analysis: Infers architectural layers and validates against rules
  • File Metadata: Extracts imports, exports, and other metadata from source files
  • Scoring System: Evaluates codebase against architectural rules and patterns

Installation

Follow these steps to install the DependencyMCP server:

  1. Clone the repository
  2. Install dependencies:
    npm install
    
  3. Build the project:
    npm run build
    

Configuration

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"
      }
    }
  }
}

Environment Variables

  • MAX_LINES_TO_READ: Maximum number of lines to read from each file (default: 1000)
  • CACHE_DIR: Directory to store dependency cache files (default: .dependency-cache)
  • CACHE_TTL: Cache time-to-live in milliseconds (default: 1 hour = 3600000)

Available Tools

The DependencyMCP server provides several tools you can use to analyze your codebase.

analyze_dependencies

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
});

get_dependency_graph

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)
});

get_file_metadata

Gets detailed metadata about a specific file.

const result = await client.callTool("DependencyMCP", "get_file_metadata", {
  path: "/path/to/file.ts"
});

get_architectural_score

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/**/*"]
    }
  ]
});

Example Output

Here are examples of the output you can expect from the tools.

Dependency Graph (JSON)

{
  "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": []
  }
}

Architectural Score

{
  "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"
}

How to install this MCP server

For Claude Code

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.

For Cursor

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.

Adding an MCP server to Cursor globally

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"
            }
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.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

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later