validate-database
validate-databaseValidate Firebird database integrity by checking data and indexes, with options to fix errors and show detailed progress.
Instructions
Validates the integrity of the Firebird database
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| options | No |
Implementation Reference
- src/tools/database.ts:436-466 (registration)Registers the "validate-database" MCP tool, including its handler function that calls the core validateDatabase function and formats the response.
// Add validate-database tool tools.set("validate-database", { name: "validate-database", description: "Validates the integrity of the Firebird database", inputSchema: ValidateDatabaseArgsSchema, handler: async (request) => { const { options } = request; logger.info(`Executing validate-database tool`); try { const result = await validateDatabase(options); return { content: [{ type: "text", text: formatForClaude(result) }] }; } catch (error) { const errorResponse = wrapError(error); logger.error(`Error validating database: ${errorResponse.error} [${errorResponse.errorType || 'UNKNOWN'}]`); return { content: [{ type: "text", text: formatForClaude(errorResponse) }] }; } } }); - src/tools/database.ts:71-78 (schema)Zod input schema for the validate-database tool defining optional validation options.
export const ValidateDatabaseArgsSchema = z.object({ options: z.object({ checkData: z.boolean().default(true).describe("Whether to validate data integrity"), checkIndexes: z.boolean().default(true).describe("Whether to validate indexes"), fixErrors: z.boolean().default(false).describe("Whether to attempt to fix errors"), verbose: z.boolean().default(false).describe("Whether to show detailed progress") }).optional() }); - src/db/management.ts:326-410 (handler)Core implementation of database validation using Firebird's gfix utility to check integrity, parse results for issues, and return validation status.
export const validateDatabase = async ( options: ValidateOptions = {}, config = DEFAULT_CONFIG ): Promise<ValidationResult> => { const startTime = Date.now(); try { // Check if Firebird tools are installed const toolsCheck = await checkFirebirdTools(); if (!toolsCheck.installed) { throw new FirebirdError( `Firebird client tools are not installed. ${toolsCheck.installInstructions}`, 'MISSING_FIREBIRD_TOOLS' ); } // Try to find Firebird bin directory const firebirdBinPath = await findFirebirdBinPath(); // Use GFIX for validation const command = firebirdBinPath ? path.join(firebirdBinPath, 'gfix') : 'gfix'; let args: string[] = [ '-user', config.user || 'SYSDBA', '-password', config.password || 'masterkey' ]; // Add validation options if (options.checkData) { args.push('-v'); // Validate database } if (options.checkIndexes) { args.push('-i'); // Validate indexes } if (options.fixErrors) { args.push('-mend'); // Fix errors } // Add database path args.push(config.database); logger.info(`Starting database validation for ${config.database}`); if (options.verbose) { logger.debug(`Validation command: ${command} ${args.join(' ')}`); } // Execute the validation command const result = await executeCommand(command, args, options.verbose); // Parse the result to determine if the database is valid const issues: string[] = []; const lines = result.split('\n'); for (const line of lines) { if (line.includes('error') || line.includes('corrupt') || line.includes('invalid')) { issues.push(line.trim()); } } const valid = issues.length === 0; const duration = Date.now() - startTime; logger.info(`Validation completed in ${duration}ms, valid: ${valid}, issues: ${issues.length}`); return { success: true, valid, issues, details: result }; } catch (error: any) { const duration = Date.now() - startTime; const errorMessage = `Error validating database: ${error.message || error}`; logger.error(errorMessage); return { success: false, valid: false, issues: [errorMessage], details: error.details || '', error: errorMessage }; } }; - src/db/management.ts:38-43 (schema)TypeScript interface defining the options for database validation, matching the Zod schema.
export interface ValidateOptions { checkData?: boolean; checkIndexes?: boolean; fixErrors?: boolean; verbose?: boolean; }