Skip to main content
Glama
blakeyoder

TypeScript Definitions MCP Server

by blakeyoder

check_type_compatibility

Verify if a source type can be assigned to a target type in TypeScript. This tool helps developers validate type compatibility for safer code and better type safety.

Instructions

Check if two types are compatible/assignable

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceTypeYesThe source type
targetTypeYesThe target type

Implementation Reference

  • Core handler function that implements the type compatibility check by generating test TypeScript code with an assignment from sourceType to targetType and validating it using the TypeScript compiler diagnostics.
    checkTypeCompatibility(sourceType: string, targetType: string): ValidationResult {
      const errors: ValidationError[] = [];
      const warnings: ValidationWarning[] = [];
    
      try {
        // Create a test assignment to check compatibility
        const testCode = `
          let source: ${sourceType};
          let target: ${targetType};
          target = source; // This will fail if types are incompatible
        `;
    
        const result = this.validateTypeUsage(testCode);
        
        // Filter out assignment-specific errors and focus on type compatibility
        const compatibilityErrors = result.errors.filter(error => 
          error.message.includes("not assignable") || 
          error.message.includes("incompatible")
        );
    
        errors.push(...compatibilityErrors);
        warnings.push(...result.warnings);
    
      } catch (error) {
        errors.push({
          message: `Type compatibility check failed: ${error instanceof Error ? error.message : String(error)}`,
          code: "COMPATIBILITY_ERROR"
        });
      }
    
      return {
        valid: errors.length === 0,
        errors,
        warnings
      };
    }
  • MCP server wrapper handler that invokes the core type validator's checkTypeCompatibility and formats the response as MCP content.
    private async handleCheckTypeCompatibility(sourceType: string, targetType: string) {
      const result = this.typeValidator.checkTypeCompatibility(sourceType, targetType);
      
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({
              sourceType,
              targetType,
              ...result
            }, null, 2)
          }
        ]
      };
    }
  • Tool registration in the listTools response, defining the tool name, description, and input schema.
    {
      name: "check_type_compatibility",
      description: "Check if two types are compatible/assignable",
      inputSchema: {
        type: "object",
        properties: {
          sourceType: {
            type: "string",
            description: "The source type"
          },
          targetType: {
            type: "string",
            description: "The target type"
          }
        },
        required: ["sourceType", "targetType"]
      }
    },
  • TypeScript type definition for the tool arguments used in validateArgs.
    check_type_compatibility: { sourceType: string; targetType: string };
  • Dispatch case in CallToolRequestSchema handler that routes the tool call to the appropriate handler method.
    case "check_type_compatibility": {
      const compatArgs = this.validateArgs<ToolArguments["check_type_compatibility"]>(args);
      return await this.handleCheckTypeCompatibility(
        compatArgs.sourceType,
        compatArgs.targetType
      );
    }

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