Skip to main content
Glama
pickstar-2002

MySQL MCP Server

mysql_export_data

Export MySQL table data to CSV or JSON files with optional filtering, enabling data backup, migration, or analysis.

Instructions

导出表数据到文件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableNameYes表名称
filePathYes导出文件路径
formatYes导出格式
whereNo查询条件(可选)

Implementation Reference

  • The main handler function for mysql_export_data tool. Constructs a SELECT query, executes it via dbManager, exports the result using exportData helper, and returns success message.
    private async handleExportData(args: { tableName: string; filePath: string; format: 'csv' | 'json'; where?: string }): Promise<any> {
      let sql = `SELECT * FROM \`${args.tableName}\``;
      if (args.where) {
        sql += ` WHERE ${args.where}`;
      }
      
      const result = await this.dbManager.query(sql);
      await exportData(result, { format: args.format, filePath: args.filePath });
      
      return {
        content: [
          {
            type: 'text',
            text: `成功导出 ${result.rows.length} 行数据到文件: ${args.filePath}`,
          },
        ],
      };
    }
  • Type definition for ExportOptions used in the exportData helper function.
    export interface ExportOptions {
      format: 'csv' | 'json';
      filePath: string;
      includeHeaders?: boolean;
    }
  • src/server.ts:196-209 (registration)
    Tool registration in the ListToolsRequestSchema handler, including name, description, and inputSchema definition.
    {
      name: 'mysql_export_data',
      description: '导出表数据到文件',
      inputSchema: {
        type: 'object',
        properties: {
          tableName: { type: 'string', description: '表名称' },
          filePath: { type: 'string', description: '导出文件路径' },
          format: { type: 'string', enum: ['csv', 'json'], description: '导出格式' },
          where: { type: 'string', description: '查询条件(可选)' },
        },
        required: ['tableName', 'filePath', 'format'],
      },
    },
  • Helper function that performs the actual data export to CSV or JSON file, called by the handler.
    export async function exportData(data: QueryResult, options: ExportOptions): Promise<void> {
      const { format, filePath, includeHeaders = true } = options;
      
      // 确保目录存在
      const dir = path.dirname(filePath);
      await fs.mkdir(dir, { recursive: true });
    
      if (format === 'json') {
        await fs.writeFile(filePath, JSON.stringify(data.rows, null, 2), 'utf-8');
      } else if (format === 'csv') {
        if (data.rows.length === 0) {
          await fs.writeFile(filePath, '', 'utf-8');
          return;
        }
    
        const headers = Object.keys(data.rows[0]).map(key => ({ id: key, title: key }));
        const csvWriter = createObjectCsvWriter({
          path: filePath,
          header: headers,
          encoding: 'utf8'
        });
    
        await csvWriter.writeRecords(data.rows);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action (export) but doesn't cover critical aspects like whether this requires write permissions to the file system, potential performance impacts on the database, file overwriting behavior, or error handling. This is inadequate for a tool that performs I/O operations.

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 phrase ('导出表数据到文件') that directly conveys the core action without unnecessary words. It is front-loaded and appropriately sized for its purpose.

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 tool's complexity (data export with file I/O), lack of annotations, and no output schema, the description is incomplete. It doesn't address behavioral traits, usage context, or return values, leaving significant gaps for an AI agent to understand how to invoke it correctly.

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%, with all parameters documented in the schema (tableName, filePath, format, where). The description adds no additional semantic context beyond what the schema provides, such as explaining the scope of 'where' or file path requirements. Baseline 3 is appropriate as the schema does the heavy lifting.

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 '导出表数据到文件' (Export table data to file) clearly states the verb (export) and resource (table data), making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like mysql_query (which might also retrieve data) or mysql_import_data (the inverse operation), missing full sibling distinction.

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?

No guidance is provided on when to use this tool versus alternatives. For example, it doesn't mention when to choose mysql_export_data over mysql_query for data retrieval or how it relates to mysql_import_data. The description lacks context on prerequisites or exclusions.

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