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'],
          },
        },
      ],
    }));
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 of behavioral disclosure. 'Get table structure' implies a read-only operation, but it doesn't specify if this requires authentication, has rate limits, returns detailed metadata (e.g., column types, indexes), or handles errors (e.g., for non-existent tables). For a tool with zero annotation coverage, this is a significant gap in describing behavior beyond basic purpose.

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 'Get table structure' is extremely concise and front-loaded, consisting of just three words that directly convey the tool's purpose. There is no wasted language or unnecessary elaboration, making it efficient and easy to parse for an AI agent.

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 (a read operation with one parameter) and the lack of annotations and output schema, the description is incomplete. It doesn't explain what 'structure' includes (e.g., schema details), potential outputs, or behavioral aspects like error handling. For a tool that likely returns metadata, more context is needed to guide the agent effectively.

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?

The input schema has 100% description coverage, with the 'table' parameter clearly documented as 'Table name'. The description adds no additional meaning beyond this, such as format examples (e.g., case sensitivity) or constraints. With high schema coverage, the baseline score of 3 is appropriate, as the schema does the heavy lifting for parameter documentation.

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

Purpose3/5

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

The description 'Get table structure' states a clear verb ('Get') and resource ('table structure'), but it's vague about what 'structure' entails (e.g., columns, types, constraints). It doesn't differentiate from sibling tools like 'list_tables' or 'query', which might also provide structural information. This is adequate but lacks specificity and 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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., after connecting to the database with 'connect_db'), differentiate from 'list_tables' (which might list names only) or 'query' (which might retrieve data), or specify use cases like schema inspection. This leaves the agent without contextual usage cues.

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/Malove86/mcp-mysql-server'

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