@hechtcarmel/vertica-mcp
Version:
MCP server for Vertica database operations with configurable readonly mode
70 lines • 2.65 kB
JavaScript
import { z } from "zod";
import { VerticaService } from "../services/vertica-service.js";
import { getDatabaseConfig } from "../config/database.js";
import { formatTableStructure, safeJsonStringify } from "../utils/response-formatter.js";
import { validateTableName, validateSchemaName, } from "../utils/table-helpers.js";
export default class GetTableStructureTool {
name = "get_table_structure";
description = "Get detailed structure information for a specific table including columns, data types, constraints, and metadata.";
inputSchema = {
type: "object",
properties: {
tableName: {
type: "string",
description: "Name of the table to analyze.",
},
schemaName: {
type: "string",
description: "Schema name (optional, defaults to configured default schema).",
},
},
required: ["tableName"],
};
async execute(input) {
const parsed = this.parseInput(input);
let service = null;
try {
validateTableName(parsed.tableName);
if (parsed.schemaName) {
validateSchemaName(parsed.schemaName);
}
const config = getDatabaseConfig();
service = new VerticaService(config);
const structure = await service.getTableStructure(parsed.tableName, parsed.schemaName);
const formatted = formatTableStructure(structure);
return safeJsonStringify({
success: true,
...formatted,
queriedAt: new Date().toISOString(),
}, 2);
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
return safeJsonStringify({
success: false,
error: errorMessage,
tableName: parsed.tableName,
schemaName: parsed.schemaName,
queriedAt: new Date().toISOString(),
}, 2);
}
finally {
if (service) {
try {
await service.disconnect();
}
catch (error) {
console.error("Warning during service cleanup:", error instanceof Error ? error.message : String(error));
}
}
}
}
parseInput(input) {
const schema = z.object({
tableName: z.string(),
schemaName: z.string().optional(),
});
return schema.parse(input);
}
}
//# sourceMappingURL=get-table-structure.js.map