Skip to main content
Glama
blakeyoder

TypeScript Definitions MCP Server

by blakeyoder

validate_interface_implementation

Check if TypeScript code correctly implements a specified interface by comparing implementation against the interface definition.

Instructions

Validate if code correctly implements an interface

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
implementationYesThe implementation code to validate
interfaceDefinitionYesThe interface definition
interfaceNameYesName of the interface being implemented

Implementation Reference

  • MCP server handler method for 'validate_interface_implementation' tool. Validates arguments, delegates to TypeValidator, and formats the JSON response.
    private async handleValidateInterfaceImplementation( implementation: string, interfaceName: string, interfaceDefinition: string ) { const result = this.typeValidator.validateInterfaceImplementation( implementation, interfaceName, interfaceDefinition ); return { content: [ { type: "text", text: JSON.stringify(result, null, 2) } ] }; }
  • Core implementation of interface validation logic. Combines interface definition and implementation code, compiles with TypeScript compiler API, and collects semantic diagnostics to determine validity.
    validateInterfaceImplementation(implementation: string, interfaceName: string, interfaceDefinition: string): ValidationResult { const errors: ValidationError[] = []; const warnings: ValidationWarning[] = []; try { // Combine interface definition with implementation const combinedCode = `${interfaceDefinition}\n\n${implementation}`; const sourceFile = ts.createSourceFile( "temp.ts", combinedCode, ts.ScriptTarget.Latest, true ); const defaultCompilerHost = ts.createCompilerHost(this.compilerOptions); const compilerHost = { ...defaultCompilerHost, getSourceFile: (fileName: string, languageVersion: ts.ScriptTarget) => { if (fileName === "temp.ts") { return sourceFile; } return defaultCompilerHost.getSourceFile(fileName, languageVersion); } }; const program = ts.createProgram(["temp.ts"], this.compilerOptions, compilerHost); const diagnostics = program.getSemanticDiagnostics(sourceFile); for (const diagnostic of diagnostics) { const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); const position = diagnostic.start ? sourceFile.getLineAndCharacterOfPosition(diagnostic.start) : undefined; errors.push({ message, line: position ? position.line + 1 : undefined, column: position ? position.character + 1 : undefined, code: diagnostic.code?.toString() }); } } catch (error) { errors.push({ message: `Interface validation failed: ${error instanceof Error ? error.message : String(error)}`, code: "INTERFACE_VALIDATION_ERROR" }); } return { valid: errors.length === 0, errors, warnings }; }
  • Registration of the 'validate_interface_implementation' tool in the MCP server's list of tools, including name, description, and input schema.
    { name: "validate_interface_implementation", description: "Validate if code correctly implements an interface", inputSchema: { type: "object", properties: { implementation: { type: "string", description: "The implementation code to validate" }, interfaceName: { type: "string", description: "Name of the interface being implemented" }, interfaceDefinition: { type: "string", description: "The interface definition" } }, required: ["implementation", "interfaceName", "interfaceDefinition"] } },
  • Dispatch case in the CallToolRequestHandler switch statement that routes 'validate_interface_implementation' calls to the handler method.
    case "validate_interface_implementation": { const implArgs = this.validateArgs<ToolArguments["validate_interface_implementation"]>(args); return await this.handleValidateInterfaceImplementation( implArgs.implementation, implArgs.interfaceName, implArgs.interfaceDefinition ); }
  • TypeScript interface definition for the tool's input arguments used for internal type safety.
    validate_interface_implementation: { implementation: string; interfaceName: string; interfaceDefinition: string; };

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