Skip to main content
Glama

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}`); } }
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