Skip to main content
Glama
AnuragRai017

Database Updater MCP Server

update_database

Update database tables from CSV or Excel files by specifying file path, database type, connection string, and target table name.

Instructions

Update the database from a CSV or Excel file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the CSV or Excel file
databaseTypeYesType of database (e.g., PostgreSQL, MySQL, MongoDB, SQLite)
connectionStringYesConnection string for the database
tableNameYesName of the table to update

Implementation Reference

  • Handler for executing the 'update_database' tool: validates arguments, parses CSV/Excel file, parses connection string, logs update (placeholder for actual DB update), returns success message.
    case "update_database": { const filePath = String(request.params.arguments?.filePath); const databaseType = String(request.params.arguments?.databaseType); const connectionString = String(request.params.arguments?.connectionString); const tableName = String(request.params.arguments?.tableName); if (!filePath || !databaseType || !connectionString || !tableName) { throw new McpError(ErrorCode.InvalidParams, "File path, database type, connection string, and table name are required"); } try { const fileExtension = filePath.split('.').pop()?.toLowerCase(); let results: any[] = []; if (fileExtension === 'csv') { results = await parseCsvFile(filePath); } else if (fileExtension === 'xlsx' || fileExtension === 'xls') { results = await parseExcelFile(filePath); } else { throw new McpError(ErrorCode.InvalidParams, "Unsupported file type. Only CSV and Excel files are supported."); } // Placeholder for database interaction logic const connectionDetails = parseConnectionString(connectionString); console.log(`Updating database of type ${databaseType} with connection details ${JSON.stringify(connectionDetails)} and table name ${tableName} with data:`, results); // Add database update logic here based on databaseType and connectionDetails // For example, you might use a library like 'pg' for PostgreSQL, 'mysql' for MySQL, or 'mongodb' for MongoDB // This is a placeholder, so for now, we'll just log the data return { content: [{ type: "text", text: `Successfully updated database from ${filePath}` }] }; } catch (error: any) { console.error("Error updating database:", error); throw new McpError(ErrorCode.InternalError, `Error updating database: ${error.message}`); } }
  • src/index.ts:125-150 (registration)
    Registration of the 'update_database' tool in ListToolsRequestSchema handler, including name, description, and input schema.
    { name: "update_database", description: "Update the database from a CSV or Excel file", inputSchema: { type: "object", properties: { filePath: { type: "string", description: "Path to the CSV or Excel file" }, databaseType: { type: "string", description: "Type of database (e.g., PostgreSQL, MySQL, MongoDB, SQLite)" }, connectionString: { type: "string", description: "Connection string for the database" }, tableName: { type: "string", description: "Name of the table to update" } }, required: ["filePath", "databaseType", "connectionString", "tableName"] } }
  • Helper function to parse CSV files into array of objects, used by update_database handler.
    async function parseCsvFile(filePath: string): Promise<any[]> { return new Promise((resolve, reject) => { const results: any[] = []; fs.createReadStream(filePath) .pipe(csvParser()) .on('data', (data: any) => results.push(data)) .on('end', () => resolve(results)) .on('error', (error: any) => reject(error)); }); }
  • Helper function to parse Excel files into array of objects, used by update_database handler.
    async function parseExcelFile(filePath: string): Promise<any[]> { const workbook = XLSX.readFile(filePath); const sheetName = workbook.SheetNames[0]; const worksheet = workbook.Sheets[sheetName]; return XLSX.utils.sheet_to_json(worksheet); }
  • Helper function to parse database connection string into details object, used by update_database handler.
    function parseConnectionString(connectionString: string): any { // This is a basic example, you might need a more robust parser try { const url = new URL(connectionString); if (url.protocol === 'mongodb:') { return { type: 'mongodb', url: connectionString }; } else { const parts = connectionString.split(';'); const connectionDetails: any = {}; parts.forEach(part => { const [key, value] = part.split('='); if (key && value) { connectionDetails[key.trim()] = value.trim(); } }); return connectionDetails; } } catch (e) { // If it's not a URL, assume it's a semicolon-separated string const parts = connectionString.split(';'); const connectionDetails: any = {}; parts.forEach(part => { const [key, value] = part.split('='); if (key && value) { connectionDetails[key.trim()] = value.trim(); } }); return connectionDetails; } }
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AnuragRai017/database-updater-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server