Skip to main content

Overview

The get_env_graph tool analyzes relationships between environment variables and returns a dependency graph. It shows:
  • Which variables cluster together (used in the same files)
  • Load-bearing variables (used across most of the codebase)
  • Isolated variables (not related to others)
  • Connection strength between variables

Parameters

projectPath
string
Path to the project directory. Defaults to current working directory.

Response

graph
object
required
The environment variable dependency graph
clusters
array
required
Array of detected variable clusters
loadBearingVars
string[]
required
Array of load-bearing variable names (used in many files)
isolatedVars
string[]
required
Array of isolated variable names (not connected to others)
stats
object
required
Graph statistics
metadata
object
required
Scan metadata

Example Response

{
  "graph": {
    "nodes": [
      {
        "name": "DATABASE_URL",
        "usageCount": 12,
        "fileCount": 8,
        "cluster": "Database",
        "isLoadBearing": true,
        "connections": 5
      },
      {
        "name": "DB_HOST",
        "usageCount": 4,
        "fileCount": 3,
        "cluster": "Database",
        "isLoadBearing": false,
        "connections": 3
      },
      {
        "name": "API_KEY",
        "usageCount": 8,
        "fileCount": 6,
        "cluster": "API",
        "isLoadBearing": true,
        "connections": 2
      },
      {
        "name": "JWT_SECRET",
        "usageCount": 6,
        "fileCount": 4,
        "cluster": "Authentication",
        "isLoadBearing": false,
        "connections": 2
      },
      {
        "name": "SESSION_SECRET",
        "usageCount": 5,
        "fileCount": 4,
        "cluster": "Authentication",
        "isLoadBearing": false,
        "connections": 3
      }
    ],
    "edges": [
      {
        "from": "DATABASE_URL",
        "to": "DB_HOST",
        "weight": 2,
        "sharedFiles": [
          "src/db/connection.ts",
          "src/config/database.ts"
        ]
      },
      {
        "from": "JWT_SECRET",
        "to": "SESSION_SECRET",
        "weight": 3,
        "sharedFiles": [
          "src/auth/jwt.ts",
          "src/middleware/session.ts",
          "src/config/auth.ts"
        ]
      },
      {
        "from": "API_KEY",
        "to": "API_SECRET",
        "weight": 4,
        "sharedFiles": [
          "src/api/client.ts",
          "src/services/external-api.ts",
          "src/config/api.ts"
        ]
      }
    ],
    "adjacencyList": {
      "DATABASE_URL": ["DB_HOST", "DB_PORT", "DB_NAME", "DB_USER", "DB_PASSWORD"],
      "DB_HOST": ["DATABASE_URL", "DB_PORT", "DB_NAME"],
      "API_KEY": ["API_SECRET", "API_ENDPOINT"],
      "JWT_SECRET": ["SESSION_SECRET", "AUTH_EXPIRY"],
      "SESSION_SECRET": ["JWT_SECRET", "COOKIE_SECRET", "AUTH_EXPIRY"]
    }
  },
  "clusters": [
    {
      "name": "Database",
      "variables": ["DATABASE_URL", "DB_HOST", "DB_PORT", "DB_USER", "DB_PASSWORD", "DB_NAME"],
      "size": 6
    },
    {
      "name": "Authentication",
      "variables": ["JWT_SECRET", "SESSION_SECRET", "COOKIE_SECRET", "AUTH_EXPIRY"],
      "size": 4
    },
    {
      "name": "API",
      "variables": ["API_KEY", "API_SECRET", "API_ENDPOINT"],
      "size": 3
    }
  ],
  "loadBearingVars": [
    "DATABASE_URL",
    "API_KEY",
    "NODE_ENV"
  ],
  "isolatedVars": [
    "LEGACY_FEATURE_FLAG",
    "TEMP_DEBUG_MODE"
  ],
  "stats": {
    "totalNodes": 42,
    "totalEdges": 87,
    "totalClusters": 8,
    "avgConnections": 4.14
  },
  "metadata": {
    "projectPath": "/Users/dev/my-project",
    "scannedFiles": 156,
    "cacheHit": false,
    "duration": 298
  }
}

Usage Example

Get the dependency graph:
{
  "name": "get_env_graph",
  "arguments": {
    "projectPath": "/path/to/project"
  }
}
Minimal call:
{
  "name": "get_env_graph",
  "arguments": {}
}

Graph Concepts

Nodes

Each node represents an environment variable with:
  • usageCount: How many times it appears in code
  • fileCount: How many files use it
  • cluster: The functional group it belongs to
  • isLoadBearing: Whether it’s used across many files
  • connections: Number of related variables

Edges

Edges represent relationships between variables:
  • weight: Number of files where both variables are used together
  • sharedFiles: Specific files creating the connection
Higher weight = stronger relationship = variables likely related functionally.

Load-Bearing Variables

Variables used across a significant portion of the codebase. These are:
  • Critical to application functionality
  • High-impact if misconfigured
  • Should be carefully documented and validated
Typically includes:
  • Database connection strings
  • API keys used throughout the app
  • Environment indicators (NODE_ENV)
  • Base URLs and core configuration

Isolated Variables

Variables with no connections to others. They:
  • Are used in isolation (single file or feature)
  • May be feature flags or legacy code
  • Could be candidates for removal if unused

Clusters

Groups of related variables detected by:
  • Co-occurrence: Used in the same files
  • Naming patterns: Similar prefixes (DB_, AWS_, etc.)
  • Functional grouping: Related purpose
Common clusters:
  • Database: DB_, DATABASE_, POSTGRES_, MYSQL_
  • Authentication: JWT_, SESSION_, AUTH_*
  • API: API_*, *_API_KEY, *_API_SECRET
  • Caching: REDIS_, MEMCACHED_
  • Email: SMTP_, SENDGRID_, MAILGUN_*
  • Monitoring: SENTRY_, DATADOG_
  • Cloud: AWS_, GCP_, AZURE_*

Use Cases

  • Architecture Understanding: Visualize how configuration is organized
  • Impact Analysis: Understand which variables are related before making changes
  • Refactoring: Identify clusters that should be migrated together
  • Documentation: Group related variables in documentation
  • Dependency Tracking: See which variables depend on each other
  • Migration Planning: Plan environment migrations by cluster
  • Code Organization: Understand configuration structure

Visualization

The graph data can be visualized using:
  • Force-directed graph layouts (D3.js, Cytoscape)
  • Network diagrams
  • Cluster maps
  • Adjacency matrices
Nodes can be sized by usageCount and colored by cluster.

Build docs developers (and LLMs) love