Skip to main content
Glama

discover_specs

Scan a directory to identify OpenAPI spec files and static subdirectories for auto-mocking, returning a suggested configuration for serving mocks locally.

Instructions

Scan a directory and report what mockzilla can do with it: top-level OpenAPI spec files (with title and endpoint count) plus any static/ subdirs that mockzilla can auto-mock. Returns a suggested_input the agent can hand directly to serve_locally. Use this when the user says 'I have a folder of specs/files, what's in it?' or 'mock this directory'.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dirYes

Implementation Reference

  • The main handler function for 'discover_specs'. Validates the dir argument, scans for OpenAPI spec files (.yml/.yaml/.json) and static/ subdirectories, returns structured results with a suggested input for serve_locally.
    export async function discoverSpecs(args) {
      const dir = args.dir;
      if (typeof dir !== "string" || dir.length === 0) {
        throw new Error("`dir` must be a non-empty string");
      }
      const dirStat = await stat(dir).catch(() => null);
      if (!dirStat || !dirStat.isDirectory()) {
        throw new Error(`Not a directory: ${dir}`);
      }
    
      const specFiles = [];
      const entries = await readdir(dir, { withFileTypes: true });
    
      for (const entry of entries) {
        if (!entry.isFile()) continue;
        if (!SPEC_EXTS.has(path.extname(entry.name).toLowerCase())) continue;
        const full = path.join(dir, entry.name);
        specFiles.push(await summariseSpec(full));
      }
    
      const staticDir = path.join(dir, "static");
      const staticServices = await discoverStaticServices(staticDir);
    
      return {
        dir,
        spec_files: specFiles,
        static_services: staticServices,
        suggested_input: suggestInput(dir, specFiles, staticServices),
      };
    }
  • Registration and input schema for 'discover_specs' tool. Defines a single required 'dir' string parameter.
    discover_specs: {
      description:
        "Scan a directory and report what mockzilla can do with it: top-" +
        "level OpenAPI spec files (with title and endpoint count) plus any " +
        "`static/` subdirs that mockzilla can auto-mock. Returns a " +
        "`suggested_input` the agent can hand directly to `serve_locally`. " +
        "Use this when the user says 'I have a folder of specs/files, " +
        "what's in it?' or 'mock this directory'.",
      inputSchema: {
        type: "object",
        properties: {
          dir: { type: "string" },
        },
        required: ["dir"],
        additionalProperties: false,
      },
      handler: discoverSpecs,
    },
  • Helper that uses the mockzilla CLI's 'info' command to parse an OpenAPI spec file and extract title, version, openapi_version, and endpoint_count.
    async function summariseSpec(file) {
      // Use `mockzilla info` for the heavy lifting so the spec parsing
      // logic stays in one place. If it fails, surface the error but keep
      // the entry — the agent can decide whether the file is salvageable.
      const resolved = await resolveMockzilla();
      if (!resolved) {
        return {
          path: file,
          error: "mockzilla CLI not installed; can't parse",
        };
      }
      const [cmd, ...prefix] =
        resolved.type === "binary" ? [resolved.path] : resolved.invocation;
      const cmdline = [cmd, ...prefix, "info", file].map(shellEscape).join(" ");
      try {
        const { stdout } = await exec(cmdline);
        const parsed = JSON.parse(stdout);
        return {
          path: file,
          title: parsed.title,
          version: parsed.version,
          openapi_version: parsed.openapi_version,
          endpoint_count: parsed.endpoint_count,
        };
      } catch (err) {
        return {
          path: file,
          error: (err.stderr && err.stderr.trim()) || err.message,
        };
      }
    }
  • Helper that discovers static/ subdirectories, each representing a service mockzilla can auto-mock.
    async function discoverStaticServices(staticDir) {
      const s = await stat(staticDir).catch(() => null);
      if (!s || !s.isDirectory()) return [];
      const entries = await readdir(staticDir, { withFileTypes: true });
      const services = [];
      for (const e of entries) {
        if (!e.isDirectory()) continue;
        services.push({
          name: e.name,
          path: path.join(staticDir, e.name),
        });
      }
      return services;
    }
  • Helper that generates a suggested_input field, telling the agent where to point serve_locally based on what was discovered.
    function suggestInput(dir, specs, services) {
      if (services.length > 0 && specs.length === 0) {
        return {
          input: dir,
          reason:
            "Directory has a `static/` subdir — point serve_locally at the " +
            "parent dir; mockzilla auto-generates specs from each service.",
        };
      }
      if (specs.length === 1 && services.length === 0) {
        return {
          input: specs[0].path,
          reason: "Single spec file — point serve_locally directly at it.",
        };
      }
      if (specs.length > 1) {
        return {
          input: dir,
          reason:
            "Multiple specs — point serve_locally at the directory; each " +
            "spec becomes its own service.",
        };
      }
      if (services.length > 0 && specs.length > 0) {
        return {
          input: dir,
          reason:
            "Mix of static services and specs — point serve_locally at the " +
            "directory; mockzilla picks up both.",
        };
      }
      return null;
    }
Behavior4/5

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

With no annotations, the description explains the tool's non-destructive scanning behavior and output format. Reveals it returns a suggested_input for serve_locally, which is helpful. Could add depth limit or side effects, but adequate.

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?

Two sentences, no fluff, efficient word choice. First sentence states action and output, second gives usage context.

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

Completeness4/5

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

Simple single-parameter tool with clear purpose. Description covers input, scan behavior, and output. Lacks output schema but hints at return value. Complete enough for this complexity.

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?

Only one parameter 'dir' with 0% schema coverage. Description implies it is a directory path but does not describe its format or constraints. Baseline 3 for single required parameter with implicit meaning.

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?

Description clearly states the tool scans a directory and reports OpenAPI spec files and static subdirs, with specific details like returning a suggested_input for serve_locally. This distinguishes it from siblings like peek_openapi.

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

Usage Guidelines4/5

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

Explicitly provides user utterances that trigger this tool ('I have a folder of specs/files, what's in it?' or 'mock this directory'), giving clear context. Lacks explicit when-not-to-use or alternatives, but sufficient.

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/mockzilla/mockzilla-mcp'

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