Skip to main content
Glama
enemyrr

MCP-MySQL Server

by enemyrr

execute

Run INSERT, UPDATE, or DELETE queries on MySQL databases. Provide SQL statements and optional parameters for precise database modifications using a secure connection.

Instructions

Execute an INSERT, UPDATE, or DELETE query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsNoAn optional array of parameters (as strings) to bind to the SQL query placeholders (e.g., ?).
sqlYesThe SQL query string (INSERT, UPDATE, DELETE) to execute.

Implementation Reference

  • Core handler function for the 'execute' tool. Validates that the SQL is an INSERT, UPDATE, or DELETE statement and executes it using the executeQuery helper, returning the result as formatted JSON.
    private async handleExecute(args: QueryArgs): Promise<QueryResult> { this.validateSqlInput(args.sql, ['INSERT', 'UPDATE', 'DELETE']); const result = await this.executeQuery(args.sql, args.params || []); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }
  • src/index.ts:444-466 (registration)
    Registers the 'execute' tool in the ListToolsRequestSchema handler, providing name, description, and input schema for tool discovery.
    { name: 'execute', description: 'Execute an INSERT, UPDATE, or DELETE query', inputSchema: { type: 'object', properties: { sql: { type: 'string', description: 'The SQL query string (INSERT, UPDATE, DELETE) to execute.', }, params: { type: 'array', items: { type: 'string', description: 'A parameter value (as string) to bind to the query.' }, description: 'An optional array of parameters (as strings) to bind to the SQL query placeholders (e.g., ?).', optional: true, }, }, required: ['sql'], }, },
  • src/index.ts:575-576 (registration)
    Dispatches incoming CallTool requests for 'execute' to the handleExecute method.
    case 'execute': return await this.handleExecute(request.params.arguments as unknown as QueryArgs);
  • Helper method that performs the actual database query execution using the MySQL pool, with error handling.
    private async executeQuery<T>(sql: string, params: any[] = []): Promise<T> { const pool = await this.ensureConnection(); try { const [result] = await pool.query(sql, params); return result as T; } catch (error) { this.handleDatabaseError(error); } }
  • TypeScript interface defining the input arguments for the 'execute' tool (and 'query' tool).
    interface QueryArgs { sql: string; params?: Array<string | number | boolean | null>; }

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

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