Skip to main content
Glama
Malove86

MCP MySQL Server

by Malove86

describe_table

Retrieve the structure of a specified table from a MySQL database using the MCP MySQL Server. Input the table name to analyze its schema and fields.

Instructions

Get table structure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name

Implementation Reference

  • The handler function for 'describe_table' tool. Ensures database connection, validates table name, executes 'DESCRIBE ??' query using prepared statement, and returns the table structure as JSON.
    private async handleDescribeTable(requestId: string, args: any) {
      await this.ensureConnection();
    
      if (!args.table) {
        throw new McpError(ErrorCode.InvalidParams, 'Table name is required');
      }
    
      try {
        console.error(`[${requestId}] Executing DESCRIBE ${args.table}`);
        const [rows] = await this.pool!.query('DESCRIBE ??', [args.table]);
        console.error(`[${requestId}] DESCRIBE completed, found ${Array.isArray(rows) ? rows.length : 0} columns`);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(rows, null, 2),
            },
          ],
        };
      } catch (error) {
        const errorMsg = getErrorMessage(error);
        console.error(`[${requestId}] Failed to describe table: ${errorMsg}`);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to describe table: ${errorMsg}`
        );
      }
    }
  • Input schema for the 'describe_table' tool, defining a required 'table' string parameter.
    {
      name: 'describe_table',
      description: 'Get table structure',
      inputSchema: {
        type: 'object',
        properties: {
          table: {
            type: 'string',
            description: 'Table name',
          },
        },
        required: ['table'],
      },
    },
  • src/index.ts:299-301 (registration)
    Registration in the CallToolRequestHandler switch statement, routing 'describe_table' calls to the handleDescribeTable method.
    case 'describe_table':
      result = await this.handleDescribeTable(requestId, request.params.arguments);
      break;
  • src/index.ts:183-265 (registration)
    Tool list registration in ListToolsRequestHandler, including 'describe_table' with its schema for tool discovery.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: 'connect_db',
          description: 'Connect to MySQL database (optional if environment variables are set)',
          inputSchema: {
            type: 'object',
            properties: {
              host: {
                type: 'string',
                description: 'Database host',
              },
              user: {
                type: 'string',
                description: 'Database user',
              },
              password: {
                type: 'string',
                description: 'Database password',
              },
              database: {
                type: 'string',
                description: 'Database name',
              },
              port: {
                type: 'number',
                description: 'Database port (optional)',
              },
            },
            required: ['host', 'user', 'password', 'database'],
          },
        },
        {
          name: 'query',
          description: 'Execute a SELECT query',
          inputSchema: {
            type: 'object',
            properties: {
              sql: {
                type: 'string',
                description: 'SQL SELECT query',
              },
              params: {
                type: 'array',
                items: {
                  type: ['string', 'number', 'boolean', 'null'],
                },
                description: 'Query parameters (optional)',
              },
            },
            required: ['sql'],
          },
        },
        {
          name: 'list_tables',
          description: 'List all tables in the database',
          inputSchema: {
            type: 'object',
            properties: {
              random_string: {
                type: 'string',
                description: 'Dummy parameter for no-parameter tools',
              }
            },
            required: [], // 修改为可选参数
          },
        },
        {
          name: 'describe_table',
          description: 'Get table structure',
          inputSchema: {
            type: 'object',
            properties: {
              table: {
                type: 'string',
                description: 'Table name',
              },
            },
            required: ['table'],
          },
        },
      ],
    }));

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

B3.2/5.0
Behavior2/5

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

No annotations are provided, and the description fails to disclose behavioral traits like read-only nature, side effects, or required permissions. It simply states the function without additional context.

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

Conciseness4/5

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

The description is extremely concise (two words), front-loaded, and gets straight to the point. However, it could benefit from a bit more detail without sacrificing brevity.

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

Completeness3/5

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

Given the tool is simple with one parameter and no output schema, the description is minimal but adequate for a basic understanding. However, it doesn't specify what 'structure' includes (e.g., columns, types), leaving some ambiguity.

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 coverage is 100% with the only parameter 'table' described as 'Table name'. The description adds no new meaning beyond the schema, so baseline 3 is appropriate.

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

Purpose5/5

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

The description 'Get table structure' clearly states the verb (Get) and resource (table structure), and distinguishes the tool from siblings like execute, list_tables, and query, which have different purposes.

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 vs alternatives, such as list_tables or query. It lacks context on when not to use it or any prerequisites.

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

Deploy Server

Other Tools

Related Tools