Skip to main content
Glama
xiangma9712

MySQL MCP Server

query

Execute read-only SQL queries to retrieve data from a MySQL database, enabling database interaction through JSON commands.

Instructions

Executes a read-only SQL query.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYes

Implementation Reference

  • The handler for the 'query' tool executes a read-only SQL query on the MySQL database and returns the result rows as a formatted JSON string.
    case "query": {
      const sql = request.params.arguments?.sql as string;
      await connection.query('START TRANSACTION READ ONLY');
      const [rows] = await connection.query(sql);
      return {
        content: [{ type: "text", text: JSON.stringify(rows, null, 2) }],
        isError: false,
      };
    }
  • Input schema definition for the 'query' tool, specifying an object with a required 'sql' string property.
    inputSchema: {
      type: "object",
      properties: {
        sql: { type: "string" },
      },
      required: ["sql"],
    },
  • src/index.ts:39-49 (registration)
    Registration of the 'query' tool in the tools list returned by the ListToolsRequestHandler.
    {
      name: "query",
      description: "Executes a read-only SQL query.",
      inputSchema: {
        type: "object",
        properties: {
          sql: { type: "string" },
        },
        required: ["sql"],
      },
    },
Install Server

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

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