extract_schemas
Extracts MCP tool definitions from server source code by scanning for tool calls and parsing their Zod schemas to identify schema mismatches.
Instructions
Extract MCP tool definitions (ProducerSchemas) from server source code. Scans for server.tool() calls and parses their Zod schemas.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rootDir | Yes | Root directory of MCP server source code | |
| include | No | Glob patterns to include | |
| exclude | No | Glob patterns to exclude |
Implementation Reference
- src/index.ts:285-309 (handler)MCP CallToolRequest handler case for 'extract_schemas' tool: validates input with Zod schema, invokes extractProducerSchemas, logs progress, and returns JSON result with extracted schemas.case 'extract_schemas': { const input = ExtractSchemasInput.parse(args); log(`Extracting schemas from: ${input.rootDir}`); const schemas = await extractProducerSchemas({ rootDir: input.rootDir, include: input.include, exclude: input.exclude, }); log(`Found ${schemas.length} tool definitions`); return { content: [ { type: 'text', text: JSON.stringify({ success: true, count: schemas.length, schemas, }, null, 2), }, ], }; }
- src/index.ts:45-49 (schema)Zod input schema validation for the 'extract_schemas' tool parameters.const ExtractSchemasInput = z.object({ rootDir: z.string().describe('Root directory of MCP server source code'), include: z.array(z.string()).optional().describe('Glob patterns to include (default: **/*.ts)'), exclude: z.array(z.string()).optional().describe('Glob patterns to exclude (default: node_modules, dist)'), });
- src/index.ts:130-142 (registration)Tool registration in ListToolsResponse: defines name, description, and inputSchema for 'extract_schemas'.{ name: 'extract_schemas', description: 'Extract MCP tool definitions (ProducerSchemas) from server source code. Scans for server.tool() calls and parses their Zod schemas.', inputSchema: { type: 'object', properties: { rootDir: { type: 'string', description: 'Root directory of MCP server source code' }, include: { type: 'array', items: { type: 'string' }, description: 'Glob patterns to include' }, exclude: { type: 'array', items: { type: 'string' }, description: 'Glob patterns to exclude' }, }, required: ['rootDir'], }, },
- src/extract/index.ts:24-44 (helper)Core extraction logic: selects language parser (defaults to TypeScript) and delegates schema extraction to parser.extractSchemas.export async function extractProducerSchemas( options: ExtractorOptions ): Promise<ProducerSchema[]> { // For backward compatibility, default to TypeScript const language = options.language || 'typescript'; // Get parser from registry if (!hasParser(language)) { throw new Error( `No parser available for language: ${language}. Make sure to call bootstrapLanguageParsers() at startup.` ); } const parser = getParser(language); return parser.extractSchemas({ rootDir: options.rootDir, include: options.include, exclude: options.exclude, }); }