extract_schemas
Extract MCP tool definitions from server source code by scanning for server.tool() calls and parsing Zod schemas to detect 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)Executes the extract_schemas tool by parsing input with Zod schema, calling extractProducerSchemas, logging progress, and returning formatted JSON result.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 schema for validating the input parameters (rootDir, include, exclude) to the extract_schemas tool.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)MCP tool registration in the listTools handler, defining name, description, and JSON inputSchema.{ 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)Helper function invoked by the tool handler; selects language parser and delegates schema extraction from source files.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, }); }