Skip to main content
Glama
Yonsn76

MyPos MCP

by Yonsn76

importarTabla

Import data from CSV or JSON text formats into database tables. Specify the target table name, data string, and format to insert records while ensuring column and type compatibility.

Instructions

Sigue estas reglas para importar a una tabla: PROPÓSITO: Importar y insertar datos en una tabla desde un formato de texto (CSV o JSON). PRECAUCIÓN: Asegúrate de que los datos en el texto coincidan con las columnas y tipos de la tabla destino para evitar errores. USO: Proporciona el nombre de la tabla, los datos en formato de texto (string) y el formato (csv o json). EJEMPLO: "Importa los datos del archivo clientes.csv a la tabla clientes."

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
columnasNoColumnas a importar (opcional, para CSV)
datosYesDatos a importar (CSV o JSON)
formatoYesFormato de los datos
tablaYesNombre de la tabla destino

Implementation Reference

  • The handler function that parses the input data (JSON or CSV), constructs parameterized INSERT SQL statements using database-specific placeholders and quoting, and inserts each record into the specified table using the QueryRunner. Handles errors and returns success count.
    async ({ tabla, datos, formato, columnas }) => { try { let registros = []; if (formato === 'json') { registros = JSON.parse(datos); } else { // CSV const rows = datos.split(/\r?\n/).filter(Boolean); let headers = rows[0].split(','); if (columnas && columnas.length > 0) { headers = columnas; } registros = rows.slice(1).map(row => { const values = row.split(','); const obj = {}; headers.forEach((h, i) => { obj[h.trim()] = values[i]?.trim(); }); return obj; }); } let insertedCount = 0; for (const registro of registros) { const cols = columnas && columnas.length > 0 ? columnas : Object.keys(registro); const valores = cols.map(c => registro[c]); const placeholders = makePlaceholders(db_type, valores.length).join(', '); const columnasStr = cols.map(col => quoteIdent(col)).join(', '); const sql = `INSERT INTO ${quoteIdent(tabla)} (${columnasStr}) VALUES (${placeholders})`; await query_runner.runQueryWithParams(sql, valores); insertedCount++; } return { content: [{ type: 'text', text: `Se importaron ${insertedCount} registro(s) en la tabla '${tabla}' exitosamente.` }] }; } catch (e) { return { isError: true, content: [{ type: 'text', text: 'Error al importar datos: ' + (e.message || e) }] }; } }
  • Zod schema defining the input parameters for the tool: table name, data string (CSV/JSON), format, and optional columns.
    { tabla: z.string().describe('Nombre de la tabla destino'), datos: z.string().describe('Datos a importar (CSV o JSON)'), formato: z.enum(['csv', 'json']).describe('Formato de los datos'), columnas: z.array(z.string()).optional().describe('Columnas a importar (opcional, para CSV)'), },
  • mcp_server.js:185-232 (registration)
    The server.tool registration call that defines and registers the 'importarTabla' tool with the MCP server, including its description, input schema, and handler function.
    server.tool( 'importarTabla', 'Sigue estas reglas para importar a una tabla:\n' + 'PROPÓSITO: Importar y insertar datos en una tabla desde un formato de texto (CSV o JSON).\n' + 'PRECAUCIÓN: Asegúrate de que los datos en el texto coincidan con las columnas y tipos de la tabla destino para evitar errores.\n' + 'USO: Proporciona el nombre de la tabla, los datos en formato de texto (string) y el formato (csv o json).\n' + 'EJEMPLO: "Importa los datos del archivo clientes.csv a la tabla clientes."', { tabla: z.string().describe('Nombre de la tabla destino'), datos: z.string().describe('Datos a importar (CSV o JSON)'), formato: z.enum(['csv', 'json']).describe('Formato de los datos'), columnas: z.array(z.string()).optional().describe('Columnas a importar (opcional, para CSV)'), }, async ({ tabla, datos, formato, columnas }) => { try { let registros = []; if (formato === 'json') { registros = JSON.parse(datos); } else { // CSV const rows = datos.split(/\r?\n/).filter(Boolean); let headers = rows[0].split(','); if (columnas && columnas.length > 0) { headers = columnas; } registros = rows.slice(1).map(row => { const values = row.split(','); const obj = {}; headers.forEach((h, i) => { obj[h.trim()] = values[i]?.trim(); }); return obj; }); } let insertedCount = 0; for (const registro of registros) { const cols = columnas && columnas.length > 0 ? columnas : Object.keys(registro); const valores = cols.map(c => registro[c]); const placeholders = makePlaceholders(db_type, valores.length).join(', '); const columnasStr = cols.map(col => quoteIdent(col)).join(', '); const sql = `INSERT INTO ${quoteIdent(tabla)} (${columnasStr}) VALUES (${placeholders})`; await query_runner.runQueryWithParams(sql, valores); insertedCount++; } return { content: [{ type: 'text', text: `Se importaron ${insertedCount} registro(s) en la tabla '${tabla}' exitosamente.` }] }; } catch (e) { return { isError: true, content: [{ type: 'text', text: 'Error al importar datos: ' + (e.message || e) }] }; } } );

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/Yonsn76/MyPos-MCP'

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