Skip to main content
Glama
6June6
by 6June6

update

Update data in UniCloud database collections by specifying collection name, query conditions, and new data values.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYes集合名称
whereYes查询条件 (JQL格式)
dataYes要更新的数据 (object)

Implementation Reference

  • Handler function for the 'update' MCP tool. Extracts parameters and calls the core updateDatabase function, formatting the response for MCP.
    async function handleUpdateTool(params, dbUrl) {
      const { collection, where, data } = params;
    
      try {
        const result = await updateDatabase(collection, where, data, dbUrl);
        return {
          content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
        };
      } catch (error) {
        return {
          content: [{ type: 'text', text: error.message }],
          isError: true,
        };
      }
    }
  • Schema definition for the 'update' tool parameters using Zod: collection (string), where (record), data (record).
    updateTool: {
      name: 'update',
      params: {
        collection: z.string().describe('集合名称'),
        where: z.record(z.any()).describe('查询条件 (JQL格式)'),
        data: z.record(z.any()).describe('要更新的数据 (object)'),
      },
      handler: (params) => handleUpdateTool(params, dbServiceUrl),
  • database.js:367-423 (registration)
    Tool definitions including the 'update' tool registration with name, params schema, and handler reference within getToolDefinitions.
    function getToolDefinitions(z, options = {}) {
      // 如果有传入dbServiceUrl则优先使用,否则使用配置
      const dbServiceUrl = options.dbServiceUrl || DEFAULT_DB_URL;
    
      return {
        // 查询工具
        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),
        },
    
        // 添加工具
        addTool: {
          name: 'add',
          params: {
            collection: z.string().describe('集合名称'),
            data: z.record(z.any()).describe('要添加的数据 (object/array)'),
          },
          handler: (params) => handleAddTool(params, dbServiceUrl),
        },
    
        // 更新工具
        updateTool: {
          name: 'update',
          params: {
            collection: z.string().describe('集合名称'),
            where: z.record(z.any()).describe('查询条件 (JQL格式)'),
            data: z.record(z.any()).describe('要更新的数据 (object)'),
          },
          handler: (params) => handleUpdateTool(params, dbServiceUrl),
        },
    
        // 删除工具
        removeTool: {
          name: 'remove',
          params: {
            collection: z.string().describe('集合名称'),
            where: z.record(z.any()).describe('查询条件 (JQL格式)'),
          },
          handler: (params) => handleRemoveTool(params, dbServiceUrl),
        },
      };
    }
  • index.js:47-50 (registration)
    Final MCP server registration of the 'update' tool using server.tool() with name, params, and handler from database.js tools.
      tools.updateTool.name,
      tools.updateTool.params,
      tools.updateTool.handler
    );
  • Core helper function that performs the actual database update by sending a POST request to the uniCloud DB service with JQL operation.
    async function updateDatabase(collection, where, data, 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: 'update',
              where,
              data,
            },
          }),
          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