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

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