Skip to main content
Glama

MCP-MongoDB-MySQL-Server

execute

Perform INSERT, UPDATE, or DELETE operations on MySQL or MongoDB databases using SQL queries with optional parameters, enabling direct data manipulation through the MCP server.

Instructions

Execute an INSERT, UPDATE, or DELETE query

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "params": { "description": "Query parameters (optional)", "items": { "type": [ "string", "number", "boolean", "null" ] }, "type": "array" }, "sql": { "description": "SQL query (INSERT, UPDATE, DELETE)", "type": "string" } }, "required": [ "sql" ], "type": "object" }

Implementation Reference

  • The core handler function that validates the input, ensures database connection, executes non-SELECT SQL queries (INSERT, UPDATE, DELETE), and returns the 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)}` ); } }
  • Input schema defining the parameters for the 'execute' tool: required 'sql' string and optional 'params' array.
    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:280-300 (registration)
    Registration of the 'execute' tool in the ListTools response, including name, description, and input schema.
    { 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)
    Dispatch registration in the CallTool request handler that routes 'execute' calls to the handleExecute method.
    case 'execute': return await this.handleExecute(request.params.arguments);

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

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