Skip to main content
Glama
adetxt

SQL MCP Server

by adetxt

execute_query

Run SQL queries on PostgreSQL, MySQL, or SQLite databases using a connection string. Enables direct database interactions via the SQL MCP Server's standardized protocol.

Instructions

Run a query to database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connection_stringYes
db_typeYes
queryYes

Implementation Reference

  • The core handler function for the 'execute_query' tool. It creates a Sequelize instance based on db_type and connection_string, optionally blocks write operations, executes the provided 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 for the execute_query tool: 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 on the McpServer instance within the registerTools 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), } ], } }, )

Other Tools

Related 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