Skip to main content
Glama

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

NameRequiredDescriptionDefault
tableYesTable name

Input Schema (JSON Schema)

{ "properties": { "table": { "description": "Table name", "type": "string" } }, "required": [ "table" ], "type": "object" }

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'], }, }, ], }));

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