Skip to main content
Glama
yaoxiaolinglong

MCP-MongoDB-MySQL-Server

query

Execute SQL SELECT queries to retrieve data from MySQL and MongoDB databases through a standardized interface, supporting query parameters for dynamic operations.

Instructions

Execute a SELECT query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesSQL SELECT query
paramsNoQuery parameters (optional)

Implementation Reference

  • The handler function that executes SELECT SQL queries on the MySQL database using the provided SQL and optional parameters. Ensures connection, validates SELECT only, executes query, and returns JSON results.
    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 definition for the 'query' tool, specifying 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)
    Tool registration in the listTools response, including name, description, and inputSchema for the 'query' tool.
    { 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)
    Dispatch case in CallToolRequestSchema handler that routes 'query' tool calls to the handleQuery method.
    case 'query': return await this.handleQuery(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