Skip to main content
Glama
blakeyoder

TypeScript Definitions MCP Server

by blakeyoder

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
NameRequiredDescriptionDefault
packageNameNoOptional package name to filter results
typeNameYesThe name of the type to look up

Implementation Reference

  • 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) } ] }; }
  • 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; }
  • 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"] }
  • TypeScript interface defining the expected ToolArguments for 'lookup_type', used for type-safe validation.
    lookup_type: { typeName: string; packageName?: string };
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/blakeyoder/typescript-definitions-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server