Skip to main content
Glama
blakeyoder

TypeScript Definitions MCP Server

by blakeyoder

find_interfaces

Search for TypeScript interfaces by name pattern to access type definitions from project dependencies for generating type-safe mocks and test data.

Instructions

Find interfaces matching a pattern

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesPattern to match interface names (supports wildcards with *)

Implementation Reference

  • Executes the tool logic by calling the type indexer's findInterfaces method with the pattern and returns a formatted JSON response containing matching interfaces.
    private async handleFindInterfaces(pattern: string) {
      const results = await this.typeIndexer.findInterfaces(pattern);
      
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({
              pattern,
              results,
              count: results.length
            }, null, 2)
          }
        ]
      };
  • JSON Schema defining the input for the find_interfaces tool: an object with a required 'pattern' string property.
    inputSchema: {
      type: "object",
      properties: {
        pattern: {
          type: "string",
          description: "Pattern to match interface names (supports wildcards with *)"
        }
      },
      required: ["pattern"]
  • Registration of the find_interfaces tool in the ListToolsRequestSchema response, including name, description, and input schema.
    {
      name: "find_interfaces",
      description: "Find interfaces matching a pattern",
      inputSchema: {
        type: "object",
        properties: {
          pattern: {
            type: "string",
            description: "Pattern to match interface names (supports wildcards with *)"
          }
        },
        required: ["pattern"]
      }
    },
  • Supporting method in TypeIndexer that implements the core logic: scans source files, extracts type definitions, filters interfaces matching the regex-converted pattern.
    async findInterfaces(pattern: string): Promise<TypeDefinition[]> {
      if (!this.program) {
        throw new Error("TypeIndexer not initialized. Call initialize() first.");
      }
    
      const results: TypeDefinition[] = [];
      const regex = new RegExp(pattern.replace(/\*/g, ".*"));
      
      for (const sourceFile of this.program.getSourceFiles()) {
        const definitions = this.extractTypeDefinitions(sourceFile);
        const matching = definitions.filter(def => 
          def.kind === "interface" && regex.test(def.name)
        );
        results.push(...matching);
      }
      
      return results;
  • Handler dispatch registration in the CallToolRequestSchema switch statement for routing find_interfaces calls to the handler.
    case "find_interfaces": {
      const interfaceArgs = this.validateArgs<ToolArguments["find_interfaces"]>(args);
      return await this.handleFindInterfaces(interfaceArgs.pattern);
    }

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