Skip to main content
Glama

query

Query specific data from a UniCloud database collection using JQL conditions, filter results by fields, apply sorting, and limit or skip records for precise retrieval.

Input Schema

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

Implementation Reference

  • The main handler function for the 'query' MCP tool. Extracts parameters, calls queryDatabase helper, and returns formatted MCP response or error.
    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, }; } }
  • Tool definition including name 'query', Zod input schema (params), and reference to handler function.
    queryTool: { name: 'query', params: { 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 using the definition from getToolDefinitions().
    server.tool( tools.queryTool.name, tools.queryTool.params, tools.queryTool.handler );
  • Helper function that performs HTTP request to the uniCloud DB service (mcp_service) with 'query' action, handling timeout and response.
    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}`); } }
  • Backend database query execution in uniCloud service (called by queryDatabase helper). Builds and executes the JQL query.
    case 'query': if (where) query = query.where(where); if (field) query = query.field(field); if (orderBy) query = query.orderBy(orderBy.field, orderBy.order); if (limit) query = query.limit(limit); if (skip) query = query.skip(skip); return await query.get();

Other Tools

Related 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