Skip to main content
Glama

execute_sql

Execute SQL statements to modify MySQL database structure and data, including ALTER TABLE, DROP, INSERT, UPDATE, and DELETE operations.

Instructions

Executes any non-SELECT SQL statement (e.g., ALTER TABLE, DROP, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL statement to execute.

Implementation Reference

  • The primary handler function for the 'execute_sql' tool. It validates the input arguments, ensures the query is not a SELECT statement, executes the SQL query using the MySQL connection pool, logs the activity, and returns a structured response with the result or an error message.
    private async handleExecuteSql(request: any, transactionId: string) {
      if (!isValidSqlQueryArgs(request.params.arguments)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid SQL query arguments.'
        );
      }
    
      const query = request.params.arguments.query;
    
      if (isReadOnlyQuery(query)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'SELECT queries are not allowed with execute_sql tool.'
        );
      }
    
      console.error(`[${transactionId}] Executing general SQL: ${query}`);
    
      try {
        const [result] = await this.pool.query(query);
        console.error(`[${transactionId}] SQL executed successfully`);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: true,
                message: 'SQL executed successfully',
                result
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error(`[${transactionId}] SQL error:`, error);
        if (error instanceof Error) {
          return {
            content: [
              {
                type: 'text',
                text: `MySQL error: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    }
  • src/index.ts:164-177 (registration)
    Registers the 'execute_sql' tool with the MCP server via setTools, defining its name, description, and input schema.
    {
      name: 'execute_sql',
      description: 'Executes any non-SELECT SQL statement (e.g., ALTER TABLE, DROP, etc.)',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'The SQL statement to execute.',
          },
        },
        required: ['query'],
      },
    },
  • Defines the input schema for the 'execute_sql' tool, specifying an object with a required 'query' string property.
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: 'The SQL statement to execute.',
        },
      },
      required: ['query'],
    },
  • src/index.ts:197-198 (registration)
    In the request handler switch statement, routes calls to the 'execute_sql' tool to its handler method.
    case 'execute_sql':
      return this.handleExecuteSql(request, transactionId);
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. It states the tool executes SQL statements but doesn't disclose behavioral traits like whether it requires specific permissions, if changes are reversible, potential side effects (e.g., data loss from DROP), or error handling. This is a significant gap for a mutation tool with zero annotation coverage.

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 is a single, efficient sentence with zero waste. It's front-loaded with the core purpose and includes helpful examples (e.g., ALTER TABLE, DROP). Every word earns its place.

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 complexity (executes non-SELECT SQL, which can be destructive), lack of annotations, and no output schema, the description is incomplete. It should address behavioral aspects like safety, permissions, or return values to compensate for the missing structured data.

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 'query' parameter documented as 'The SQL statement to execute.' The description adds no additional meaning beyond this, as it doesn't specify syntax, format, or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb ('executes') and resource ('non-SELECT SQL statement') with specific examples (ALTER TABLE, DROP). However, it doesn't explicitly differentiate from siblings like 'run_sql_query' (which likely handles SELECT) or 'create_table'/'delete_data' (which are specific operations).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by specifying 'non-SELECT SQL statement', which suggests when to use this tool (for non-SELECT operations) versus alternatives like 'run_sql_query' (for SELECT). However, it doesn't explicitly name alternatives or provide exclusions (e.g., when to use 'create_table' instead).

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

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

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