validate_interface_implementation
Check if code correctly implements a TypeScript interface by comparing implementation against the interface definition.
Instructions
Validate if code correctly implements an interface
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| implementation | Yes | The implementation code to validate | |
| interfaceName | Yes | Name of the interface being implemented | |
| interfaceDefinition | Yes | The interface definition |
Implementation Reference
- src/type-validator.ts:109-162 (handler)Core handler function that validates interface implementation by combining interface definition and implementation code, compiling with TypeScript, and reporting semantic diagnostics.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 }; }
- src/mcp-server.ts:143-160 (schema)JSON Schema defining the input parameters for the validate_interface_implementation tool.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"] }
- src/mcp-server.ts:140-161 (registration)Tool registration in the ListTools response, 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"] } },
- src/mcp-server.ts:339-358 (handler)MCP server wrapper handler that delegates to TypeValidator and formats the 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) } ] }; }
- src/mcp-server.ts:232-239 (registration)Tool dispatcher case in the CallToolRequest handler switch statement.case "validate_interface_implementation": { const implArgs = this.validateArgs<ToolArguments["validate_interface_implementation"]>(args); return await this.handleValidateInterfaceImplementation( implArgs.implementation, implArgs.interfaceName, implArgs.interfaceDefinition ); }