Skip to main content
Glama
adetxt

SQL MCP Server

by adetxt

Execute Query

execute_query

Run SQL queries on PostgreSQL, MySQL, or SQLite databases using connection strings to retrieve or modify data.

Instructions

Run a query to database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
db_typeYes
connection_stringYes
queryYes

Implementation Reference

  • The handler function that creates a Sequelize connection based on db_type and connection_string, optionally blocks write operations, executes the provided SQL query, and returns the results as JSON text.
    async ({db_type, connection_string, query}) => {
      const sequelize = new Sequelize(connection_string, {
        dialect: db_type,
      })
    
      if (!enableWriteOperations) {
        const writeOperations = ['INSERT', 'UPDATE', 'DELETE', 'CREATE', 'ALTER', 'DROP']
        if (writeOperations.some((operation) => query.toUpperCase().includes(operation))) {
          throw new Error('Write operations are not enabled')
        }
      }
    
      const [results] = await sequelize.query(query)
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(results),
          }
        ],
      }
    },
  • Zod input schema defining parameters: db_type (postgres/mysql/sqlite), connection_string, and query.
    inputSchema: {
      db_type: z.enum(['postgres', 'mysql', 'sqlite']), 
      connection_string: z.string(),
      query: z.string(),
    },
  • src/tools.ts:123-157 (registration)
    Registration of the 'execute_query' tool using McpServer.registerTool, including title, description, input schema, and handler function.
    server.registerTool(
      'execute_query',
      {
        title: 'Execute Query',
        description: 'Run a query to database',
        inputSchema: {
          db_type: z.enum(['postgres', 'mysql', 'sqlite']), 
          connection_string: z.string(),
          query: z.string(),
        },
      },
      async ({db_type, connection_string, query}) => {
        const sequelize = new Sequelize(connection_string, {
          dialect: db_type,
        })
    
        if (!enableWriteOperations) {
          const writeOperations = ['INSERT', 'UPDATE', 'DELETE', 'CREATE', 'ALTER', 'DROP']
          if (writeOperations.some((operation) => query.toUpperCase().includes(operation))) {
            throw new Error('Write operations are not enabled')
          }
        }
    
        const [results] = await sequelize.query(query)
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(results),
            }
          ],
        }
      },
    )
Behavior1/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 of behavioral disclosure. 'Run a query to database' implies a potentially mutating operation (e.g., INSERT, UPDATE, DELETE) but doesn't specify if it's read-only, destructive, requires authentication, has rate limits, or what the output format is. This is a significant gap for a tool with no 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 extremely concise with a single sentence 'Run a query to database', which is front-loaded and wastes no words. It efficiently conveys the core action, though this brevity contributes to gaps in other dimensions.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (a database query tool with potential mutations), no annotations, no output schema, and 0% schema coverage, the description is incomplete. It doesn't address key aspects like safety, return values, or parameter details, making it insufficient for effective tool use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning parameters (db_type, connection_string, query) are undocumented in the schema. The description adds no meaning beyond the schema, failing to explain what these parameters do, their formats, or examples. For a tool with 3 parameters and low coverage, this is inadequate.

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

Purpose3/5

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

The description 'Run a query to database' states the action (run/execute) and resource (database query), which clarifies the basic purpose. However, it's vague about what type of query (e.g., SELECT, INSERT, UPDATE) and lacks distinction from sibling tools like get_columns or get_tables, which might also involve database queries but for specific purposes.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools (get_columns, get_tables) or specify contexts like executing arbitrary SQL versus retrieving metadata, leaving the agent with no usage instructions beyond the basic action.

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/adetxt/sql-mcp'

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