Skip to main content
Glama
Atomzzm
by Atomzzm

query

Execute SELECT queries on MySQL databases to retrieve data using SQL statements with optional parameters for dynamic filtering.

Instructions

Execute a SELECT query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesSQL SELECT query
paramsNoQuery parameters (optional)

Implementation Reference

  • The main handler function for the 'query' tool, which executes SELECT queries on the MySQL database after validation.
    private async handleQuery(args: any) {
      await this.ensureConnection();
    
      if (!args.sql) {
        throw new McpError(ErrorCode.InvalidParams, 'SQL query is required');
      }
    
      if (!args.sql.trim().toUpperCase().startsWith('SELECT')) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Only SELECT queries are allowed with query tool'
        );
      }
    
      try {
        const [rows] = await this.connection!.query(args.sql, args.params || []);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(rows, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Query execution failed: ${getErrorMessage(error)}`
        );
      }
    }
  • The tool definition including name, description, and input schema for the 'query' tool in the listTools response.
    {
      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'],
      },
    },
  • src/index.ts:197-198 (registration)
    The switch case that routes the 'query' tool call to the handleQuery function.
    case 'query':
      return await this.handleQuery(request.params.arguments);

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

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