lookup_type
Find TypeScript type definitions by name and optional package to generate type-safe mocks and test data from project dependencies.
Instructions
Look up TypeScript type definitions by name and optional package
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| packageName | No | Optional package name to filter results | |
| typeName | Yes | The name of the type to look up |
Implementation Reference
- src/mcp-server.ts:275-290 (handler)MCP tool handler for 'lookup_type'. Validates arguments, calls TypeIndexer.findType, and returns JSON-formatted results.private async handleLookupType(typeName: string, packageName?: string) { const results = await this.typeIndexer.findType(typeName, packageName); return { content: [ { type: "text", text: JSON.stringify({ query: { typeName, packageName }, results, count: results.length }, null, 2) } ] }; }
- src/type-indexer.ts:87-118 (helper)Core implementation that searches TypeScript program source files for type definitions matching the name (optionally filtered by package), using caching and AST traversal.async findType(typeName: string, packageName?: string): Promise<TypeDefinition[]> { if (!this.program || !this.typeChecker) { throw new Error("TypeIndexer not initialized. Call initialize() first."); } const cacheKey = `${typeName}:${packageName || ""}`; if (this.typeCache.has(cacheKey)) { const cached = this.typeCache.get(cacheKey)!; // Check cache age const now = Date.now(); if (now - this.getCacheTimestamp(cacheKey) < this.config.maxCacheAge) { return cached; } } const results: TypeDefinition[] = []; for (const sourceFile of this.program.getSourceFiles()) { if (packageName && !this.isFromPackage(sourceFile.fileName, packageName)) { continue; } const definitions = this.extractTypeDefinitions(sourceFile, typeName); results.push(...definitions); } this.typeCache.set(cacheKey, results); this.setCacheTimestamp(cacheKey, Date.now()); return results; }
- src/mcp-server.ts:76-92 (registration)Tool registration in ListToolsRequestSchema handler, defining name, description, and input schema.{ name: "lookup_type", description: "Look up TypeScript type definitions by name and optional package", inputSchema: { type: "object", properties: { typeName: { type: "string", description: "The name of the type to look up" }, packageName: { type: "string", description: "Optional package name to filter results" } }, required: ["typeName"] }
- src/mcp-server.ts:16-16 (schema)TypeScript interface defining the expected ToolArguments for 'lookup_type', used for type-safe validation.lookup_type: { typeName: string; packageName?: string };
- src/mcp-server.ts:212-214 (handler)Dispatch handler in CallToolRequestSchema switch statement that routes to the specific handleLookupType function.case "lookup_type": { const lookupArgs = this.validateArgs<ToolArguments["lookup_type"]>(args); return await this.handleLookupType(lookupArgs.typeName, lookupArgs.packageName);