csv-mcp
Version:
A Model Context Protocol (MCP) server for powerful CSV file operations - read, write, query, transform, analyze CSV data with formulas and charts.
236 lines • 4.8 kB
TypeScript
/**
* CSV Types and Interfaces
*/
/**
* CSV file configuration
*/
export interface CSVConfig {
path: string;
delimiter?: string;
hasHeader?: boolean;
encoding?: BufferEncoding;
quote?: string;
escape?: string;
skipEmptyLines?: boolean;
}
/**
* CSV parse options
*/
export interface CSVParseOptions {
delimiter?: string;
quote?: string;
escape?: string;
columns?: boolean | string[];
skip_empty_lines?: boolean;
trim?: boolean;
cast?: boolean;
cast_date?: boolean;
from?: number;
to?: number;
encoding?: BufferEncoding;
}
/**
* CSV write options
*/
export interface CSVWriteOptions {
delimiter?: string;
quote?: string;
escape?: string;
header?: boolean;
columns?: string[] | {
key: string;
header: string;
}[];
quoted?: boolean;
quoted_empty?: boolean;
encoding?: BufferEncoding;
}
/**
* CSV row data - flexible object structure
*/
export type CSVRow = Record<string, any>;
/**
* CSV data result
*/
export interface CSVData {
headers: string[];
rows: CSVRow[];
rowCount: number;
filePath: string;
}
/**
* CSV operation result
*/
export interface CSVOperationResult {
success: boolean;
message: string;
data?: CSVData | CSVRow[] | any;
rowsAffected?: number;
error?: string;
}
/**
* CSV file info
*/
export interface CSVFileInfo {
path: string;
exists: boolean;
size: number;
rowCount?: number;
columnCount?: number;
headers?: string[];
encoding?: string;
delimiter?: string;
}
/**
* CSV query options for filtering and sorting
*/
export interface CSVQueryOptions {
select?: string[];
where?: CSVWhereClause;
orderBy?: CSVOrderBy[];
limit?: number;
offset?: number;
distinct?: boolean;
}
/**
* Where clause for filtering
*/
export interface CSVWhereClause {
column: string;
operator: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'in' | 'notIn' | 'isNull' | 'isNotNull';
value?: any;
and?: CSVWhereClause[];
or?: CSVWhereClause[];
}
/**
* Order by clause for sorting
*/
export interface CSVOrderBy {
column: string;
direction: 'asc' | 'desc';
}
/**
* CSV transformation options
*/
export interface CSVTransformOptions {
addColumn?: {
name: string;
value: any | ((row: CSVRow) => any);
};
removeColumn?: string;
renameColumn?: {
from: string;
to: string;
};
transformColumn?: {
column: string;
transform: (value: any, row: CSVRow) => any;
};
filterRows?: (row: CSVRow) => boolean;
sortBy?: CSVOrderBy[];
}
/**
* CSV statistics for a column
*/
export interface CSVColumnStats {
column: string;
count: number;
nullCount: number;
uniqueCount: number;
dataType: 'string' | 'number' | 'boolean' | 'date' | 'mixed';
min?: number | string;
max?: number | string;
mean?: number;
median?: number;
mode?: any;
sum?: number;
stdDev?: number;
topValues?: {
value: any;
count: number;
}[];
}
/**
* CSV file statistics
*/
export interface CSVStats {
filePath: string;
rowCount: number;
columnCount: number;
headers: string[];
columnStats: CSVColumnStats[];
fileSize: number;
encoding?: string;
delimiter?: string;
}
/**
* CSV merge options
*/
export interface CSVMergeOptions {
type: 'inner' | 'left' | 'right' | 'outer';
leftKey: string;
rightKey: string;
suffix?: {
left: string;
right: string;
};
}
/**
* CSV export format options
*/
export interface CSVExportOptions {
format?: 'csv' | 'json' | 'tsv';
outputPath: string;
overwrite?: boolean;
}
/**
* CSV validation result
*/
export interface CSVValidationResult {
valid: boolean;
errors: CSVValidationError[];
warnings: CSVValidationWarning[];
rowsChecked: number;
}
/**
* CSV validation error
*/
export interface CSVValidationError {
row: number;
column?: string;
message: string;
value?: any;
}
/**
* CSV validation warning
*/
export interface CSVValidationWarning {
row?: number;
column?: string;
message: string;
}
/**
* CSV schema for validation
*/
export interface CSVSchema {
columns: CSVColumnSchema[];
required?: string[];
unique?: string[];
}
/**
* Column schema for validation
*/
export interface CSVColumnSchema {
name: string;
type: 'string' | 'number' | 'boolean' | 'date' | 'email' | 'url';
required?: boolean;
unique?: boolean;
pattern?: RegExp;
min?: number;
max?: number;
minLength?: number;
maxLength?: number;
enum?: any[];
custom?: (value: any, row: CSVRow) => boolean | string;
}
//# sourceMappingURL=csv.d.ts.map