@hechtcarmel/vertica-mcp
Version:
MCP (Model Context Protocol) server for readonly Vertica database operations
65 lines • 2.29 kB
JavaScript
import { z } from "zod";
import { VerticaService } from "../services/vertica-service.js";
import { getDatabaseConfig } from "../config/database.js";
export default class ListTablesTool {
name = "list_tables";
description = "List all tables in a schema with metadata";
inputSchema = {
type: "object",
properties: {
schemaName: {
type: "string",
description: "Schema name (optional, defaults to configured default schema)",
},
},
required: [],
};
async execute(input) {
const parsed = this.parseInput(input);
let verticaService = null;
try {
const config = getDatabaseConfig();
verticaService = new VerticaService(config);
const tables = await verticaService.listTables(parsed.schemaName);
return JSON.stringify({
success: true,
schema: parsed.schemaName || config.defaultSchema || "public",
tableCount: tables.length,
tables: tables.map((table) => ({
schemaName: table.schemaName,
tableName: table.tableName,
owner: table.owner,
comment: table.comment,
rowCount: table.rowCount,
})),
queriedAt: new Date().toISOString(),
}, null, 2);
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
return JSON.stringify({
success: false,
error: errorMessage,
schemaName: parsed.schemaName,
queriedAt: new Date().toISOString(),
}, null, 2);
}
finally {
if (verticaService) {
try {
await verticaService.disconnect();
}
catch (error) {
console.warn("Warning during service cleanup:", error);
}
}
}
}
parseInput(input) {
const schema = z.object({
schemaName: z.string().optional(),
});
return schema.parse(input);
}
}
//# sourceMappingURL=list-tables.js.map