Skip to main content
Glama
egarcia74

Warp SQL Server MCP

by egarcia74

export_table_csv

Export SQL Server table data to CSV format with optional filters for database, schema, row limits, and WHERE conditions.

Instructions

Export table data in CSV format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYesName of the table to export
databaseNoDatabase name (optional)
schemaNoSchema name (optional, defaults to dbo)
limitNoMaximum number of rows to export (optional)
whereNoWHERE clause conditions (optional)

Implementation Reference

  • The primary handler function implementing export_table_csv tool. Exports table data as CSV, supports streaming for large tables, handles database/schema switching, CSV escaping, performance monitoring, and error handling.
    async exportTableCsv(tableName, database = null, schema = 'dbo', limit = null) {
      try {
        const pool = await this.getConnection();
        const request = pool.request();
    
        // Switch database if specified
        if (database) {
          await request.query(`USE [${database}]`);
        }
    
        // Use streaming handler for CSV export
        const streamingResult = await this.streamingHandler.streamTableExport(request, tableName, {
          schema,
          database,
          limit,
          outputFormat: 'csv'
        });
    
        // Track performance
        if (this.performanceMonitor) {
          const stats = this.streamingHandler.getStreamingStats(streamingResult);
          this.performanceMonitor.recordQuery({
            tool: 'export_table_csv',
            query: `SELECT${limit ? ` TOP ${limit}` : ''} * FROM [${schema}].[${tableName}]`,
            executionTime: streamingResult.performance?.duration || 0,
            success: true,
            database,
            streaming: stats.streaming,
            totalRows: stats.totalRows,
            memoryEfficient: stats.memoryEfficient,
            timestamp: new Date()
          });
        }
    
        // Handle empty results
        if (streamingResult.totalRows === 0) {
          return [
            {
              type: 'text',
              text: 'No data found in table'
            }
          ];
        }
    
        // For streaming results, reconstruct CSV from chunks
        if (streamingResult.streaming && streamingResult.chunks) {
          const csvContent = this.streamingHandler.reconstructFromChunks(
            streamingResult.chunks,
            'csv'
          );
    
          return [
            {
              type: 'text',
              text: csvContent
            }
          ];
        }
    
        // For non-streaming results, convert recordset to CSV
        if (streamingResult.recordset && streamingResult.recordset.length > 0) {
          const headers = Object.keys(streamingResult.recordset[0]);
          const csvHeaders = headers.join(',');
          const csvRows = streamingResult.recordset.map(row =>
            headers
              .map(header => {
                const value = row[header];
                if (value === null || value === undefined) return '';
                const stringValue = String(value);
                // Escape quotes and wrap in quotes if contains comma or quotes
                if (
                  stringValue.includes(',') ||
                  stringValue.includes('"') ||
                  stringValue.includes('\n')
                ) {
                  return `"${stringValue.replace(/"/g, '""')}"`;
                }
                return stringValue;
              })
              .join(',')
          );
    
          const csvContent = [csvHeaders, ...csvRows].join('\n');
    
          return [
            {
              type: 'text',
              text: csvContent
            }
          ];
        }
    
        return [
          {
            type: 'text',
            text: 'No data found in table'
          }
        ];
      } catch (error) {
        // Track failed query
        if (this.performanceMonitor) {
          this.performanceMonitor.recordQuery({
            tool: 'export_table_csv',
            query: `SELECT${limit ? ` TOP ${limit}` : ''} * FROM [${schema}].[${tableName}]`,
            executionTime: 0,
            success: false,
            error: error.message,
            database,
            timestamp: new Date()
          });
        }
    
        throw error;
      }
    }
  • Tool schema definition including input validation schema for parameters: table_name (required), database, schema, limit, where.
      name: 'export_table_csv',
      description: 'Export table data in CSV format',
      inputSchema: {
        type: 'object',
        properties: {
          table_name: { type: 'string', description: 'Name of the table to export' },
          database: { type: 'string', description: 'Database name (optional)' },
          schema: { type: 'string', description: 'Schema name (optional, defaults to dbo)' },
          limit: { type: 'number', description: 'Maximum number of rows to export (optional)' },
          where: { type: 'string', description: 'WHERE clause conditions (optional)' }
        },
        required: ['table_name']
      }
    }
  • index.js:298-306 (registration)
    MCP tool call handler registration in the main server switch statement, dispatching to DatabaseToolsHandler.exportTableCsv.
    case 'export_table_csv':
      return {
        content: await this.databaseTools.exportTableCsv(
          args.table_name,
          args.database,
          args.schema,
          args.limit
        )
      };
  • index.js:561-567 (registration)
    Proxy method in SqlServerMCP class that delegates to the DatabaseToolsHandler.exportTableCsv for backward compatibility or testing.
    async exportTableCsv(...args) {
      try {
        return { content: await this.databaseTools.exportTableCsv(...args) };
      } catch (error) {
        throw new McpError(ErrorCode.InternalError, error.message);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool exports data but doesn't mention whether this is a read-only operation, if it requires specific permissions, what happens with large datasets, or if there are rate limits. The description is too minimal to provide adequate behavioral context for a data export 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 extremely concise at just 5 words, with zero wasted language. It's front-loaded with the core purpose and uses efficient phrasing. Every word earns its place in communicating the essential function.

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?

For a data export tool with 5 parameters and no output schema, the description is insufficient. It doesn't explain what the CSV output looks like, whether headers are included, how null values are handled, or what happens when no data matches the criteria. With no annotations and no output schema, the description should provide more context about the tool's behavior and results.

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 already documents all 5 parameters thoroughly. The description adds no additional parameter information beyond what's in the schema, meeting the baseline expectation but not providing extra value. The description doesn't explain relationships between parameters or provide usage examples.

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 ('Export') and resource ('table data in CSV format'), making the tool's purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'get_table_data' which might also retrieve table data, leaving room for ambiguity about when to choose this specific export tool.

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 like 'get_table_data' or 'execute_query' for data retrieval. There's no mention of prerequisites, limitations, or specific scenarios where CSV export is preferred over other formats or methods.

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/egarcia74/warp-sql-server-mcp'

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