Skip to main content
Glama
pickstar-2002

MySQL MCP Server

mysql_import_data

Import data from CSV or JSON files into MySQL tables. Specify table name, file path, format, and optional truncation to load external data into your database.

Instructions

从文件导入数据到表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableNameYes表名称
filePathYes导入文件路径
formatYes文件格式
truncateFirstNo是否先清空表

Implementation Reference

  • The main handler function that executes the mysql_import_data tool: optionally truncates the table, parses the input file using importData helper, and inserts the data row-by-row into the MySQL table using parameterized queries.
    private async handleImportData(args: { tableName: string; filePath: string; format: 'csv' | 'json'; truncateFirst?: boolean }): Promise<any> {
      if (args.truncateFirst) {
        await this.dbManager.query(`TRUNCATE TABLE \`${args.tableName}\``);
      }
      
      const data = await importData({
        format: args.format,
        filePath: args.filePath,
        tableName: args.tableName,
      });
      
      if (data.length === 0) {
        return {
          content: [
            {
              type: 'text',
              text: '导入文件为空,没有数据需要导入',
            },
          ],
        };
      }
      
      const columns = Object.keys(data[0]);
      const placeholders = columns.map(() => '?').join(', ');
      
      let importedRows = 0;
      for (const row of data) {
        const values = columns.map(col => row[col]);
        const sql = `INSERT INTO \`${args.tableName}\` (\`${columns.join('`, `')}\`) VALUES (${placeholders})`;
        const result = await this.dbManager.query(sql, values);
        importedRows += result.affectedRows || 0;
      }
      
      return {
        content: [
          {
            type: 'text',
            text: `成功导入 ${importedRows} 行数据到表 ${args.tableName}`,
          },
        ],
      };
    }
  • Input schema definition for the mysql_import_data tool, specifying required parameters and types for validation.
    inputSchema: {
      type: 'object',
      properties: {
        tableName: { type: 'string', description: '表名称' },
        filePath: { type: 'string', description: '导入文件路径' },
        format: { type: 'string', enum: ['csv', 'json'], description: '文件格式' },
        truncateFirst: { type: 'boolean', description: '是否先清空表', default: false },
      },
      required: ['tableName', 'filePath', 'format'],
    },
  • src/server.ts:210-223 (registration)
    Tool registration in the listTools response, defining name, description, and input schema for mysql_import_data.
    {
      name: 'mysql_import_data',
      description: '从文件导入数据到表',
      inputSchema: {
        type: 'object',
        properties: {
          tableName: { type: 'string', description: '表名称' },
          filePath: { type: 'string', description: '导入文件路径' },
          format: { type: 'string', enum: ['csv', 'json'], description: '文件格式' },
          truncateFirst: { type: 'boolean', description: '是否先清空表', default: false },
        },
        required: ['tableName', 'filePath', 'format'],
      },
    },
  • src/server.ts:261-262 (registration)
    Switch case in CallToolRequest handler that routes mysql_import_data calls to the handleImportData method.
    case 'mysql_import_data':
      return await this.handleImportData(args as any);
  • Supporting utility function that reads and parses data from JSON or CSV files, used by the handler to load import data.
    export async function importData(options: ImportOptions): Promise<any[]> {
      const { format, filePath } = options;
      
      if (format === 'json') {
        const content = await fs.readFile(filePath, 'utf-8');
        return JSON.parse(content);
      } else if (format === 'csv') {
        return new Promise((resolve, reject) => {
          const results: any[] = [];
          
          createReadStream(filePath)
            .pipe(csvParser())
            .on('data', (data: any) => results.push(data))
            .on('end', () => resolve(results))
            .on('error', reject);
        });
      }
      
      throw new Error(`不支持的格式: ${format}`);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions importing data but fails to disclose critical behavioral traits such as whether the operation is destructive (e.g., truncateFirst parameter), authentication requirements, error handling, or performance implications. This is a significant gap for a data import tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Chinese that directly states the tool's purpose without unnecessary words. It is front-loaded and appropriately sized for conveying the core action, making it highly concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a data import tool with no annotations and no output schema, the description is incomplete. It doesn't cover behavioral aspects like side effects, error cases, or return values, leaving gaps that could hinder an AI agent's correct invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all four parameters (tableName, filePath, format, truncateFirst). The description adds no additional meaning beyond the schema, such as explaining parameter interactions or constraints, which aligns with the baseline score when schema coverage is high.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '从文件导入数据到表' clearly states the action (import) and target (data to table) in Chinese, which translates to 'import data from file to table.' It specifies the verb and resource but doesn't differentiate from sibling tools like mysql_export_data or mysql_insert, which handle related operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives such as mysql_insert for direct data insertion or mysql_export_data for the reverse operation. It lacks context about prerequisites like needing an established connection or file format compatibility.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/pickstar-2002/mysql-mcp'

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