Skip to main content
Glama
wirdes

db-mcp-tool

!export-db

Export data from a specified database table in PostgreSQL, MySQL, or Firestore using the db-mcp-tool, ensuring structured and precise extraction for further use.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYes

Implementation Reference

  • The main handler function for the '!export-db' tool. It checks if a database connection exists via dbService, then calls exportTableSchema on the table provided in args, returning the generated schema SQL or an error.
    async (args: { table: string }) => {
      if (!dbService) {
        return {
          content: [{ type: "text", text: "You must connect to a database first!" }],
          isError: true,
        };
      }
    
      try {
        const schema = await dbService.exportTableSchema(args.table);
        return {
          content: [
            {
              type: "text",
              text: schema,
            },
          ],
        };
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : 'Unknown error';
        return {
          content: [{ type: "text", text: `Failed to export table schema: ${errorMessage}` }],
          isError: true,
        };
      }
    }
  • Input schema for '!export-db' tool: requires a 'table' string parameter for specifying which table's schema to export.
    {
      table: z.string(),
    },
  • src/index.ts:255-286 (registration)
    Registration of the '!export-db' tool on the MCP server using server.tool(), including name, schema, and handler function.
    server.tool(
      "!export-db",
      {
        table: z.string(),
      },
      async (args: { table: string }) => {
        if (!dbService) {
          return {
            content: [{ type: "text", text: "You must connect to a database first!" }],
            isError: true,
          };
        }
    
        try {
          const schema = await dbService.exportTableSchema(args.table);
          return {
            content: [
              {
                type: "text",
                text: schema,
              },
            ],
          };
        } catch (error: unknown) {
          const errorMessage = error instanceof Error ? error.message : 'Unknown error';
          return {
            content: [{ type: "text", text: `Failed to export table schema: ${errorMessage}` }],
            isError: true,
          };
        }
      }
    );
  • Core helper method 'exportTableSchema' in DatabaseService that implements the logic to generate CREATE TABLE SQL schema for a given table in PostgreSQL (via dynamic query on information_schema) or MySQL (via SHOW CREATE TABLE), throwing errors for unsupported cases like Firestore.
    async exportTableSchema(tableName: string): Promise<string> {
        switch (this.config.type) {
            case 'postgres': {
                if (!this.postgresClient) {
                    throw new Error('PostgreSQL connection not found');
                }
                const query = `
                    SELECT 
                        'CREATE TABLE ' || quote_ident($1) || ' (' ||
                        string_agg(
                            quote_ident(column_name) || ' ' ||
                            data_type ||
                            CASE 
                                WHEN character_maximum_length IS NOT NULL 
                                THEN '(' || character_maximum_length || ')'
                                ELSE ''
                            END ||
                            CASE 
                                WHEN is_nullable = 'NO' 
                                THEN ' NOT NULL'
                                ELSE ''
                            END,
                            ', '
                        ) || ');' as create_table_sql
                    FROM information_schema.columns
                    WHERE table_name = $1 AND table_schema = 'public'
                    GROUP BY table_name;
                `;
                const result = await this.postgresClient.query(query, [tableName]);
                return result.rows[0]?.create_table_sql || '';
            }
            case 'mysql': {
                if (!this.mysqlConnection) {
                    throw new Error('MySQL connection not found');
                }
                const [result] = await this.mysqlConnection.query(
                    'SHOW CREATE TABLE ??',
                    [tableName]
                );
                return result[0]?.['Create Table'] || '';
            }
            case 'firestore': {
                throw new Error('SQL schema export is not supported for Firestore');
            }
            default:
                throw new Error('Unsupported database type');
        }
    }
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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

Related 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/wirdes/db-mcp-tool'

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