extract_file
Extract MCP tool definitions from TypeScript files to analyze and validate schema compatibility between data producers and consumers.
Instructions
Extract MCP tool definitions from a single TypeScript file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to a TypeScript file |
Implementation Reference
- src/index.ts:311-329 (handler)Main handler for the 'extract_file' tool. Parses the input using ExtractFileInput schema, logs the action, calls extractFromFile to extract schemas from the specified file, and returns the results as JSON.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), }, ], }; }
- src/index.ts:65-67 (schema)Zod schema definition for the extract_file tool input, validating the filePath parameter.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 listTools response, defining name, description, and inputSchema for extract_file.{ 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'], }, },
- src/extract/index.ts:50-72 (helper)Core helper function that performs single-file schema extraction by delegating to the appropriate language parser, filtering results to the target file.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); }