Skip to main content
Glama
bvisible

MCP SSH Manager

ssh_db_query

Execute SELECT queries on MySQL, PostgreSQL, or MongoDB databases through SSH connections to retrieve data from remote servers.

Instructions

Execute SELECT query on database (read-only, SELECT queries only)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serverYesServer name
typeYesDatabase type
databaseYesDatabase name
queryYesSQL query (SELECT only) or MongoDB find query
collectionNoCollection name (MongoDB only)
dbUserNoDatabase user
dbPasswordNoDatabase password
dbHostNoDatabase host (default: localhost)
dbPortNoDatabase port

Implementation Reference

  • Registration of 'ssh_db_query' tool in the TOOL_GROUPS.database array. This central registry controls which tools are conditionally registered based on user configuration.
    database: [
      'ssh_db_dump',
      'ssh_db_import',
      'ssh_db_list',
      'ssh_db_query'
    ],
  • Helper function buildMySQLQueryCommand constructs the MySQL SELECT query command executed over SSH for the ssh_db_query tool.
    export function buildMySQLQueryCommand(options) {
      const { database, query, user, password, host = 'localhost', port = 3306, format = 'json' } = options;
    
      // Validate query is SELECT only
      if (!isSafeQuery(query)) {
        throw new Error('Only SELECT queries are allowed');
      }
    
      let command = 'mysql';
      if (user) command += ` -u${user}`;
      if (password) command += ` -p'${password}'`;
      if (host) command += ` -h ${host}`;
      if (port) command += ` -P ${port}`;
      command += ` ${database}`;
    
      if (format === 'json') {
        // Use JSON output if MySQL 5.7.8+
        command += ` -e "${query}" --batch --skip-column-names | awk 'BEGIN{print "["} {if(NR>1)print ","; printf "{\\"row\\":%d,\\"data\\":\\"%s\\"}", NR, $0} END{print "]"}'`;
      } else {
        command += ` -e "${query}"`;
      }
    
      return command;
    }
  • Helper function buildPostgreSQLQueryCommand constructs the PostgreSQL SELECT query command for ssh_db_query tool.
    export function buildPostgreSQLQueryCommand(options) {
      const { database, query, user, password, host = 'localhost', port = 5432 } = options;
    
      if (!isSafeQuery(query)) {
        throw new Error('Only SELECT queries are allowed');
      }
    
      let command = '';
      if (password) {
        command = `PGPASSWORD='${password}' `;
      }
    
      command += 'psql';
      if (user) command += ` -U ${user}`;
      if (host) command += ` -h ${host}`;
      if (port) command += ` -p ${port}`;
      command += ` -d ${database}`;
      command += ` -c "${query}"`;
    
      return command;
    }
  • Helper function buildMongoDBQueryCommand constructs the MongoDB query command for ssh_db_query tool.
    export function buildMongoDBQueryCommand(options) {
      const { database, collection, query, user, password, host = 'localhost', port = 27017 } = options;
    
      let command = 'mongo';
      if (host) command += ` --host ${host}`;
      if (port) command += ` --port ${port}`;
      if (user) command += ` --username ${user}`;
      if (password) command += ` --password '${password}'`;
      command += ` ${database}`;
      command += ` --quiet --eval "db.${collection}.find(${query || '{}'}).forEach(printjson)"`;
    
      return command;
    }
  • Safety validation helper isSafeQuery ensures only safe SELECT queries are executed by ssh_db_query tool.
    export function isSafeQuery(query) {
      const trimmedQuery = query.trim().toLowerCase();
    
      // Must start with SELECT
      if (!trimmedQuery.startsWith('select')) {
        return false;
      }
    
      // Block dangerous keywords
      const dangerousKeywords = [
        'insert', 'update', 'delete', 'drop', 'create', 'alter',
        'truncate', 'grant', 'revoke', 'exec', 'execute'
      ];
    
      for (const keyword of dangerousKeywords) {
        if (trimmedQuery.includes(keyword)) {
          return false;
        }
      }
    
      return true;
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It does disclose the read-only nature and query type restriction, which are crucial behavioral traits. However, it doesn't mention authentication requirements (though parameters suggest them), potential rate limits, error handling, or what the return format looks like, leaving gaps in behavioral understanding.

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 perfectly concise with a single sentence that front-loads the core purpose ('Execute SELECT query on database') followed by important restrictions ('read-only, SELECT queries only'). Every word earns its place with zero waste or redundancy.

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

Completeness3/5

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

For a tool with 9 parameters, no annotations, and no output schema, the description is somewhat incomplete. While it clearly states the purpose and restrictions, it doesn't address authentication requirements (implied by parameters), expected return format, error conditions, or performance considerations that would help an agent use it correctly in complex scenarios.

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%, so the schema already documents all 9 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema descriptions. It only reinforces the query parameter restriction ('SELECT only'), which is already implied by the tool's purpose statement.

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

Purpose5/5

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

The description clearly states the tool's purpose with a specific verb ('Execute SELECT query') and resource ('on database'), and distinguishes it from siblings by specifying 'read-only, SELECT queries only'. This differentiates it from other database tools like ssh_db_dump or ssh_db_import that perform different operations.

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

Usage Guidelines4/5

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

The description provides clear context about when to use this tool by specifying 'read-only, SELECT queries only', which implicitly guides usage toward data retrieval rather than modification. However, it doesn't explicitly mention when NOT to use it or name specific alternatives among the sibling tools for different database operations.

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/bvisible/mcp-ssh-manager'

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