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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. 'Execute a SELECT query' implies a read-only operation, but it doesn't specify permissions needed, potential side effects (e.g., read locks), error handling, or return format. For a database query tool with zero annotation coverage, this is insufficient to inform safe and effective use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at three words, with zero wasted language. It's front-loaded with the core action and resource, making it easy to parse quickly. This efficiency is appropriate for a simple tool, though it may sacrifice completeness for brevity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of database queries, lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like safety, performance implications, or result formatting. While the schema handles parameters well, the overall context for reliable tool invocation is inadequate, especially compared to siblings that might overlap in functionality.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear documentation for 'sql' (SQL SELECT query) and 'params' (query parameters). The description adds no additional parameter semantics beyond what the schema provides, such as SQL dialect constraints or parameter binding details. Given high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but doesn't detract either.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Execute a SELECT query' clearly states the action (execute) and resource (SELECT query), making the purpose understandable. However, it doesn't distinguish this tool from sibling tools like 'execute' or 'mongodb_find' that might also perform query operations, leaving ambiguity about when to use this specific SQL query tool versus alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'execute' (which might handle broader SQL operations) and 'mongodb_find' (for NoSQL queries), there's no indication of context, prerequisites, or exclusions. This lack of differentiation could lead to incorrect tool selection by an AI agent.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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