Skip to main content
Glama
yaoxiaolinglong

MCP-MongoDB-MySQL-Server

execute

Execute INSERT, UPDATE, or DELETE queries to modify data in MySQL or MongoDB databases through a standardized interface.

Instructions

Execute an INSERT, UPDATE, or DELETE query

Input Schema

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

Implementation Reference

  • The handler function that executes INSERT, UPDATE, or DELETE SQL queries on a MySQL database connection. Ensures connection, validates non-SELECT query, executes with optional parameters, and returns JSON result.
    private async handleExecute(args: any) {
      await this.ensureConnection();
    
      if (!args.sql) {
        throw new McpError(ErrorCode.InvalidParams, 'SQL query is required');
      }
    
      const sql = args.sql.trim().toUpperCase();
      if (sql.startsWith('SELECT')) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Use query tool for SELECT statements'
        );
      }
    
      try {
        const [result] = await this.connection!.query(args.sql, args.params || []);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Query execution failed: ${getErrorMessage(error)}`
        );
      }
    }
  • The input schema for the 'execute' tool, defining required 'sql' string for non-SELECT queries and optional 'params' array.
    {
      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'],
      },
    },
  • src/index.ts:541-542 (registration)
    Registration in the CallToolRequestHandler switch statement that routes 'execute' tool calls to the handleExecute method.
    case 'execute':
      return await this.handleExecute(request.params.arguments);

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

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