@hechtcarmel/vertica-mcp
Version:
MCP server for Vertica database operations with configurable readonly mode
81 lines • 2.42 kB
JavaScript
function jsonReplacer(_key, value) {
if (typeof value === "bigint") {
return value.toString();
}
if (value instanceof Date) {
return value.toISOString();
}
if (Buffer.isBuffer(value)) {
return value.toString("base64");
}
return value;
}
export function safeJsonStringify(data, space) {
return JSON.stringify(data, jsonReplacer, space);
}
export function createSuccessResponse(data) {
const response = {
success: true,
data,
executedAt: new Date().toISOString(),
};
return JSON.stringify(response, null, 2);
}
export function createErrorResponse(error) {
let formattedError;
if (typeof error === "string") {
formattedError = { message: error };
}
else if (error instanceof Error) {
formattedError = { message: error.message };
}
else {
formattedError = error;
}
const response = {
success: false,
error: formattedError,
executedAt: new Date().toISOString(),
};
return JSON.stringify(response, null, 2);
}
export function formatQueryResult(result) {
return {
query: result.query,
rowCount: result.rowCount,
fields: result.fields.map((field) => ({
name: field.name,
dataType: field.format,
})),
rows: result.rows,
};
}
export function formatTableStructure(structure) {
return {
table: {
schemaName: structure.schemaName,
tableName: structure.tableName,
tableType: structure.tableType,
owner: structure.owner,
comment: structure.comment,
},
columns: structure.columns.map((col) => ({
name: col.columnName,
dataType: col.dataType,
nullable: col.isNullable,
defaultValue: col.defaultValue,
size: col.columnSize,
decimalDigits: col.decimalDigits,
position: col.ordinalPosition,
comment: col.comment,
})),
constraints: structure.constraints.map((constraint) => ({
name: constraint.constraintName,
type: constraint.constraintType,
column: constraint.columnName,
referencedTable: constraint.referencedTable,
referencedColumn: constraint.referencedColumn,
})),
};
}
//# sourceMappingURL=response-formatter.js.map