Skip to main content
Glama
xuejike

Database Query MCP Server

by xuejike

query_oracle

Read-only

Execute read-only Oracle database queries securely by providing connection details and SELECT statements to retrieve data without modification.

Instructions

执行Oracle数据库查询(只读模式)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYes数据库主机地址
portYes数据库端口
userYes数据库用户名
pwdYes数据库密码
dbYes数据库名称
querySqlYes要执行的SQL查询语句(仅支持SELECT等只读操作)

Implementation Reference

  • Main handler function for query_oracle tool: checks if SQL is read-only, connects to Oracle database, executes the query, handles errors, closes connection, returns structured result.
    async executeOracle(config) {
      const { querySql } = config;
      
      // 检查是否为只读查询
      if (!this.isReadOnlyQuery(querySql)) {
        return {
          success: false,
          error: "不允许执行非只读操作。仅支持SELECT、SHOW、DESCRIBE等查询语句。",
          code: "READONLY_VIOLATION"
        };
      }
      
      let connection;
      
      try {
        // 建立数据库连接
        connection = await this.getOracleConnection(config);
        
        // 执行查询
        const result = await this.executeOracleQuery(connection, querySql);
        
        // 返回结果
        return {
          success: true,
          data: result.data,
          columns: result.columns,
          rowCount: result.rowCount
        };
      } catch (error) {
        // 错误处理
        return {
          success: false,
          error: error.message,
          code: error.code || 'DATABASE_ERROR'
        };
      } finally {
        // 关闭数据库连接
        await this.closeOracleConnection(connection);
      }
    }
  • Schema definition for query_oracle tool including input parameters (host, port, user, pwd, db, querySql), description, and annotations.
    query_oracle: {
      name: "query_oracle",
      description: "执行Oracle数据库查询(只读模式)",
      inputSchema: {
        type: "object",
        properties: {
          host: { 
            type: "string", 
            description: "数据库主机地址" 
          },
          port: { 
            type: "integer", 
            description: "数据库端口" 
          },
          user: { 
            type: "string", 
            description: "数据库用户名" 
          },
          pwd: { 
            type: "string", 
            description: "数据库密码" 
          },
          db: { 
            type: "string", 
            description: "数据库名称" 
          },
          querySql: { 
            type: "string", 
            description: "要执行的SQL查询语句(仅支持SELECT等只读操作)" 
          }
        },
        required: ["host", "port", "user", "pwd", "db", "querySql"]
      },
      annotations: {
        title: "Oracle数据库查询工具(只读)",
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: false,
        openWorldHint: false
      }
    }
  • mcp-server.js:48-50 (registration)
    Registration and dispatch: switch case that calls executeOracle for query_oracle tool invocations.
    case config.tools.query_oracle.name:
      result = await dbTool.executeOracle(request.params.arguments);
      break;
  • mcp-server.js:77-86 (registration)
    Tool list handler that registers query_oracle in the available tools list.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          config.tools.query_mysql,
          config.tools.query_postgresql,
          config.tools.query_mssql,
          config.tools.query_oracle
        ]
      };
    });
  • Helper function to establish Oracle database connection using oracledb.
    async getOracleConnection(config) {
      const { host, port, user, pwd, db } = config;
      const oracledb = require('oracledb');
      return await oracledb.getConnection({
        host,
        port,
        user,
        password: pwd,
        database: db
      });
    }
Behavior4/5

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

Annotations already provide readOnlyHint=true, destructiveHint=false, openWorldHint=false, and idempotentHint=false. The description adds valuable context by specifying '只读模式' (read-only mode) and implying Oracle-specific behavior. While it doesn't detail rate limits, authentication needs beyond parameters, or result formats, it usefully reinforces the read-only constraint beyond what annotations alone convey.

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 a single, efficient sentence in Chinese: '执行Oracle数据库查询(只读模式)'. It's front-loaded with the core purpose and includes the critical 'read-only mode' qualification. There's zero wasted verbiage or redundant information.

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

Completeness4/5

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

For a database query tool with 6 parameters, 100% schema coverage, and annotations covering safety (readOnlyHint=true, destructiveHint=false), the description is reasonably complete. It specifies the database type (Oracle) and read-only mode. The main gap is lack of output schema, but the description doesn't need to explain return values. It could better differentiate from sibling tools but covers essential context.

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 all 6 parameters well-documented in the input schema (e.g., host, port, user, pwd, db, querySql). The description adds no additional parameter information beyond what's in the schema. With complete schema coverage, the baseline score of 3 is appropriate as the description doesn't need to compensate for gaps.

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

Purpose4/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 as '执行Oracle数据库查询(只读模式)' which translates to 'Execute Oracle database query (read-only mode)'. This specifies both the verb (execute query) and resource (Oracle database), and distinguishes it from non-database tools. However, it doesn't explicitly differentiate from sibling database query tools (query_mssql, query_mysql, query_postgresql) beyond specifying Oracle.

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

Usage Guidelines3/5

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

The description implies usage context through '只读模式' (read-only mode) and the input schema's querySql description specifies '仅支持SELECT等只读操作' (only supports SELECT and other read-only operations). However, there's no explicit guidance on when to use this tool versus the sibling database tools, nor any mention of prerequisites or alternative scenarios.

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/xuejike/coding-db-mcp'

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