Skip to main content
Glama

extract_file

Extract MCP tool definitions from TypeScript files to detect schema mismatches between data producers and consumers through static analysis.

Instructions

Extract MCP tool definitions from a single TypeScript file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to a TypeScript file

Implementation Reference

  • MCP server handler for the 'extract_file' tool. Parses input, calls extractFromFile helper, and returns JSON-formatted schemas.
    case 'extract_file': {
      const input = ExtractFileInput.parse(args);
      log(`Extracting from file: ${input.filePath}`);
      
      const schemas = await extractFromFile(input.filePath);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              count: schemas.length,
              schemas,
            }, null, 2),
          },
        ],
      };
    }
  • Zod input schema for validating 'extract_file' tool arguments.
    const ExtractFileInput = z.object({
      filePath: z.string().describe('Path to a single TypeScript file to extract schemas from'),
    });
  • src/index.ts:143-153 (registration)
    Tool registration in the MCP server's listTools response, including name, description, and JSON input schema.
    {
      name: 'extract_file',
      description: 'Extract MCP tool definitions from a single TypeScript file.',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: { type: 'string', description: 'Path to a TypeScript file' },
        },
        required: ['filePath'],
      },
    },
  • Main helper function implementing file-based schema extraction by delegating to language-specific parsers.
    export async function extractFromFile(filePath: string, language?: string): Promise<ProducerSchema[]> {
      // For backward compatibility, default to TypeScript
      const lang = language || 'typescript';
    
      if (!hasParser(lang)) {
        throw new Error(
          `No parser available for language: ${lang}. Make sure to call bootstrapLanguageParsers() at startup.`
        );
      }
    
      const parser = getParser(lang);
    
      // Extract from the directory containing the file
      const rootDir = filePath.substring(0, filePath.lastIndexOf('/') || filePath.lastIndexOf('\\'));
      const fileName = filePath.substring((filePath.lastIndexOf('/') || filePath.lastIndexOf('\\')) + 1);
    
      const allSchemas = await parser.extractSchemas({
        rootDir: rootDir || '.',
        include: [fileName],
      });
    
      return allSchemas.filter(s => s.location.file === filePath);
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states what the tool does but doesn't disclose behavioral traits like error handling, performance characteristics, what happens if the file doesn't exist or isn't TypeScript, whether extraction is partial or complete, or what format the extracted definitions are in. This is a significant gap for a tool with no annotation coverage.

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, efficient sentence with zero waste. It's front-loaded with the core purpose and appropriately sized for a tool with one parameter and clear scope.

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

Completeness2/5

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

Given no annotations and no output schema, the description is incomplete. It doesn't explain what 'MCP tool definitions' means in practice, what the output looks like, or any behavioral context needed for reliable use. For a tool that presumably returns structured data, this leaves significant gaps.

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 schema already documents the single parameter 'filePath' as a path to a TypeScript file. The description adds no additional parameter semantics beyond what the schema provides, such as path format requirements or examples. Baseline 3 is appropriate when the schema does the heavy lifting.

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 specific action ('extract') and resource ('MCP tool definitions') with precise scope ('from a single TypeScript file'). It distinguishes from siblings like extract_schemas (which extracts schemas rather than tool definitions) and trace_file/trace_usage (which trace usage rather than extract definitions).

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

Usage Guidelines2/5

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

No guidance is provided about when to use this tool versus alternatives. While the description implies it works on TypeScript files, it doesn't mention prerequisites, limitations, or when to choose this over siblings like extract_schemas or trace_file. The agent must infer usage from the description alone.

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/Mnehmos/mnehmos.trace.mcp'

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