Skip to main content
Glama

get-schema

Retrieve table structure details from MySQL databases to understand data organization and relationships for query optimization and analysis.

Instructions

Get the schema of a table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNameYesThe name of the schema

Implementation Reference

  • Handler function for the 'get-schema' tool that extracts the schemaName from args, calls the getSchema helper, and returns the result formatted as text content.
    async (args) => { const schemaName = args.schemaName; const result = await getSchema(schemaName); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), } ] }; }
  • Input schema definition using Zod for the 'schemaName' parameter of the 'get-schema' tool.
    schemaName: z.string().describe("The name of the schema"),
  • src/index.ts:82-101 (registration)
    Registration of the 'get-schema' tool using server.tool, specifying name, description, input schema, options, and handler function.
    server.tool("get-schema", "Get the schema of a table", { schemaName: z.string().describe("The name of the schema"), }, { title: "Get Schema", readOnlyHint: true, destructiveHint: false, }, async (args) => { const schemaName = args.schemaName; const result = await getSchema(schemaName); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), } ] }; } );
  • Helper function that connects to the MySQL database, executes DESCRIBE query on the given schemaName (table), and returns the results or error.
    async function getSchema(schemaName: string) { // Create the connection to database using config (environment variables or command-line arguments) const connection = await mysql.createConnection({ host: config.host, port: config.port, user: config.user, password: config.password, database: config.database, }); try { const [results] = await connection.query( `DESCRIBE ${mysql.escapeId(schemaName)}` ); return results; } catch (err) { console.log(err); return err; } finally { connection.end(); } }

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

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