extract_schemas
Extract MCP tool definitions from server source code by scanning for tool calls and parsing their Zod schemas to analyze server capabilities.
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)The main execution handler for the 'extract_schemas' tool. It validates input with Zod, invokes extractProducerSchemas on the specified directory, and returns the extracted ProducerSchemas as JSON.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 to the extract_schemas tool (rootDir, include globs, exclude globs).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)Registration of the extract_schemas tool in the ListTools response, defining its name, description, and JSON input schema.{ 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 extractProducerSchemas that wraps language-specific parsers. Defaults to TypeScript parser and delegates the extraction.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, }); }
- src/languages/typescript.ts:18-57 (helper)Core TypeScript parser implementation for extractSchemas. Uses ts-morph to scan files for server.tool() calls, parse Zod schemas into JSON Schema, and collect ProducerSchema objects.async extractSchemas(options: ExtractOptions): Promise<ProducerSchema[]> { console.log(`[TypeScript] Scanning: ${options.rootDir}`); const project = new Project({ tsConfigFilePath: undefined, skipAddingFilesFromTsConfig: true, }); // Add source files const patterns = options.include || this.filePatterns; const excludePatterns = options.exclude || ['**/node_modules/**', '**/dist/**']; project.addSourceFilesAtPaths( patterns.map(p => `${options.rootDir}/${p}`) ); const schemas: ProducerSchema[] = []; for (const sourceFile of project.getSourceFiles()) { const filePath = sourceFile.getFilePath(); // Skip excluded patterns if (excludePatterns.some(pattern => filePath.includes(pattern.replace('**/', '')))) { continue; } // Find all server.tool() calls const toolCalls = this.findToolCalls(sourceFile); for (const toolCall of toolCalls) { const schema = this.parseToolCall(toolCall, filePath); if (schema) { schemas.push(schema); } } } console.log(`[TypeScript] Found ${schemas.length} tool definitions`); return schemas; }