Skip to main content
Glama
6June6
by 6June6

query

Query data from UniCloud database collections using JQL conditions, with options to filter fields, sort results, and limit returns.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYes集合名称
whereYes查询条件 (JQL格式)
fieldNo返回字段 (可选)
orderByNo排序条件 (可选)
limitNo限制返回数量 (可选)
skipNo跳过记录数 (可选)

Implementation Reference

  • Handler function for the 'query' tool. Destructures input params, prepares query options, executes queryDatabase helper, and returns MCP-formatted content or error response.
    async function handleQueryTool(params, dbUrl) {
      const { collection, where, field, orderBy, limit, skip } = params;
    
      try {
        const options = {
          field: field || undefined,
          orderBy: orderBy || undefined,
          limit: limit || undefined,
          skip: skip || undefined,
        };
    
        const data = await queryDatabase(collection, where, options, dbUrl);
        return {
          content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
        };
      } catch (error) {
        return {
          content: [{ type: 'text', text: error.message }],
          isError: true,
        };
      }
    }
  • Input schema for the 'query' tool defined using Zod, validating parameters: collection (string), where (record), field (optional record), orderBy (optional object), limit/skip (optional numbers).
      collection: z.string().describe('集合名称'),
      where: z.record(z.any()).describe('查询条件 (JQL格式)'),
      field: z.record(z.any()).optional().describe('返回字段 (可选)'),
      orderBy: z
        .object({
          field: z.string(),
          order: z.enum(['asc', 'desc']),
        })
        .optional()
        .describe('排序条件 (可选)'),
      limit: z.number().optional().describe('限制返回数量 (可选)'),
      skip: z.number().optional().describe('跳过记录数 (可选)'),
    },
    handler: (params) => handleQueryTool(params, dbServiceUrl),
  • index.js:38-42 (registration)
    Registration of the 'query' tool on the MCP server instance via server.tool(name, paramsSchema, handler).
    server.tool(
      tools.queryTool.name,
      tools.queryTool.params,
      tools.queryTool.handler
    );
  • Helper function that sends HTTP POST request to the database service endpoint with 'query' action and parameters, handling timeout and response parsing.
    async function queryDatabase(
      collection,
      where,
      options = {},
      dbUrl = DEFAULT_DB_URL
    ) {
      try {
        // 创建请求控制器,用于超时处理
        const controller = new AbortController();
        const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT);
    
        // 使用传入的dbUrl或默认URL
        const targetUrl = dbUrl || DEFAULT_DB_URL;
        // console.log('查询操作使用URL:', targetUrl);
    
        // 发送请求
        const response = await fetch(targetUrl, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({
            operation: {
              collection,
              action: 'query',
              where,
              field: options.field,
              orderBy: options.orderBy,
              limit: options.limit,
              skip: options.skip,
            },
          }),
          signal: controller.signal,
        });
    
        clearTimeout(timeoutId);
        const result = await response.json();
    
        // 处理响应结果
        if (result.code !== 0) {
          throw new Error(result.msg || '查询失败');
        }
    
        return result.data;
      } catch (error) {
        // 超时错误特殊处理
        if (error.name === 'AbortError') {
          throw new Error(`查询超时: 请求超过${REQUEST_TIMEOUT}毫秒`);
        }
        throw new Error(`查询错误: ${error.message}`);
      }
    }
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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/6June6/uniclouddb-mcp'

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