Skip to main content
Glama
kevinbin

MCP MySQL Server

by kevinbin

execute

Run INSERT, UPDATE, or DELETE queries on MySQL databases via the MCP server, enabling direct database modifications with optional parameters for precise command execution.

Instructions

Execute an INSERT, UPDATE, or DELETE query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsNoQuery parameters (optional)
sqlYesSQL query (INSERT, UPDATE, DELETE)

Implementation Reference

  • The primary handler for the 'execute' tool. Validates SQL type, executes the query via executeQuery helper, and formats the result as JSON text content.
    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:396-415 (registration)
    Tool registration entry in the ListTools handler, specifying name, description, and input schema for the 'execute' tool.
    { name: 'execute', description: 'Execute an INSERT, UPDATE, or DELETE query', inputSchema: { type: 'object', properties: { sql: { type: 'string', description: 'SQL query (INSERT, UPDATE, DELETE)', }, params: { type: 'array', items: { type: ['string', 'number', 'boolean', 'null'], }, description: 'Query parameters (optional)', }, }, required: ['sql'], },
  • TypeScript interface defining the input arguments for the 'execute' tool (shared with 'query' tool).
    interface QueryArgs { sql: string; params?: Array<string | number | boolean | null>; }
  • Core helper function that executes SQL queries using the MySQL connection pool and handles database errors.
    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); }
  • src/index.ts:523-524 (registration)
    Dispatch case in the CallTool request handler that routes 'execute' tool calls to the handleExecute method.
    case 'execute': return await this.handleExecute(request.params.arguments as unknown as QueryArgs);

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

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