Skip to main content
Glama
blakeyoder

TypeScript Definitions MCP Server

by blakeyoder

check_type_compatibility

Verify TypeScript type compatibility by checking if a source type can be assigned to a target type, ensuring type safety in your code.

Instructions

Check if two types are compatible/assignable

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceTypeYesThe source type
targetTypeYesThe target type

Implementation Reference

  • Handler function in MCPServer that executes the check_type_compatibility tool by calling TypeValidator and formatting the response.
    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) } ] }; }
  • Core implementation of the type compatibility check using a test assignment compiled with TypeScript compiler API to detect assignability errors.
    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 }; }
  • Registration of the check_type_compatibility tool in the ListTools response, including 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 interface definition for tool arguments used for type-safe validation.
    check_type_compatibility: { sourceType: string; targetType: string }; reinitialize_indexer: { workingDir?: string }; }
  • Switch case dispatcher in CallToolRequestHandler that validates arguments and invokes the tool handler.
    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