Skip to main content
Glama

MCP-MongoDB-MySQL-Server

query

Run SQL SELECT queries on MySQL or MongoDB databases via a standardized MCP server interface, enabling data retrieval and analysis for integrated database operations.

Instructions

Execute a SELECT query

Input Schema

NameRequiredDescriptionDefault
paramsNoQuery parameters (optional)
sqlYesSQL SELECT query

Input Schema (JSON Schema)

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

Implementation Reference

  • The handler function that validates the SQL query is a SELECT statement, executes it on the MySQL connection with optional parameters, and returns the results as JSON.
    private async handleQuery(args: any) { await this.ensureConnection(); if (!args.sql) { throw new McpError(ErrorCode.InvalidParams, 'SQL query is required'); } if (!args.sql.trim().toUpperCase().startsWith('SELECT')) { throw new McpError( ErrorCode.InvalidParams, 'Only SELECT queries are allowed with query tool' ); } try { const [rows] = await this.connection!.query(args.sql, args.params || []); return { content: [ { type: 'text', text: JSON.stringify(rows, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Query execution failed: ${getErrorMessage(error)}` ); } }
  • Input schema defining the parameters for the query tool: required 'sql' string and optional 'params' array.
    inputSchema: { type: 'object', properties: { sql: { type: 'string', description: 'SQL SELECT query', }, params: { type: 'array', items: { type: ['string', 'number', 'boolean', 'null'], }, description: 'Query parameters (optional)', }, }, required: ['sql'], },
  • src/index.ts:259-279 (registration)
    Registration of the 'query' tool in the tools list returned by listToolsRequest, including name, description, and schema.
    { name: 'query', description: 'Execute a SELECT query', inputSchema: { type: 'object', properties: { sql: { type: 'string', description: 'SQL SELECT query', }, params: { type: 'array', items: { type: ['string', 'number', 'boolean', 'null'], }, description: 'Query parameters (optional)', }, }, required: ['sql'], }, },
  • src/index.ts:539-540 (registration)
    Switch case in CallToolRequest handler that dispatches 'query' tool calls to the handleQuery method.
    case 'query': return await this.handleQuery(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