Skip to main content
Glama
codedrop-codes

Refactory

refactory_depmap

Map dependencies of a file: discover its consumers, dependencies, and circular dependencies to understand code structure.

Instructions

Map dependencies for a file — who requires it (consumers), what it requires (dependencies), detect circular deps.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesPath to the file to map
projectDirNoProject root directory

Implementation Reference

  • Core handler: mapDependencies() — given {file, projectDir}, scans all project files to find consumers (files that import the target), dependencies (what the target imports), dynamic require risks, and the full dependency graph.
    function mapDependencies({ file, projectDir }) {
      const projDir = path.resolve(projectDir || path.dirname(file));
      const absFile = path.resolve(file);
      const allFiles = collectFiles(projDir);
      const graph = {}, consumers = [], dependencies = [], dynamicRisks = [];
      const rel = (p) => path.relative(projDir, p);
    
      for (const f of allFiles) {
        const reqs = readReqs(f);
        const resolved = reqs.static
          .map((r) => resolveLocal(r, f, projDir))
          .filter(Boolean);
        graph[f] = resolved;
        if (f !== absFile && resolved.includes(absFile)) consumers.push(f);
        if (f === absFile) {
          dependencies.push(...resolved);
          reqs.dynamic.forEach((d) => dynamicRisks.push(`${rel(f)}: require(${d})`));
        }
      }
      // Flag dynamic requires in consumers of target
      for (const c of consumers) {
        const reqs = readReqs(c);
        reqs.dynamic.forEach((d) => dynamicRisks.push(`${rel(c)}: require(${d})`));
      }
    
      const relGraph = {};
      for (const [k, v] of Object.entries(graph)) relGraph[rel(k)] = v.map(rel);
    
      return { consumers: consumers.map(rel), dependencies: dependencies.map(rel), dynamicRisks, graph: relGraph };
    }
  • Helper: extractRequires() — parses source code for require(), import from, and side-effect import statements using regex.
    function extractRequires(source) {
      const statics = new Set(), dynamics = new Set();
      let m;
      const re1 = new RegExp(RE_REQUIRE.source, "g");
      while ((m = re1.exec(source))) statics.add(m[2]);
      const re2 = new RegExp(RE_DYNAMIC.source, "g");
      while ((m = re2.exec(source))) dynamics.add(m[1].trim());
      const re3 = new RegExp(RE_IMPORT_FROM.source, "g");
      while ((m = re3.exec(source))) statics.add(m[2]);
      const re4 = new RegExp(RE_IMPORT_SIDE.source, "g");
      while ((m = re4.exec(source))) statics.add(m[2]);
      return { static: [...statics], dynamic: [...dynamics] };
    }
  • Helper: resolveLocal() — resolves a local require path (relative/absolute) to an actual file on disk, trying common extensions.
    function resolveLocal(reqPath, fromFile, projectDir) {
      if (!reqPath.startsWith(".") && !reqPath.startsWith("/")) return null;
      const base = path.dirname(fromFile);
      for (const suffix of ["", ".js", ".ts", ".mjs", ".cjs", "/index.js", "/index.ts"]) {
        const abs = path.resolve(base, reqPath + suffix);
        if (abs.startsWith(projectDir) && fs.existsSync(abs) && fs.statSync(abs).isFile()) return abs;
      }
      return null;
    }
  • Helper: collectFiles() — recursively collects all JS/TS files in a directory, skipping node_modules and .git.
    function collectFiles(dir, exts = [".js", ".ts", ".mjs", ".cjs"]) {
      const results = [];
      if (!fs.existsSync(dir)) return results;
      for (const ent of fs.readdirSync(dir, { withFileTypes: true })) {
        const full = path.join(dir, ent.name);
        if (ent.isDirectory()) {
          if (ent.name !== "node_modules" && ent.name !== ".git") results.push(...collectFiles(full, exts));
        } else if (exts.some((e) => ent.name.endsWith(e))) {
          results.push(full);
        }
      }
      return results;
    }
  • Schema and registration: defines the 'refactory_depmap' tool with name, description, and inputSchema (file, projectDir).
    {
      name: "refactory_depmap",
      description: "Map dependencies for a file — who requires it (consumers), what it requires (dependencies), detect circular deps.",
      inputSchema: {
        type: "object",
        properties: {
          file: { type: "string", description: "Path to the file to map" },
          projectDir: { type: "string", description: "Project root directory" },
        },
        required: ["file"],
      },
    },
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description adds 'detect circular deps' as a behavioral trait. However, it does not disclose side effects, permissions, or limitations. For a read-only mapping tool, it provides moderate transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, concise sentence with clear, front-loaded structure using dashes to enumerate outputs. No unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description lists three output aspects but does not explain how they are returned (e.g., lists, graphs). With no output schema, more detail on the return format would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the description adds no extra meaning beyond the schema. It does not elaborate on parameter values or constraints beyond what the schema specifies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Map', the resource 'dependencies for a file', and distinct results: consumers, dependencies, and circular dep detection. It differentiates from siblings by specifying this unique dependency-mapping purpose.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when dependency mapping is needed but lacks explicit guidance on when to use this tool versus alternatives like refactory_analyze. No 'when-not' or alternative names are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/codedrop-codes/refactory'

If you have feedback or need assistance with the MCP directory API, please join our Discord server